示例#1
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [4, 1, 1, 1, 1, 1, 1, 1, 0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False

        s = random.randrange(150, 190, 5)
        v = random.randrange(230, 255, 5)
        h = random.randrange(0, 255, 5)
        white = (255, 255, 255)
        if self.mainloop.scheme is None:
            color0 = ex.hsv_to_rgb(h, 40, 230)  # highlight 1
        else:
            color0 = self.mainloop.scheme.u_color
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
        outline_color = (150, 150, 150)
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [13, 7, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [13, 7, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [12, 7, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [12, 7, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [12, 7, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [13, 7, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [13, 7, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [13, 7, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [12, 7, 11, 6, 2]
        elif self.level.lvl == 10:
            data = [12, 7, 17, 6, 3]

        self.chapters = [1, 5, 10]
        self.points = (data[3] * data[4]) // 2

        # rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            x_count = self.get_x_count(data[1], even=True)
        else:
            x_count = self.get_x_count(data[1], even=False)

        if x_count > data[0]:
            data[0] = x_count

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        image_src = [os.path.join('memory', "n_img%da.png" % (i)) for i in range(1, 22)]
        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)

        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        color = ((255, 255, 255))

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4] - 1  # height of the bottom margin minus 1 (game label)
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]

        self.board.add_door(w2, h1, data[3], data[4], classes.board.Door, "", color, "")
        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        # add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])
        for i in range(data[2]):
            h = (h_start + (self.shuffled[i] - 1) * h_step)
            number_color = ex.hsv_to_rgb(h, s, v)  # highlight 1
            caption = str(self.shuffled[i])
            self.board.add_unit(x, y, 1, 1, classes.board.ImgShip, caption, white, image_src[self.shuffled[i]])
            self.board.ships[-1].readable = False
            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        self.outline_all(outline_color, 1)
        instruction = self.d["Re-arrange right"]
        self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter, instruction, color0, "", 8)  # bottom 2
        self.board.ships[-1].immobilize()
        if self.mainloop.scheme is not None:
            self.board.ships[-1].font_color = self.mainloop.scheme.u_font_color
        self.board.ships[-1].speaker_val = self.dp["Re-arrange right"]
        self.board.ships[-1].speaker_val_update = False

        # horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "", white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], h2, classes.board.Obstacle, "", white, "", 7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # right

        self.board.all_sprites_list.move_to_front(self.board.units[0])
示例#2
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [1, 1, 1, 1, 1, 1, 1, 1, 0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False
        s = 100
        v = 255
        h = random.randrange(0, 255, 5)
        white = (255, 255, 255)
        if self.mainloop.scheme is None:
            color0 = ex.hsv_to_rgb(h, 40, 230)  # highlight 1
            instr_font_col = ex.hsv_to_rgb(h, 255, 140)
            font_col = (0, 0, 0)
        else:
            font_col = self.mainloop.scheme.u_font_color
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
                color0 = (0, 0, 10)
            else:
                color0 = (254, 254, 255)
            instr_font_col = font_col
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [13, 9, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [13, 9, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [12, 9, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [12, 9, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [12, 9, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [13, 9, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [13, 9, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [13, 9, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [13, 9, 24, 5, 5]
        elif self.level.lvl == 10:
            data = [12, 9, 11, 6, 2]
        elif self.level.lvl == 11:
            data = [12, 9, 17, 6, 3]
        elif self.level.lvl == 12:
            data = [12, 9, 23, 6, 4]
        elif self.level.lvl == 13:
            data = [12, 9, 29, 6, 5]
        elif self.level.lvl == 14:
            data = [12, 9, 35, 6, 6]

        self.points = (data[3] * data[4]) // 2
        self.chapters = [1, 3, 6, 10, 14]
        # rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            data[0] = self.get_x_count(data[1], even=True)
        else:
            data[0] = self.get_x_count(data[1], even=False)

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)
        """
        If the grid size is odd, then the number of inversions in a solvable situation are even.
        If the grid size is even, and the blank is on an odd row (first, third etc), then the number of inversions in a solvable situation are odd.
        If the grid size is even, and the blank is on an even row (second, fourth etc), then the number of inversions in a solvable situation are even. 
        """
        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4] - 1  # height of the bottom margin minus 1 (game label)
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]

        self.board.add_door(w2, h1, data[3], data[4], classes.board.Door, "", white, "")
        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        # add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])
        for i in range(data[2]):
            if self.mainloop.scheme is None:
                h = (h_start + (self.shuffled[i] - 1) * h_step)
                number_color = ex.hsv_to_rgb(h, s, v)  # highlight 1
            else:
                number_color = color0
            caption = str(self.shuffled[i])
            self.board.add_unit(x, y, 1, 1, classes.board.Letter, caption, number_color, "", 2)

            self.board.ships[-1].readable = False
            if self.mainloop.scheme is None:
                self.board.ships[-1].font_color = ex.hsv_to_rgb(h, 255, 140)
            else:
                self.board.ships[-1].font_color = font_col

            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        if self.mainloop.scheme is not None:
            self.outline_all(font_col, 1)
        instruction = self.d["Re-arrange right"]
        self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter, instruction, color0, "", 5)  # bottom 2
        self.board.ships[-1].font_color = instr_font_col
        self.board.ships[-1].immobilize()
        # if self.mainloop.scheme is not None:
        #    self.board.ships[-1].font_color = self.mainloop.scheme.u_font_color

        self.board.ships[-1].speaker_val = self.dp["Re-arrange right"]
        self.board.ships[-1].speaker_val_update = False
        if self.mainloop.scheme is None:
            self.outline_all(0, 1)
        # horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "", white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], h2, classes.board.Obstacle, "", white, "", 7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # right

        self.board.all_sprites_list.move_to_front(self.board.units[0])
示例#3
0
    def create_game_objects(self, level = 1):
        self.board.decolorable = False
        self.vis_buttons = [0,1,1,1,1,1,1,1,0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False

        outline_color = (150,150,150)
        white = (255,255,255)
        if self.mainloop.scheme is not None and self.mainloop.scheme.dark:
            white = (0,0,0)
        #setting level variable
        #data = [x_count, y_count, number_count, top_limit, ordered]
        data = [7,6,8,3,3]
        self.chapters = [1,5,10,15,20]

        #rescale the number of squares horizontally to better match the screen width
        data[0] = self.get_x_count(data[1],even=False)

        self.data = data

        self.points = 9

        self.layout.update_layout(data[0],data[1])
        self.board.level_start(data[0],data[1],self.layout.scale)

        if self.mainloop.m.game_variant == 0:
            if self.mainloop.scheme is None or not self.mainloop.scheme.dark:
                image_src = [os.path.join('memory', "m_img%da.png" % (i)) for i in range(1,21)]
                grey_image_src = [os.path.join('memory', "m_img%db.png" % (i)) for i in range(1,22)]
            else:
                image_src = [os.path.join('schemes', "black", "match_animals", "m_img%da.png" % (i)) for i in range(1,21)]
                grey_image_src  = [os.path.join('schemes', "black", "match_animals", "m_img%db.png" % (i)) for i in range(1,22)]

        elif self.mainloop.m.game_variant == 1:
            image_src = [os.path.join('memory', "f_img%da.png" % (i)) for i in range(1,21)]
            grey_image_src = [os.path.join('memory', "m_img22b.png")]
        elif self.mainloop.m.game_variant == 2:
            image_src = [os.path.join('memory', "n_img%da.png" % (i)) for i in range(2,22)]
            grey_image_src = [os.path.join('memory', "m_img22b.png")]

        self.bg_img_src = image_src[self.level.lvl-1] #os.path.join('memory', "m_img13a.png")
        if len(grey_image_src) > 1:
            self.bg_img_grey_src = grey_image_src[self.level.lvl-1] #os.path.join('memory', "m_img13b.png")
        else:
            self.bg_img_grey_src = "" #grey_image_src[0]
        self.bg_img = classes.board.ImgSurf(self.board,3,3,white,self.bg_img_src)

        self.finished = False
        self.choice_list = [x for x in range(1,data[2]+1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)

        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0: #if number of inversions is odd it is unsolvable
            #in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0]=self.shuffled[1]
            self.shuffled[1]=temp

        h1=(data[1]-data[4])//2 #height of the top margin
        h2=data[1]-h1-data[4]-1 #height of the bottom margin minus 1 (game label)
        w2=(data[0]-data[3])//2 #side margin width
        self.check = [h1,h2,w2]
        self.board.add_door(w2,h1,data[3],data[4],classes.board.Door,"",white,self.bg_img_grey_src)

        self.board.units[0].image.set_colorkey((1,2,3))
        #create table to store 'binary' solution
        #find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        #add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])

        for i in range(data[2]):
            h = (h_start + (self.shuffled[i]-1)*h_step)
            caption = str(self.shuffled[i])
            self.board.add_unit(x,y,1,1,classes.board.ImgShip,caption,white,self.bg_img_src)
            self.board.ships[-1].img = self.bg_img.img.copy()
            self.board.ships[-1].readable = False
            offset_x = 0
            offset_y = 0
            if self.shuffled[i] in [2,5,8]:
                offset_x = self.board.scale - 0
            elif self.shuffled[i] in [3,6]:
                offset_x = (self.board.scale - 0)*2

            if self.shuffled[i] in [4,5,6]:
                offset_y = self.board.scale - 0
            elif self.shuffled[i] in [7,8]:
                offset_y = (self.board.scale - 0)*2

            self.board.ships[-1].img_pos = (-offset_x,-offset_y)

            line.append(i)
            x += 1
            if x >= w2+data[3] or i == data[2]-1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line=[]

        #mini img below game
        self.board.add_unit(w2+data[3]-2,data[1]-1,1,1,classes.board.ImgShip,"",white,self.bg_img_src)
        self.preview = self.board.ships[-1]
        self.preview.immobilize()
        self.preview.outline = False
        #draw 4 lines on the mini preview
        step = self.board.scale // 3
        pygame.draw.line(self.preview.img,outline_color,[step,0],[step,step*3],1)
        pygame.draw.line(self.preview.img,outline_color,[step*2,0],[step*2,step*3],1)
        pygame.draw.line(self.preview.img,outline_color,[0,step],[step*3,step],1)
        pygame.draw.line(self.preview.img,outline_color,[0,step*2],[step*3,step*2],1)

        self.preview.update_me = True
        self.outline_all(outline_color,1)

        #horizontal
        self.board.add_unit(0,0,data[0],1,classes.board.Obstacle,"",white,"",7)#top
        self.board.add_unit(0,h1+data[4],data[0],1,classes.board.Obstacle,"",white,"",7)#bottom 1
        #side obstacles
        self.board.add_unit(0,h1,w2,data[4],classes.board.Obstacle,"",white,"",7)#left
        self.board.add_unit(w2+data[3],h1,w2,data[4],classes.board.Obstacle,"",white,"",7)#right

        #self.board.all_sprites_list.move_to_front(self.board.units[0])
        self.board.all_sprites_list.move_to_back(self.board.units[0])
        self.board.all_sprites_list.move_to_back(self.board.board_bg)
示例#4
0
    def create_game_objects(self, level=1):
        self.board.decolorable = False
        self.vis_buttons = [4, 1, 1, 1, 1, 1, 1, 1, 0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False

        s = random.randrange(150, 190, 5)
        v = random.randrange(230, 255, 5)
        h = random.randrange(0, 255, 5)
        white = (255, 255, 255)
        if self.mainloop.scheme is None:
            color0 = ex.hsv_to_rgb(h, 40, 230)  #highlight 1
        else:
            color0 = self.mainloop.scheme.u_color
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
        outline_color = (150, 150, 150)
        #setting level variable
        #data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [13, 7, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [13, 7, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [12, 7, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [12, 7, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [12, 7, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [13, 7, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [13, 7, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [13, 7, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [12, 7, 11, 6, 2]
        elif self.level.lvl == 10:
            data = [12, 7, 17, 6, 3]

        self.chapters = [1, 5, 10]
        self.points = (data[3] * data[4]) // 2

        #rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            x_count = self.get_x_count(data[1], even=True)
        else:
            x_count = self.get_x_count(data[1], even=False)

        if x_count > data[0]:
            data[0] = x_count

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        image_src = [
            os.path.join('memory', "n_img%da.png" % (i)) for i in range(1, 22)
        ]
        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)

        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  #if number of inversions is odd it is unsolvable
            #in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        color = ((255, 255, 255))

        h1 = (data[1] - data[4]) // 2  #height of the top margin
        h2 = data[1] - h1 - data[
            4] - 1  #height of the bottom margin minus 1 (game label)
        w2 = (data[0] - data[3]) // 2  #side margin width
        self.check = [h1, h2, w2]

        self.board.add_door(w2, h1, data[3], data[4], classes.board.Door, "",
                            color, "")
        #create table to store 'binary' solution
        #find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        #add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])
        for i in range(data[2]):
            h = (h_start + (self.shuffled[i] - 1) * h_step)
            number_color = ex.hsv_to_rgb(h, s, v)  #highlight 1
            caption = str(self.shuffled[i])
            self.board.add_unit(x, y, 1, 1, classes.board.ImgShip, caption,
                                white, image_src[self.shuffled[i]])
            self.board.ships[-1].readable = False
            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        self.outline_all(outline_color, 1)
        instruction = self.d["Re-arrange right"]
        self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter,
                            instruction, color0, "", 8)  #bottom 2
        self.board.ships[-1].immobilize()
        if self.mainloop.scheme is not None:
            self.board.ships[-1].font_color = self.mainloop.scheme.u_font_color
        self.board.ships[-1].speaker_val = self.dp["Re-arrange right"]
        self.board.ships[-1].speaker_val_update = False

        #horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "",
                            white, "", 7)  #top
        self.board.add_unit(0, h1 + data[4], data[0], h2,
                            classes.board.Obstacle, "", white, "",
                            7)  #bottom 1
        #side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "",
                            white, "", 7)  #left
        self.board.add_unit(w2 + data[3], h1, w2, data[4],
                            classes.board.Obstacle, "", white, "", 7)  #right

        self.board.all_sprites_list.move_to_front(self.board.units[0])
示例#5
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [1, 1, 1, 1, 1, 0, 1, 1, 1]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False
        white = (255, 255, 255)
        if self.mainloop.scheme is not None:
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
        outline_color = (150, 150, 150)
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [5, 4, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [5, 5, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [6, 4, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [6, 5, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [6, 6, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [7, 4, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [7, 5, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [7, 6, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [8, 4, 11, 6, 2]
        elif self.level.lvl == 10:
            data = [8, 5, 17, 6, 3]

        self.chapters = [1, 5, 10]

        # rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            x_count = self.get_x_count(data[1], even=True)
        else:
            x_count = self.get_x_count(data[1], even=False)

        if x_count > data[0]:
            data[0] = x_count

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        self.unit_mouse_over = None
        self.units = []

        image_src = [
            os.path.join('numbers_alpha', "n%d.png" % i) for i in range(1, 22)
        ]
        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)

        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4]  # height of the bottom margin
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]

        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []

        h = random.randrange(0, 255, 5)
        if self.mainloop.scheme is not None and self.mainloop.scheme.dark:
            img_style = "bb"
            self.default_bg_color = ex.hsv_to_rgb(h, 200,
                                                  self.mainloop.cl.bg_color_v)
            self.hover_bg_color = ex.hsv_to_rgb(h, 255,
                                                self.mainloop.cl.fg_hover_v)
            self.font_color = [
                ex.hsv_to_rgb(h, self.mainloop.cl.font_color_s,
                              self.mainloop.cl.font_color_v),
            ]

            self.semi_selected_color = ex.hsv_to_rgb(h, 230, 90)
            self.semi_selected_font_color = [
                ex.hsv_to_rgb(h, 150, 200),
            ]

            self.selected_color = ex.hsv_to_rgb(h, 150, 50)
            self.selected_font_color = [
                ex.hsv_to_rgb(h, 150, 100),
            ]
        else:
            img_style = "wb"
            self.default_bg_color = ex.hsv_to_rgb(h, 150,
                                                  self.mainloop.cl.bg_color_v)
            self.hover_bg_color = ex.hsv_to_rgb(h, 255,
                                                self.mainloop.cl.fg_hover_v)
            self.font_color = [
                ex.hsv_to_rgb(h, self.mainloop.cl.font_color_s,
                              self.mainloop.cl.font_color_v),
            ]

            self.semi_selected_color = ex.hsv_to_rgb(
                h, 80, self.mainloop.cl.bg_color_v)
            self.semi_selected_font_color = [
                ex.hsv_to_rgb(h, 200, self.mainloop.cl.font_color_v),
            ]

            self.selected_color = ex.hsv_to_rgb(h, 50,
                                                self.mainloop.cl.bg_color_v)
            self.selected_font_color = [
                ex.hsv_to_rgb(h, 50, 250),
            ]

        self.dc_img_src = os.path.join('unit_bg', "universal_sq_door.png")
        if self.mainloop.m.game_variant == 4:
            self.dc_selected_img_src = os.path.join(
                'unit_bg', "dc_hover_%s150.png" % img_style)
        elif self.mainloop.m.game_variant == 5:
            self.dc_selected_img_src = os.path.join(
                'unit_bg', "dc_hover_%s20.png" % img_style)

        fg_tint_color = (40, 40, 40)

        # add objects to the board
        line = []
        for i in range(data[2]):
            caption = str(self.shuffled[i])
            self.board.add_universal_unit(
                grid_x=x,
                grid_y=y,
                grid_w=1,
                grid_h=1,
                txt=caption,
                fg_img_src=image_src[self.shuffled[i]],
                bg_img_src=image_src[self.shuffled[i]],
                dc_img_src=self.dc_img_src,
                bg_color=(0, 0, 0, 0),
                border_color=None,
                font_color=None,
                bg_tint_color=None,
                dc_tint_color=self.default_bg_color,
                fg_tint_color=fg_tint_color,
                txt_align=(0, 0),
                font_type=0,
                multi_color=False,
                alpha=True,
                immobilized=False,
                fg_as_hover=True)
            self.units.append(self.board.ships[-1])

            self.board.ships[-1].readable = False
            self.board.ships[i].checkable = True
            self.board.ships[i].init_check_images()
            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        self.outline_all(outline_color, 1)

        # horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "",
                            white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], h2,
                            classes.board.Obstacle, "", white, "",
                            7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "",
                            white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4],
                            classes.board.Obstacle, "", white, "", 7)  # right

        self.board.all_sprites_list.move_to_front(self.board.units[0])
示例#6
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [1, 1, 1, 1, 1, 0, 1, 1, 1]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False
        white = (255, 255, 255)
        if self.mainloop.scheme is None:
            font_col = (0, 0, 0)
        else:
            font_col = self.mainloop.scheme.u_font_color
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [5, 4, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [5, 5, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [6, 4, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [6, 5, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [6, 6, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [7, 4, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [7, 5, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [7, 6, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [7, 7, 24, 5, 5]
        elif self.level.lvl == 10:
            data = [8, 4, 11, 6, 2]
        elif self.level.lvl == 11:
            data = [8, 5, 17, 6, 3]
        elif self.level.lvl == 12:
            data = [8, 6, 23, 6, 4]
        elif self.level.lvl == 13:
            data = [8, 7, 29, 6, 5]
        elif self.level.lvl == 14:
            data = [8, 8, 35, 6, 6]

        self.chapters = [1, 3, 6, 10, 14]
        # rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            data[0] = self.get_x_count(data[1], even=True)
        else:
            data[0] = self.get_x_count(data[1], even=False)

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        self.unit_mouse_over = None
        self.units = []

        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)
        """
        If the grid size is odd, then the number of inversions in a solvable situation are even.
        If the grid size is even, and the blank is on an odd row (first, third etc), then the number of inversions in a solvable situation are odd.
        If the grid size is even, and the blank is on an even row (second, fourth etc), then the number of inversions in a solvable situation are even. 
        """
        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4]  # height of the bottom margin
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]

        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []

        if self.mainloop.scheme is None:
            dc_img_src = os.path.join('unit_bg', "universal_sq_dc.png")
        else:
            dc_img_src = None

        bg_img_src = os.path.join('unit_bg', "universal_sq_bg.png")

        # add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])
        for i in range(data[2]):
            h = (h_start + (self.shuffled[i] - 1) * h_step)
            number_color = ex.hsv_to_rgb(h, self.mainloop.cl.bg_color_s,
                                         self.mainloop.cl.bg_color_v)
            fg_number_color = ex.hsv_to_rgb(h, self.mainloop.cl.fg_hover_s,
                                            self.mainloop.cl.fg_hover_v)
            font_color = [
                ex.hsv_to_rgb(h, self.mainloop.cl.font_color_s,
                              self.mainloop.cl.font_color_v),
            ]

            caption = str(self.shuffled[i])
            self.board.add_universal_unit(grid_x=x,
                                          grid_y=y,
                                          grid_w=1,
                                          grid_h=1,
                                          txt=caption,
                                          fg_img_src=bg_img_src,
                                          bg_img_src=bg_img_src,
                                          dc_img_src=dc_img_src,
                                          bg_color=(0, 0, 0, 0),
                                          border_color=None,
                                          font_color=font_color,
                                          bg_tint_color=number_color,
                                          fg_tint_color=fg_number_color,
                                          txt_align=(0, 0),
                                          font_type=2,
                                          multi_color=False,
                                          alpha=True,
                                          immobilized=False,
                                          fg_as_hover=True)
            self.units.append(self.board.ships[-1])

            self.board.ships[-1].readable = False
            self.board.ships[i].checkable = True
            self.board.ships[i].init_check_images()

            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        if self.mainloop.scheme is not None:
            self.outline_all(font_col, 1)

        if self.mainloop.scheme is None:
            self.outline_all(0, 1)
        # horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "",
                            white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], h2,
                            classes.board.Obstacle, "", white, "",
                            7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "",
                            white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4],
                            classes.board.Obstacle, "", white, "", 7)  # right

        self.board.all_sprites_list.move_to_front(self.board.units[0])
示例#7
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [0, 1, 1, 1, 1, 1, 1, 1, 0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False

        outline_color = (150, 150, 150)
        white = (255, 255, 255)
        if self.mainloop.scheme is not None and self.mainloop.scheme.dark:
            white = (0, 0, 0)
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        data = [7, 6, 8, 3, 3]
        self.chapters = [1, 5, 10, 15, 20]

        # rescale the number of squares horizontally to better match the screen width
        data[0] = self.get_x_count(data[1], even=False)

        self.data = data

        self.points = 9

        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        if self.mainloop.m.game_variant == 0:
            if self.mainloop.scheme is None or not self.mainloop.scheme.dark:
                image_src = [os.path.join('memory', "m_img%da.png" % (i)) for i in range(1, 21)]
                grey_image_src = [os.path.join('memory', "m_img%db.png" % (i)) for i in range(1, 22)]
            else:
                image_src = [os.path.join('schemes', "black", "match_animals", "m_img%da.png" % (i)) for i in
                             range(1, 21)]
                grey_image_src = [os.path.join('schemes', "black", "match_animals", "m_img%db.png" % (i)) for i in
                                  range(1, 22)]

        elif self.mainloop.m.game_variant == 1:
            image_src = [os.path.join('memory', "f_img%da.png" % (i)) for i in range(1, 21)]
            grey_image_src = [os.path.join('memory', "m_img22b.png")]
        elif self.mainloop.m.game_variant == 2:
            image_src = [os.path.join('memory', "n_img%da.png" % (i)) for i in range(2, 22)]
            grey_image_src = [os.path.join('memory', "m_img22b.png")]

        self.bg_img_src = image_src[self.level.lvl - 1]  # os.path.join('memory', "m_img13a.png")
        if len(grey_image_src) > 1:
            self.bg_img_grey_src = grey_image_src[self.level.lvl - 1]  # os.path.join('memory', "m_img13b.png")
        else:
            self.bg_img_grey_src = ""  # grey_image_src[0]
        self.bg_img = classes.board.ImgSurf(self.board, 3, 3, white, self.bg_img_src)

        self.finished = False
        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)

        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4] - 1  # height of the bottom margin minus 1 (game label)
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]
        self.board.add_door(w2, h1, data[3], data[4], classes.board.Door, "", white, self.bg_img_grey_src)

        self.board.units[0].image.set_colorkey((1, 2, 3))
        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        # add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])

        for i in range(data[2]):
            h = (h_start + (self.shuffled[i] - 1) * h_step)
            caption = str(self.shuffled[i])
            self.board.add_unit(x, y, 1, 1, classes.board.ImgShip, caption, white, self.bg_img_src)
            self.board.ships[-1].img = self.bg_img.img.copy()
            self.board.ships[-1].readable = False
            offset_x = 0
            offset_y = 0
            if self.shuffled[i] in [2, 5, 8]:
                offset_x = self.board.scale - 0
            elif self.shuffled[i] in [3, 6]:
                offset_x = (self.board.scale - 0) * 2

            if self.shuffled[i] in [4, 5, 6]:
                offset_y = self.board.scale - 0
            elif self.shuffled[i] in [7, 8]:
                offset_y = (self.board.scale - 0) * 2

            self.board.ships[-1].img_pos = (-offset_x, -offset_y)

            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []

        # mini img below game
        self.board.add_unit(w2 + data[3] - 2, data[1] - 1, 1, 1, classes.board.ImgShip, "", white, self.bg_img_src)
        self.preview = self.board.ships[-1]
        self.preview.immobilize()
        self.preview.outline = False
        # draw 4 lines on the mini preview
        step = self.board.scale // 3
        pygame.draw.line(self.preview.img, outline_color, [step, 0], [step, step * 3], 1)
        pygame.draw.line(self.preview.img, outline_color, [step * 2, 0], [step * 2, step * 3], 1)
        pygame.draw.line(self.preview.img, outline_color, [0, step], [step * 3, step], 1)
        pygame.draw.line(self.preview.img, outline_color, [0, step * 2], [step * 3, step * 2], 1)

        self.preview.update_me = True
        self.outline_all(outline_color, 1)

        # horizontal
        self.board.add_unit(0, 0, data[0], 1, classes.board.Obstacle, "", white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], 1, classes.board.Obstacle, "", white, "", 7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # right

        # self.board.all_sprites_list.move_to_front(self.board.units[0])
        self.board.all_sprites_list.move_to_back(self.board.units[0])
        self.board.all_sprites_list.move_to_back(self.board.board_bg)
示例#8
0
    def create_game_objects(self, level=1):
        self.allow_unit_animations = False
        self.allow_teleport = False
        self.board.decolorable = False
        self.vis_buttons = [1, 1, 1, 1, 1, 0, 1, 1, 0]
        self.mainloop.info.hide_buttonsa(self.vis_buttons)

        self.board.draw_grid = False
        s = 100
        v = 255
        h = random.randrange(0, 255, 5)
        white = (255, 255, 255)
        if self.mainloop.scheme is None:
            color0 = ex.hsv_to_rgb(h, 40, 230)  # highlight 1
            instr_font_col = ex.hsv_to_rgb(h, 255, 140)
            font_col = (0, 0, 0)
        else:
            font_col = self.mainloop.scheme.u_font_color
            if self.mainloop.scheme.dark:
                white = (0, 0, 0)
                color0 = (0, 0, 10)
            else:
                color0 = (254, 254, 255)
            instr_font_col = font_col
        # setting level variable
        # data = [x_count, y_count, number_count, top_limit, ordered]
        if self.level.lvl == 1:
            data = [13, 9, 5, 3, 2]
        elif self.level.lvl == 2:
            data = [13, 9, 8, 3, 3]
        elif self.level.lvl == 3:
            data = [12, 9, 7, 4, 2]
        elif self.level.lvl == 4:
            data = [12, 9, 11, 4, 3]
        elif self.level.lvl == 5:
            data = [12, 9, 15, 4, 4]
        elif self.level.lvl == 6:
            data = [13, 9, 9, 5, 2]
        elif self.level.lvl == 7:
            data = [13, 9, 14, 5, 3]
        elif self.level.lvl == 8:
            data = [13, 9, 19, 5, 4]
        elif self.level.lvl == 9:
            data = [13, 9, 24, 5, 5]
        elif self.level.lvl == 10:
            data = [12, 9, 11, 6, 2]
        elif self.level.lvl == 11:
            data = [12, 9, 17, 6, 3]
        elif self.level.lvl == 12:
            data = [12, 9, 23, 6, 4]
        elif self.level.lvl == 13:
            data = [12, 9, 29, 6, 5]
        elif self.level.lvl == 14:
            data = [12, 9, 35, 6, 6]

        self.chapters = [1, 3, 6, 10, 14]
        # rescale the number of squares horizontally to better match the screen width
        m = data[0] % 2
        if m == 0:
            data[0] = self.get_x_count(data[1], even=True)
        else:
            data[0] = self.get_x_count(data[1], even=False)

        self.data = data
        self.layout.update_layout(data[0], data[1])
        self.board.level_start(data[0], data[1], self.layout.scale)

        self.choice_list = [x for x in range(1, data[2] + 1)]
        self.shuffled = self.choice_list[:]
        random.shuffle(self.shuffled)
        """
        If the grid size is odd, then the number of inversions in a solvable situation are even.
        If the grid size is even, and the blank is on an odd row (first, third etc), then the number of inversions in a solvable situation are odd.
        If the grid size is even, and the blank is on an even row (second, fourth etc), then the number of inversions in a solvable situation are even. 
        """
        inversions = ex.inversions(self.shuffled)
        if inversions % 2 != 0:  # if number of inversions is odd it is unsolvable
            # in unsolvable combinations swapping 2 squares will make it solvable
            temp = self.shuffled[0]
            self.shuffled[0] = self.shuffled[1]
            self.shuffled[1] = temp

        h1 = (data[1] - data[4]) // 2  # height of the top margin
        h2 = data[1] - h1 - data[4] - 1  # height of the bottom margin minus 1 (game label)
        w2 = (data[0] - data[3]) // 2  # side margin width
        self.check = [h1, h2, w2]

        self.board.add_door(w2, h1, data[3], data[4], classes.board.Door, "", white, "")
        # create table to store 'binary' solution
        # find position of first door square
        x = w2
        y = h1
        self.mini_grid = []
        # add objects to the board
        line = []
        h_start = random.randrange(0, 155, 5)
        h_step = 100 // (data[2])
        for i in range(data[2]):
            if self.mainloop.scheme is None:
                h = (h_start + (self.shuffled[i] - 1) * h_step)
                number_color = ex.hsv_to_rgb(h, s, v)  # highlight 1
            else:
                number_color = color0
            caption = str(self.shuffled[i])
            self.board.add_unit(x, y, 1, 1, classes.board.Letter, caption, number_color, "", 2)

            self.board.ships[-1].readable = False
            self.board.ships[i].checkable = True
            self.board.ships[i].init_check_images()
            if self.mainloop.scheme is None:
                self.board.ships[-1].font_color = ex.hsv_to_rgb(h, 255, 140)
            else:
                self.board.ships[-1].font_color = font_col

            line.append(i)
            x += 1
            if x >= w2 + data[3] or i == data[2] - 1:
                x = w2
                y += 1
                self.mini_grid.append(line)
                line = []
        if self.mainloop.scheme is not None:
            self.outline_all(font_col, 1)
        instruction = self.d["Re-arrange right"]
        self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter, instruction, color0, "", 5)  # bottom 2
        self.board.ships[-1].font_color = instr_font_col
        self.board.ships[-1].immobilize()

        self.board.ships[-1].speaker_val = self.dp["Re-arrange right"]
        self.board.ships[-1].speaker_val_update = False
        if self.mainloop.scheme is None:
            self.outline_all(0, 1)
        # horizontal
        self.board.add_unit(0, 0, data[0], h1, classes.board.Obstacle, "", white, "", 7)  # top
        self.board.add_unit(0, h1 + data[4], data[0], h2, classes.board.Obstacle, "", white, "", 7)  # bottom 1
        # side obstacles
        self.board.add_unit(0, h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # left
        self.board.add_unit(w2 + data[3], h1, w2, data[4], classes.board.Obstacle, "", white, "", 7)  # right

        self.board.all_sprites_list.move_to_front(self.board.units[0])