def init(self): self.gameMode = 'Image' self.solve = False self.solveSteps = [] self.width = 500 self.height = 600 Star.init() self.star = pygame.sprite.Group() self.hint = False self.gameWon = False self.rows = 3 Block.init(self.rows) self.blocks = pygame.sprite.Group() self.puzzleWidth = 500 self.blockWidth = self.puzzleWidth / self.rows self.boardL = self.rows**2 - 1 for i in range(self.rows): for j in range(self.rows): #Not taking the last block, as it is supposed to be blank if i + j == (self.rows - 1) * 2: continue #Calculating location of blocks and adding them to sprite group x = j * (self.blockWidth) + (self.blockWidth / 2) y = i * (self.blockWidth) + (self.blockWidth / 2) self.blocks.add(Block(x, y, self.rows)) #Loading up the blank and adding it to sprite group Blank.init() blankInitial = self.puzzleWidth * (5 / 6) self.blocks.add(Blank(blankInitial, blankInitial, self.rows)) #If the board that was created is not valid, make a new one until it is if not self.isValidBoard(self, Block.board): self.init(self) return
def init(self): self.gameMode = 'Maze' self.gameWon = False self.gameLost = False Block.init() self.blocks = pygame.sprite.Group() self.rows = 4 self.puzzleWidth = 500 self.blockWidth = self.puzzleWidth / self.rows self.boardL = 15 self.coords = [] MazeBlock.init() for i in range(self.rows): for j in range(self.rows): index = i * self.rows + j #Not taking the last block, as it is supposed to be blank if index == self.rows**2-1: continue #Calculating location of blocks and adding them to sprite group x = j*(self.blockWidth)+(self.blockWidth/2) y = i*(self.blockWidth)+(self.blockWidth/2) self.coords.append((x, y)) #Creating the maze pieces cross = (True, True, True, True) upt = (True, True, False, True) downt = (False, True, True, True) tlc = (True, False, False, True) trc = (True, True, False, False) blc = (False, False, True, True) brc = (False, True, True, False) blank = (False, False, False, False) vert = (True, False, True, False) horz = (False, True, False, True) #Creating the maze maze1 = [horz, horz, cross, downt, upt, tlc, trc, blc, brc, blank, horz, blank, horz, blank, blank] for i in range(self.rows**2-1): self.blocks.add(MazeBlock(self.coords[i][0], self.coords[i][1], maze1[i])) #Loading up the blank and adding it to sprite group Blank.init() blankInitial = self.puzzleWidth * (7/8) self.blocks.add(Blank(blankInitial, blankInitial)) #Initiating the player Player.init() self.player = Player(62.5, 62.5) self.playerSprite = pygame.sprite.Group() self.playerSprite.add(self.player) self.playerIndex = 0 self.remainingMoves = 30 self.remainingTime = 30 self.timerCalled = 0