private void HandleGameOver()
        {
            Debug.Log("Game over");

            var winningPlayer = currentRoundScores.SortedByDescendingScores()[0];

            AFEventManager.INSTANCE.PostEvent(AFEvents.GameOver(winningPlayer.PlayerNumber(), winningPlayer.Score(), winningPlayer.PlayerColor()));
        }
Esempio n. 2
0
        void HandlePlayerKilledEvent(KilledEventPayload payload)
        {
            var killerScore = currentRoundScores.GetScoreForPlayer <UndeadScore>(payload.playerNumberOfKiller);
            var killedScore = currentRoundScores.GetScoreForPlayer <UndeadScore>(payload.playerNumberOfKilledPlayer);

            if (killerScore.Undead && killedScore.Undead)
            {
                // Undead player killed another undead player.
                // This is uninteresting. Won't generate a Scoring event
                return;
            }

            if (payload.playerNumberOfKilledPlayer == payload.playerNumberOfKiller)
            {
                // Player killed itself, should become undead. Won't generate a Scoring event
                killedScore.Undead = true;
                MakeUndead(PlayerFetcher.FindPlayerByPlayerNumber(killedScore.PlayerNumber()));
            }
            else
            {
                // Player killed another player. Will generate a Scoring event
                var scoreForKillV2 = killerScore.Undead ? UndeadKillPoints : AliveKillPoints;
                killerScore.IncreaseScoreBy(scoreForKillV2);

                if (!killedScore.Undead)
                {
                    killedScore.Undead = true;
                    MakeUndead(PlayerFetcher.FindPlayerByPlayerNumber(killedScore.PlayerNumber()));
                }
                AFEventManager.INSTANCE.PostEvent(AFEvents.Score(payload.playerNumberOfKiller, killerScore.Score(), killerScore.Score()));
            }
            killedScore.Deaths++;

            if (currentRoundScores.DoTrueForAllCheck(score => ((UndeadScore)score).Undead))
            {
                if (IsEntireGameOver())
                {
                    Debug.Log("Game over, all players are undead!");
                    var winningScoreForRound = currentRoundScores.SortedByDescendingScores()[0];
                    AFEventManager.INSTANCE.PostEvent(AFEvents.GameOver(winningScoreForRound.PlayerNumber(), winningScoreForRound.Score(), winningScoreForRound.PlayerColor()));
                }
                else
                {
                    Debug.Log("Round over, all players are undead!");
                    var winningScore = currentRoundScores.SortedByDescendingScores()[0];
                    AFEventManager.INSTANCE.PostEvent(AFEvents.RoundOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor()));
                }
            }
        }
Esempio n. 3
0
        public bool HandleEvent(AFEvent afEvent)
        {
            switch (afEvent.type)
            {
            case AFEventType.KILLED:
            {
                HandlePlayerKilledEvent((KilledEventPayload)afEvent.payload);
                return(true);
            }

            case AFEventType.PLAYERS_ALL_CREATED:
            {
                var payload = (PlayersAllCreatedPayload)afEvent.payload;
                HandleGameStart(payload.AllPlayers);
                return(true);
            }

            case AFEventType.COUNT_DOWN_FINISHED:
            {
                var payload = (CountDownFinishedPayload)afEvent.payload;
                if (!payload.TimerName.Equals(RoundTimerName))
                {
                    break;
                }
                countDownTimerInstance.StopTimer();
                if (IsEntireGameOver())
                {
                    Debug.Log("Game over, time ran out!");
                    var winningScore = currentRoundScores.SortedByDescendingScores()[0];
                    AFEventManager.INSTANCE.PostEvent(AFEvents.GameOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor()));
                }
                else
                {
                    Debug.Log("Round over, time ran out!");
                    var winningScore = currentRoundScores.SortedByDescendingScores()[0];
                    AFEventManager.INSTANCE.PostEvent(AFEvents.RoundOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor()));
                }
                break;
            }

            case AFEventType.GAME_START:
            {
                countDownTimerInstance.StartTimer();
                break;
            }
            }
            return(false);
        }