예제 #1
0
    def vote(self, player, choice):
        if self._state is not VoteTeam:
            # Now is not the time to vote on a team
            raise E.OutOfOrder('Now is not the time to vote on a team')
        if choice is None:
            # The player is retracting their vote
            self._submittedVotes.remove(player)
            return
        if not isinstance(choice, TeamVote):
            raise ValueError('Must specify a TeamVote type')
        self._submittedVotes.add(player)

        # If not everyone has voted, then we continue to wait
        if len(self._submittedVotes) != self._nPlayers:
            return

        # Tally the votes
        voteCount = Counter(p.getVote() for p in self._submittedVotes)
        self._submittedVotes = {}
        if voteCount[Approve] > voteCount[Reject]:
            # Team vote passes. Move on to the mission
            self._setState(OnMission)
        else:
            # Team vote fails
            self._nProposedTeams += 1
            if self._nProposedTeams == 5:
                # Bad team wins
                self._victory = Bad
                self._victoryReason = FiveRejectedTeams
                self.onGameOver(Bad, FiveRejectedTeams)
                return
            self._advanceLeader()
예제 #2
0
 def finalizeTeam(self, leader):
     if self._state is not MakeTeam:
         raise E.OutOfOrder('Cannot make a team at this time')
     if leader is not self._leader:
         raise E.RoleRulesViolation('Only the leader can finalize a team')
     if len(self._currentTeam) != self._missionSize[self._round]:
         raise E.TeamSizeError
     self._setState(VoteTeam)
예제 #3
0
 def removeFromTeam(self, leader, player):
     if self._state is not MakeTeam:
         raise E.OutOfOrder('Cannot make a team at this time')
     if leader is not self._leader:
         raise E.RoleRulesViolation('Only the leader can propose teams')
     self._currentTeam.remove(player)
     player.removeFromTeam()
     self.onTeamChange(self._currentTeam)
예제 #4
0
 def addToTeam(self, leader, player):
     if self._state is not MakeTeam:
         raise E.OutOfOrder('Cannot make a team at this time')
     if leader is not self._leader:
         raise E.RoleRulesViolation('Only the leader can propose teams')
     if len(self._currentTeam) >= self._missionSize[self._round]:
         raise E.TeamSizeError
     self._currentTeam.add(player)
     player.addToTeam()
     self.onTeamChange(self._currentTeam)
예제 #5
0
    def playerJoin(self, newPlayer):
        # Can only add players before the game has started
        if self._state is not CreateGame:
            raise E.OutOfOrder('Cannot add players once the game has started')
        # Make sure the player name isn't already taken
        if any(p.getName() == newPlayer.getName() for p in self._players):
            raise E.InvalidSetup('Name {} already taken'.format(
                newPlayer.getName()))

        # Setup the player and add him to the game
        newPlayer.setGame(self)
        newPlayer.setRole(self._unallocatedRoles.pop()())
        self._players.append(newPlayer)

        # Check if game is startable. If so, start it
        if len(self._players) == self._nPlayers:
            self._startGame()