Exemplo n.º 1
0
                        colInput = int(clickX / (cycleRadius * 2))
                        gameBoard.drop_piece(currentPlayer.number, colInput)
                        arrowsColor = [0] * len(gameBoard.game_map[0])
                        dropped = True
                    except Exception as exception:
                        print(exception)

    else:  # currentPlayer == AIPlayer
        col = currentPlayer.get_drop_input(gameBoard.game_map)
        gameBoard.drop_piece(currentPlayer.number, col)
        dropped = True

    refresh_screen()

    if dropped:
        if gameBoard.check_win(currentPlayer.number):
            break
        if currentPlayer == player1:
            currentPlayer = player2
        else:
            currentPlayer = player1
        droppedCount += 1

if droppedCount == allSlots:
    label = myFont.render("Game draw", 1, (255, 255, 255))
elif currentPlayer == player1:
    label = myFont.render("Player 1 won !!", 1, (100, 100, 255))
else:
    label = myFont.render("Player 2 won !!", 1, (255, 100, 100))

screen.blit(label, (40, 10))
Exemplo n.º 2
0
def run_game():
    global currentPlayer
    global gameBoard
    global game_running
    game_running = True
    currentPlayer = player1
    fake_wait = 0
    dropped_count = 0
    gameBoard = GameBoard()
    while dropped_count != allSlots:
        dropped = False
        if type(currentPlayer) == Person:
            for ev in pygame.event.get():
                if ev.type == pygame.QUIT:
                    sys.exit()

                if ev.type == pygame.MOUSEBUTTONDOWN:
                    if ev.pos[0] < COLUMN_COUNT * cycleRadius * 2:
                        try:
                            input_column = int(ev.pos[0] / (cycleRadius * 2))
                            gameBoard.drop_piece(currentPlayer.number,
                                                 input_column)
                            dropped = True
                        except Exception as exception:
                            print(exception)

        else:  # currentPlayer == AIPlayer
            for ev in pygame.event.get():
                if ev.type == pygame.QUIT:
                    sys.exit()
            fake_wait += 1
            if fake_wait == AI_FAKE_TIME:
                input_column = currentPlayer.get_drop_input(gameBoard.game_map)
                gameBoard.drop_piece(currentPlayer.number, input_column)
                dropped = True

        refresh_screen()

        if dropped:
            fake_wait = 0
            if gameBoard.check_win(currentPlayer.number):
                break
            if currentPlayer == player1:
                currentPlayer = player2
            else:
                currentPlayer = player1
            dropped_count += 1

        clock.tick(30)

    if dropped_count == allSlots:
        label = finalFont.render("Game draw", True, WHITE)
    elif currentPlayer == player1:
        label = finalFont.render("Player 1 won !!", True, LIGHT_BLUE)
    else:
        label = finalFont.render("Player 2 won !!", True, LIGHT_RED)

    screen.blit(label, (40, ROW_COUNT * cycleRadius))
    pygame.display.update()
    pygame.time.wait(1000)
    game_running = False