Exemplo n.º 1
0
        public void EndGame()
        {
            if (TurnDirector.Ins.GetMyPlayer().HasLost)
            {
                ExitGame();
            }

            TurnDirector ins = TurnDirector.Ins;

            List <Player> wonPlayers   = new List <Player>();
            WinCondition  wonCondition = null;

            foreach (var winCondition in winConditions)
            {
                bool hasPlayerWon = false;

                foreach (var player in TurnDirector.Ins.ListPlayer)
                {
                    if (player.HasLost)
                    {
                        continue;
                    }

                    bool won = winCondition.CheckWinner(player);

                    if (won)
                    {
                        wonPlayers.Add(player);
                        hasPlayerWon = true;
                    }
                }

                if (hasPlayerWon)
                {
                    wonCondition = winCondition;
                    break;
                }
            }

            foreach (var player in wonPlayers)
            {
                player.Rank = 1;
            }


            int currentRank = TurnDirector.Ins.ListPlayer.Count;

            if (listPlayerEndTurn.Count > 0)
            {
                // Set rank for player lost

                listPlayerEndTurn.OrderBy(x => x.Item1); // Sort list player lose by the turn count they pass

                int currentTurnCount = listPlayerEndTurn[0].Item1;

                foreach (var playerEndTurn in listPlayerEndTurn)
                {
                    if (playerEndTurn.Item1 > currentTurnCount)
                    {
                        currentRank--;
                        currentTurnCount = playerEndTurn.Item1;
                    }

                    playerEndTurn.Item2.Rank = currentRank;
                }
                currentRank--;
            }

            // Set rank for player that hasn't lost but the winner appear
            foreach (var player in TurnDirector.Ins.ListPlayer)
            {
                if (wonPlayers.Contains(player) || player.HasLost)
                {
                    continue;
                }

                player.Rank = currentRank;
            }

            wonCondition.ShowWinScreen();

            //ExitGame();
        }
Exemplo n.º 2
0
 public WinConCheckAction(WinCondition wincon)
 {
     winCon = wincon;
 }