def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'FloodIt', grid.position(8, 1), self.font.large, 'royalblue', anchor=Anchor.CENTER) self.turn_text = Text(self, 'Turn: 0', grid.position(8, 14), self.font.basic, 'wheat4', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'royalblue', self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'royalblue', self.push_newgame) self.colors = tuple( map(pygame.Color, [ 'dodgerblue', 'gold', 'firebrick1', 'darkslateblue', 'forestgreen', 'darkorange', 'mediumorchid' ])) self.board_grid = Grid((190, 100, 420, 420), (14, 14), (1, 1)) self.push_newgame(None, None)
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect.inflate(-10, -10), (16, 15), (3, 3)) Text(self, 'Text Group Example', grid.position(8, 1), self.font.basic, 'orange', anchor=Anchor.CENTER) self.back = Button(self, 'Back', grid.align(0, 0, 2, 1), 'orange', self.back_push) text_args = (self.font.basic, 'wheat4', None, 'me_group') text_kargs = { 'anchor': Anchor.CENTER, 'hilight': 'burlywood', 'toggle': 'wheat' } self.texts = [ Text(self, 'Me First', grid.position(8, 4), *text_args, **text_kargs), Text(self, 'Pick Me', grid.position(8, 5), *text_args, **text_kargs), Text(self, 'Click Me', grid.position(8, 6), *text_args, **text_kargs) ]
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'Simple Games', grid.position(8, 1), self.font.large, 'dodgerblue', anchor=Anchor.CENTER) Text(self, 'TicTacToe', grid.position(8, 4), self.font.large, 'wheat4', callback=(self.push_game, 'TicTacToe'), hilight='burlywood', anchor=Anchor.CENTER) Text(self, 'MasterMind', grid.position(8, 5), self.font.large, 'wheat4', callback=(self.push_game, 'MasterMind'), hilight='burlywood', anchor=Anchor.CENTER) Text(self, 'FloodIt', grid.position(8, 6), self.font.large, 'wheat4', callback=(self.push_game, 'FloodIt'), hilight='burlywood', anchor=Anchor.CENTER) Text(self, 'Memory', grid.position(8, 7), self.font.large, 'wheat4', callback=(self.push_game, 'Memory'), hilight='burlywood', anchor=Anchor.CENTER) Text(self, 'Puzzle', grid.position(8, 8), self.font.large, 'wheat4', callback=(self.push_game, 'Puzzle'), hilight='burlywood', anchor=Anchor.CENTER)
def __init__(self): QuitScene.__init__(self) self.page = 1 text_grid = Grid(self._rect.inflate(-10, -10), (16, 15), (3, 3)) grid = Grid(self._rect.inflate(-10, -10), (17, 15), (3, 3)) self.keys = [ key for key in list(pygame.color.THECOLORS.keys()) if key[:4] not in ['gray', 'grey'] ] self.max_page = int(len(self.keys) / 60) + 1 self.keys.sort() self.keys_group = [] for x in range(5): for y in range(12): self.keys_group.append( Text(self, "None", text_grid.position(2 + x * 3, 2 + y), self.font.basic, anchor=Anchor.MID_TOP)) self.update_colors() title = 'Pygame Builtin Colors {0}'.format(self.page) color_option = self.keys[:] color_option.remove('black') colors = [] for i in range(len(title)): color_choice = choice(color_option) colors.append(color_choice) color_option.remove(color_choice) color_surface = gradient.by_letter(self.font.large, title, colors, True) self.intro = Text(self, title, text_grid.position(8, 1), self.font.large, color_surface, anchor=Anchor.CENTER) Button(self, 'Prev', grid.align(5, 14, 2, 1), 'aliceblue', self.prev_page) Button(self, 'Next', grid.align(10, 14, 2, 1), 'aliceblue', self.next_page) Button(self, 'Back', grid.align(0, 0, 2, 1), 'aliceblue', self.push_back)
def __init__(self): QuitScene.__init__(self) caption = 'PyScene' text_grid = Grid(self._rect.inflate(-10, -10), (16, 15), (3, 3)) grid = Grid(self._rect.inflate(-10, -10), (17, 15), (3, 3)) color_surface = gradient.by_letter( self.font.super, caption, ('dodgerblue', 'dodgerblue', 'snow')) Text(self, caption, text_grid.position(8, 1), self.font.super, color_surface, reflection=(1, 'down', (45, 'down')), anchor=Anchor.CENTER) Button(self, 'Text Group', grid.align(1, 5, 3, 1), None, (self.push_button, 'GroupExample')) Button(self, 'Text Effects', grid.align(1, 6, 3, 1), None, (self.push_button, 'TextEffects')) Button(self, 'Pygame Builtin Color', grid.align(6, 5, 5, 1), 'steelblue', (self.push_button, "ColorBuiltin"))
def __init__(self, parent): # init Scenery through init_center method Scenery.init_center(self, parent, (170, 80), False, False) grid = Grid(self._rect, (6, 8), (10, 5)) Text(self, 'Confirm Quit', grid.position(3, 1), self.font.basic, 'mediumorchid', anchor=Anchor.MID_TOP) Button(self, 'Yes', grid.align(0, 4, 3, 4, (2, 4)), 'red', (self.push_confirm, True)) Button(self, 'No', grid.align(3, 4, 3, 4, (2, 4)), 'green', (self.push_confirm, False)) self.position = grid.position(2, 0) self.image = self.font.basic.render('Test', 1, (0, 200, 0))
def push_newgame(self, button, data): grid = Grid((300, 150, 200, 260), (4, 10), (4, 3)) self.board = [] for j in range(10): self.board.append([]) for i in range(4): self.board[j].append(Slot(grid.rect(i, 9 - j))) self.code = [choice(self.colors) for i in range(4)] self.code_slots = [] for i in range(4): self.code_slots.append(Slot(grid.rect(i, -2), self.code[i])) grid = Grid((530, 150, 70, 260), (4, 10), (3, 8)) self.check_blocks = [] for j in range(10): self.check_blocks.append([]) for i in range(4): self.check_blocks[j].append(Slot(grid.rect(i, 9 - j))) self.current_row = 0 self.current_pos = 0 self.outcome.set_text("")
def __init__(self): Card.load_images() QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'Memory', grid.position(8, 1), self.font.large, 'orange', anchor=Anchor.CENTER) self.move_text = Text(self, 'Moves: 0', grid.position(8, 3), self.font.basic, 'orange', anchor=Anchor.CENTER) # image artist Text(self, 'artwork by Kenny', grid.position(4, 14), self.font.basic, 'orange', anchor=Anchor.CENTER) Text(self, 'www.kenney.nl', grid.position(12, 14), self.font.basic, 'orange', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'orange', callback=self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'orange', callback=self.push_newgame) gx = (self._rect.w - 700) / 2 gy = (self._rect.h - 360) / 2 + 30 self.grid = Grid((gx, gy, 700, 360), (10, 6), (5, 5)) self.push_newgame(None, None)
class Memory(QuitScene): def __init__(self): Card.load_images() QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'Memory', grid.position(8, 1), self.font.large, 'orange', anchor=Anchor.CENTER) self.move_text = Text(self, 'Moves: 0', grid.position(8, 3), self.font.basic, 'orange', anchor=Anchor.CENTER) # image artist Text(self, 'artwork by Kenny', grid.position(4, 14), self.font.basic, 'orange', anchor=Anchor.CENTER) Text(self, 'www.kenney.nl', grid.position(12, 14), self.font.basic, 'orange', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'orange', callback=self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'orange', callback=self.push_newgame) gx = (self._rect.w - 700) / 2 gy = (self._rect.h - 360) / 2 + 30 self.grid = Grid((gx, gy, 700, 360), (10, 6), (5, 5)) self.push_newgame(None, None) def push_newgame(self, button, data): self.cards = [] self.move_text.set_text('Moves: 0') objects = list(range(30)) + list(range(30)) for across in range(10): self.cards.append([]) for down in range(6): pick = choice(objects) objects.remove(pick) self.cards[across].append( Card(self.grid.rect(across, down), pick)) self.last_pick = [] self.move_count = 0 def push_back(self, button, data): self.set_scene('SimpleGames') def blit(self, surface): surface.fill((30, 30, 30)) for item in self.cards: for card in item: card.blit(surface) def event(self, event): QuitScene.event(self, event) if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x, y = self.grid.location(*event.pos) if x == None or y == None: return if 0 <= x < 10 and 0 <= y < 6: if self.cards[x][y].show == True: return self.cards[x][y].show = True if len(self.last_pick) == 0: self.last_pick = [(x, y)] elif len(self.last_pick) == 1: cx, cy = self.last_pick[0] if self.cards[x][y].item == self.cards[cx][cy].item: self.last_pick = [] else: self.last_pick.append((x, y)) self.move_count += 1 self.move_text.set_text('Moves: {0}'.format( self.move_count)) else: for cx, cy in self.last_pick: self.cards[cx][cy].show = False self.last_pick = [(x, y)]
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'TicTacToe', grid.position(8, 1), self.font.large, 'dodgerblue', anchor=Anchor.CENTER) self.wins_text = Text(self, 'Wins: 0', grid.position(2, 3), self.font.basic, 'forestgreen', anchor=Anchor.CENTER) self.cats_text = Text(self, 'Cats: 0', grid.position(8, 3), self.font.basic, 'dodgerblue', anchor=Anchor.CENTER) self.lost_text = Text(self, 'Lost: 0', grid.position(13, 3), self.font.basic, 'firebrick', anchor=Anchor.CENTER) self.winner_text = Text(self, '', grid.position(8, 12), self.font.basic, 'dodgerblue', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'dodgerblue', callback=self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'dodgerblue', callback=self.push_newgame) self.x_style = BoxStyle('dodgerblue3', 'dodgerblue3') self.o_style = BoxStyle('firebrick1', 'firebrick1') self.box_style = BoxStyle('aquamarine4', 'aquamarine4') box = Grid(self._rect.inflate(-530, -330), (3, 3), (3, 3)) self.buttons = [] for y in range(3): for x in range(3): self.buttons.append( Button(self, '', box.rect(x, y), self.box_style, callback=(self.push_button, x + y * 3))) self.game_data() self.win_pattern = ( (0, 1, 2), (3, 4, 5), (6, 7, 8), # across (0, 3, 6), (1, 4, 7), (2, 5, 8), # down (0, 4, 8), (2, 4, 6)) self.ai_pattern = { 0: ((1, 2), (3, 6), (4, 8)), 1: ((1, 2), (4, 7)), 2: ((0, 1), (5, 8), (4, 6)), 3: ((0, 6), (4, 5)), 4: ((1, 7), (3, 5), (0, 8), (2, 6)), 5: ((2, 8), (3, 4)), 6: ((0, 3), (4, 2), (7, 8)), 7: ((1, 4), (6, 8)), 8: ((6, 7), (0, 4), (2, 5)) }
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'Puzzle', grid.position(8, 1), self.font.large, 'mediumorchid1', anchor=Anchor.CENTER) # image artist Text(self, 'artwork by Kenny', grid.position(4, 14), self.font.basic, 'mediumorchid1', anchor=Anchor.CENTER) Text(self, 'www.kenney.nl', grid.position(12, 14), self.font.basic, 'mediumorchid1', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'mediumorchid1', self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'mediumorchid1', self.push_newgame) self.grab_images() width = 288 height = 288 gx = (self._rect.w - width) / 2 gy = (self._rect.h - height) / 2 self.board_grid = Grid((gx, gy, width, height), (4, 4), (1, 1)) self.board = [] self.board_rect = [] for j in range(4): for i in range(4): rect = self.board_grid.rect(i, j) clip_rect = rect.copy() clip_rect.x -= i * 2 + self.board_grid._rect.x + 1 clip_rect.y -= j * 2 + self.board_grid._rect.y + 1 self.board.append(clip_rect) self.board_rect.append(rect) self.board[-1] = None self.push_newgame(None, None)
class Puzzle(QuitScene): def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'Puzzle', grid.position(8, 1), self.font.large, 'mediumorchid1', anchor=Anchor.CENTER) # image artist Text(self, 'artwork by Kenny', grid.position(4, 14), self.font.basic, 'mediumorchid1', anchor=Anchor.CENTER) Text(self, 'www.kenney.nl', grid.position(12, 14), self.font.basic, 'mediumorchid1', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'mediumorchid1', self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'mediumorchid1', self.push_newgame) self.grab_images() width = 288 height = 288 gx = (self._rect.w - width) / 2 gy = (self._rect.h - height) / 2 self.board_grid = Grid((gx, gy, width, height), (4, 4), (1, 1)) self.board = [] self.board_rect = [] for j in range(4): for i in range(4): rect = self.board_grid.rect(i, j) clip_rect = rect.copy() clip_rect.x -= i * 2 + self.board_grid._rect.x + 1 clip_rect.y -= j * 2 + self.board_grid._rect.y + 1 self.board.append(clip_rect) self.board_rect.append(rect) self.board[-1] = None self.push_newgame(None, None) def grab_images(self): filepath = os.path.join('images', 'PNG') self.images_file = [] items = os.listdir(filepath) for item in items: if item.endswith('.png'): filename = os.path.join(filepath, item) self.images_file.append(filename) def load_image(self): filename = choice(self.images_file) self.image = pygame.image.load(filename) self.image = self.image.convert_alpha() self.shadow_image = pygame.transform.scale(self.image, (60, 60)) self.image = pygame.transform.scale(self.image, self.board_grid.get_size()) def push_newgame(self, button, pydata): self.load_image() shuffle(self.board) def push_back(self, button, pydata): self.set_scene('SimpleGames') def blit(self, surface): surface.fill((40, 0, 40)) surface.blit(self.shadow_image, self.board_grid.rect(5, 1)) for clip_rect, rect in zip(self.board, self.board_rect): if clip_rect: surface.blit(self.image.subsurface(clip_rect), rect) def event(self, event): QuitScene.event(self, event) if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x, y = self.board_grid.location(*event.pos) if x is None or y is None: return if 0 <= x < 4 and 0 <= y < 4: pos = y * 4 + x if self.board[pos] is None: return def setboard(npos): if self.board[npos] is None: self.board[npos] = self.board[pos] self.board[pos] = None if pos + 4 < 16: setboard(pos + 4) if pos - 4 >= 0: setboard(pos - 4) if pos % 4 + 1 < 4: setboard(pos + 1) if pos % 4 - 1 >= 0: setboard(pos - 1)
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect.inflate(-10, -10), (16, 15), (3, 3)) self.back = Button(self, 'Back', grid.align(0, 0, 2, 1), 'darkolivegreen3', self.back_push) Text(self, 'Text Effects', grid.position(8, 1), self.font.big, 'darkolivegreen3', anchor=Anchor.CENTER) Text(self, 'Shifted Text', grid.position(1, 4), self.font.large, 'darkolivegreen4', shift=(45, 'top')) Text(self, 'Fading Text', grid.position(1, 5), self.font.large, 'darkolivegreen4', fade='right') Text(self, 'Reflection Text', grid.position(8, 3), self.font.large, 'darkolivegreen4', reflection=(1, 'down'), anchor=Anchor.CENTER) Text(self, 'Shadow Trail Text', grid.position(11, 4), self.font.large, 'darkolivegreen4', shadow=('darkolivegreen', (5, 5), True)) Text(self, 'Shadow Text', grid.position(12, 5), self.font.large, 'darkolivegreen4', shadow=('darkolivegreen', (3, 3))) Text(self, 'Blinking Text', grid.position(8, 6), self.font.large, 'darkolivegreen4', blink=((30, 30, 30), 1500, 700), anchor=Anchor.CENTER) self.type_text = Text(self, 'TypeWriter Text', grid.position(8, 8), self.font.large, 'darkolivegreen4', typewriter=(333, self.writer_finish), anchor=Anchor.CENTER) self.timer.add('TypeWriter', 2000, self.timer_retype) self.timer.stop('TypeWriter')
def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'MasterMind', grid.position(8, 1), self.font.large, 'forestgreen', anchor=Anchor.CENTER) self.outcome = Text(self, "", grid.position(8, 12), self.font.basic, 'forestgreen', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Check', box.align(2, 9, 4, 1, (28, 0)), 'forestgreen', self.push_check) Button(self, 'Back', box.align(0, 0, 3, 1), 'forestgreen', self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'forestgreen', self.push_newgame) self.colors = ('gold', 'darkred', 'royalblue', 'honeydew2', 'wheat4', 'orange', 'green3', 'purple') self.colors = tuple(map(pygame.Color, self.colors)) grid = Grid((124, 208, 96, 92), (2, 4), (4, 3)) self.color_picker = [] for j in range(4): self.color_picker.append([]) for i in range(2): self.color_picker[j].append( Slot(grid.rect(i, j), self.colors[i * 4 + j])) self.push_newgame(None, None)
class FloodIt(QuitScene): def __init__(self): QuitScene.__init__(self) grid = Grid(self._rect, (16, 15), (3, 3)) Text(self, 'FloodIt', grid.position(8, 1), self.font.large, 'royalblue', anchor=Anchor.CENTER) self.turn_text = Text(self, 'Turn: 0', grid.position(8, 14), self.font.basic, 'wheat4', anchor=Anchor.CENTER) box = Grid(self._rect.inflate(-10, -10), (19, 17), (2, 2)) Button(self, 'Back', box.align(0, 0, 3, 1), 'royalblue', self.push_back) Button(self, 'New Game', box.align(0, 1, 3, 1), 'royalblue', self.push_newgame) self.colors = tuple( map(pygame.Color, [ 'dodgerblue', 'gold', 'firebrick1', 'darkslateblue', 'forestgreen', 'darkorange', 'mediumorchid' ])) self.board_grid = Grid((190, 100, 420, 420), (14, 14), (1, 1)) self.push_newgame(None, None) def push_newgame(self, button, data): self.board = [] for j in range(14): self.board.append([]) for i in range(14): self.board[j].append( Dot(self.colors, self.board_grid.rect(i, j), (j, i))) self.board[0][0].choosen = True self.board[0][0].disturbance(self.board, self.board[0][0].color) for item in self.board: for dot in item: dot.ignore_me = False self.count = 0 self.turn_text.set_text("Turn: 0") def push_back(self, button, data): self.set_scene('SimpleGames') def blit(self, surface): surface.fill((10, 10, 20)) for row in self.board: for dot in row: surface.fill(dot.color, dot.rect) def event(self, event): QuitScene.event(self, event) if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x, y = self.board_grid.location(*event.pos) if x is None or y is None: return if 0 <= x < 14 and 0 <= y < 14: color = self.board[y][x].color match = self.board[0][0].disturbance(self.board, color) if match > 0: self.count += 1 self.turn_text.set_text('Turn: ' + str(self.count)) for item in self.board: for dot in item: dot.ignore_me = False if dot.choosen: dot.color = color else: for item in self.board: for dot in item: dot.ignore_me = False