def game(): game = Game(10, 5, 20) game.boats = [ Boat(0, 0, 0, 5), Boat(3, 4, 1, 3), Boat(2, 2, 0, 4), Boat(7, 8, 1, 2), Boat(8, 2, 1, 4) ] return game
def test_game_fails(): game = Game() game.players[0].turn = False assert game.current_turn == 0 game.next_player_turn() assert game.current_turn == 1 game.next_player_turn() assert game.current_turn == 0 game.next_player_turn() assert game.current_turn == 1 game.next_player_turn()
def message(s): msg = FONTOBJ.render(s, True, white, black) DISPLAY_SURF.blit(msg, msg.get_rect()) def exit(s): for tile in board: tile.draw() message(s) pygame.display.update() sleep(3) sysexit() board = create_graphic_board(SIZE) clock = pygame.time.Clock() game = Game(players) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.MOUSEBUTTONUP: for tile in board: if tile.is_clicked(): if tile.toggle(game.players[game.current_turn].symbol): if board.has_three_in_a_row(): exit('game over, player %d won' % game.current_turn) game.next_player_turn() DISPLAY_SURF.fill(black) for tile in board: tile.draw()
def test_player_turns(): game = Game() # set player 0 to go first game.players[0].turn = True assert game.current_turn == 0 game.next_player_turn() assert game.current_turn == 1 game.next_player_turn() assert game.current_turn == 0 game.next_player_turn() assert game.current_turn == 1 game.next_player_turn() assert game.current_turn == 0 game.next_player_turn() assert game.current_turn == 1 game.next_player_turn()
def test_init(): game = Game() assert len(game.players) == 2
def main(): game = Game(10, 5, 20) game.play()
msg = FONTOBJ.render(s, True, white, black) DISPLAY_SURF.blit(msg, msg.get_rect()) def exit(s): for tile in board: tile.draw() message(s) pygame.display.update() sleep(3) sysexit() board = create_graphic_board(SIZE) clock = pygame.time.Clock() game = Game(players) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.MOUSEBUTTONUP: for tile in board: if tile.is_clicked(): if tile.toggle(game.players[game.current_turn].symbol): if board.has_three_in_a_row(): exit('game over, player %d won' % game.current_turn) game.next_player_turn() DISPLAY_SURF.fill(black) for tile in board: