示例#1
0
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()
示例#2
0
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()
    message("Player %s, it's your turn" % game.current_turn)
    pygame.display.flip()
    clock.tick(60)
示例#3
0
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()
示例#4
0
    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()
    message("Player %s, it's your turn" % game.current_turn)
    pygame.display.flip()
    clock.tick(60)