Beispiel #1
0
def get_stat_list(table):
    player_list = []
    for row in table:
        name = row.find("a").string
        player = Player(name)
        attr = {}
        stats = row.findAll("td")
        for stat in stats:
            attr[stat["data-stat"]] = stat.string
        player.create(attr)
        player_list.append(player)
    return player_list
Beispiel #2
0
def main():
    """This functions triggers the game to run"""
    run = True
    paused = False
    FPS = 60
    clock = pygame.time.Clock()

    lost = False
    lost_count = 0  #variable to determine how many seconds to pauze the game before quiting out after losing.

    songswitch = 0
    count = 0

    tiles = []

    players = []
    player_turn_count = 0
    player_start_positions = {
        "player 1": (int(STEPSIZE * (TILE_XY_COUNT / 2)), HEIGHT - STEPSIZE),
        "player 2": (int(STEPSIZE * (TILE_XY_COUNT / 2)), 0),
        "player 3": (0, int(STEPSIZE * (TILE_XY_COUNT / 2))),
        "player 4": (WIDTH - STEPSIZE, int(STEPSIZE * (TILE_XY_COUNT / 2)))
    }

    center_x = range(0, WIDTH, STEPSIZE)[int(TILE_XY_COUNT / 2)]
    center_y = range(0, HEIGHT, STEPSIZE)[int(TILE_XY_COUNT / 2)]
    cursor = Cursor(center_x, center_y)

    #generating game board..
    # board = SquareGrid(WIDTH, HEIGHT)
    board = SquareGrid(TILE_XY_COUNT, TILE_XY_COUNT)
    # board = WeightedGrid(WIDTH, HEIGHT)
    #generating tiles
    for row, x in zip(STARTING_BOARD, range(0, WIDTH, STEPSIZE)):
        for health, y in zip(row, range(0, HEIGHT, STEPSIZE)):
            tiles.append(Tile(x, y, health))

    #spawning players
    for player in player_start_positions:
        players.append(Player(player_start_positions[player], player))
        board.blocked.append(vec(player_start_positions[player]) // STEPSIZE)

    player_count = len(players)

    while run:
        clock.tick(FPS)  #makes sure the game runs at the frames set by FPS
        if not pygame.mixer.music.get_busy():
            songswitch = play_music(songswitch)

        if lost:
            run = False

        #handeling player pause or quit input:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  #  if someone clicks the X in the corner it makes sure the games ends
                run = False
                pygame.mixer.music.stop()
            elif event.type == KEYDOWN:
                if event.key == pygame.K_p:
                    paused = not paused
                    if paused:
                        pygame.mixer.music.pause()
                    else:
                        pygame.mixer.music.unpause()

        redraw_window(tiles, players, cursor, lost, paused, board)
        if not paused:
            count += 1
            if count == 3600:
                run == False

            cursor.interact(count, board)

            #making sure that cursor and player snaps to tiles --> fixed position
            for tile in tiles:
                for player in players:
                    if player.contact(tile):
                        # print (f"{player.player}, contacts tile at {tile.x, tile.y} while at {player.x, player.y}")
                        player.x, player.y = tile.x, tile.y
                        # if turn_ends:
                        # 	tile.health -= 1
                # if tile is destroyed, remove from board
                if tile.health <= 0:
                    tile_position = vec(tile.x, tile.y) // STEPSIZE
                    board.blocked.append(tile_position)
                    tiles.remove(tile)

            # if keys[pygame.K_SPACE]:
            # 	player.shoot()

            player_turn = player_turn_count % player_count
            last_player_name = players[-1].player
            for player in players:
                try:
                    current_player = players[player_turn].player
                except IndexError:
                    player_count = len(players)
                    player_turn = player_turn_count % player_count
                    current_player = players[player_turn].player
                if player.player == current_player:
                    player.active = True  #when True, player is allowed to move and colors player name
                    check4hotfeet(
                        player, players, tiles,
                        player_turn_count)  #checks whether player has hotfeet
                    player.menu(
                        cursor, WIN, tiles, players, lost, paused,
                        board)  #checking whether player tries to start menu
                    if player.action_points <= 0:
                        player_turn_count += 1
                        player.active = False
                        player.action_points = 4
                        for tile in tiles:
                            if player.contact(tile):
                                tile.damage(
                                    1
                                )  #damage tile on turn end if player on tile
                                player.hotfeet = False  #player contacts tile on turn end, so not hotfeet
                        if player.player == last_player_name:  #if last player turn ended, update player count
                            player_count = len(players)

            pygame.display.set_caption(
                f"Hotfeet, running at: {int(clock.get_fps())} fps"
            )  #Setting the name of the window