Exemple #1
0
def DistributeRolesBaseGame(game):
    players = game.Players;
    playerCount = len(players);

    numberOfWerewolves = GetPlayerCountForRole(playerCount, GameConstants.PLAYERS_PER_WEREWOLF);
    numberOfSeers = GetPlayerCountForRole(playerCount, GameConstants.PLAYERS_PER_SEER);
    numberOfGuards = GetPlayerCountForRole(playerCount, GameConstants.PLAYERS_PER_GUARD);

    numberOfVillagers = playerCount\
        - numberOfWerewolves\
        - numberOfSeers\
        - numberOfGuards;

    if (numberOfVillagers < 0):
        LogUtility.Error("Cannot have a game with less than 0 villagers.", game);

    if (numberOfVillagers == 0):
        LogUtility.Warning("Game has 0 villagers.", game);

    rolesBag = sum([\
        numberOfWerewolves * [Werewolf()],\
        numberOfSeers * [Seer()],\
        numberOfGuards * [Guard()],\
        numberOfVillagers * [Villager()]], []);

    for player in players:
        roleType = random.choice(rolesBag);
        rolesBag.remove(roleType);

        player._Player__role = roleType;

        LogUtility.Information(f"'{player.Name}' is a {player.Role.Type}.", game);

    return;
Exemple #2
0
    def Join(self, player):
        if self.IsFull:
            # can't really be hit by normal users, this can only get hit by trying to add agents
            LogUtility.Warning(
                f"'{player.Name}' cannot join the game, the game is full!",
                self)
            return

        # TODO: This is kind of nasty and we should probably have a server player
        # and a game instance player entity, but this will do as a first pass. This
        # implies that the server is a "common world" instead of having a meta-player identity
        player._Player__isReady = False
        self.__players.add(player)
        LogUtility.CreateGameMessage(f"'{player.Name}' has joined.", self)
        return