コード例 #1
0
        public void DoNextPhase(bool eraseActions = true)
        {
            if (GameEnded)
            {
                return;
            }

            if (eraseActions)
            {
                ClearActions();
            }

            var troopsInStartupPhase = GetTroopsInStartupPhase();

            var turnManager = GetTurnManager(CurrentPlayer);

            if (troopsInStartupPhase > 0)
            {
                TroopsToDeploy = troopsInStartupPhase;
                try
                {
                    CurrentPlayer.Deploy(turnManager, troopsInStartupPhase);
                }
                catch (Exception e)
                {
                    Log.AddException(e);
                }
                SetNextPlayer();
            }
            else
            {
                if (CurrentPhase == EPhase.Deploy)
                {
                    if (CurrentPlayer == startPlayer)
                    {
                        Turn++;

                        if (Turn > MaximumAmountOfTurns)
                        {
                            var winner = GetPlayerWithMostCountries();
                            Log.AddMessage(
                                string.Format("----- {0} has won the game with {1} countries, turn limit reached",
                                              winner.Name,
                                              turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(winner).Count));
                            statistics.AddCurrentGameResults(winner);
                            GameEnded = true;
                            return;
                        }
                    }

                    var troopsToDeploy = new DeploymentCounter(CurrentPlayer, turnManager.GetGameInfo()).GetTroopsToDeploy();
                    Log.AddGameInfo(CurrentPhase, troopsToDeploy);
                    TroopsToDeploy = troopsToDeploy;

                    try
                    {
                        CurrentPlayer.Deploy(turnManager, troopsToDeploy);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }
                }
                else if (CurrentPhase == EPhase.Attack)
                {
                    Log.AddGameInfo(CurrentPhase);

                    try
                    {
                        CurrentPlayer.Attack(turnManager);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }

                    if (PlayerHasWon())
                    {
                        Log.AddMessage(string.Format("----- {0} has won the game with {1} countries", CurrentPlayer.Name,
                                                     turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(CurrentPlayer).Count));
                        statistics.AddCurrentGameResults(CurrentPlayer);
                        GameEnded = true;
                        return;
                    }
                }
                else if (CurrentPhase == EPhase.Move)
                {
                    Log.AddGameInfo(CurrentPhase);
                    TroopsToMove = 7;

                    try
                    {
                        CurrentPlayer.Move(turnManager);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }

                    SetNextPlayer();
                }

                SetNextPhase();
            }
        }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: resc/Risk
        public void DoNextPhase(bool eraseActions = true)
        {
            if (GameEnded) return;

            if (eraseActions)
            {
                ClearActions();
            }

            var troopsInStartupPhase = GetTroopsInStartupPhase();

            var turnManager = GetTurnManager(CurrentPlayer);
            if (troopsInStartupPhase > 0)
            {
                TroopsToDeploy = troopsInStartupPhase;
                try
                {
                    CurrentPlayer.Deploy(turnManager, troopsInStartupPhase);
                }
                catch (Exception e)
                {
                    Log.AddException(e);
                }
                SetNextPlayer();
            }
            else
            {
                if (CurrentPhase == EPhase.Deploy)
                {
                    if (CurrentPlayer == startPlayer)
                    {
                        Turn++;

                        if (Turn > MaximumAmountOfTurns)
                        {
                            var winner = GetPlayerWithMostCountries();
                            Log.AddMessage(
                                string.Format("----- {0} has won the game with {1} countries, turn limit reached",
                                              winner.Name,
                                              turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(winner).Count));
                            statistics.AddCurrentGameResults(winner);
                            GameEnded = true;
                            return;
                        }
                    }

                    var troopsToDeploy = new DeploymentCounter(CurrentPlayer, turnManager.GetGameInfo()).GetTroopsToDeploy();
                    Log.AddGameInfo(CurrentPhase, troopsToDeploy);
                    TroopsToDeploy = troopsToDeploy;

                    try
                    {
                        CurrentPlayer.Deploy(turnManager, troopsToDeploy);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }
                }
                else if (CurrentPhase == EPhase.Attack)
                {
                    Log.AddGameInfo(CurrentPhase);

                    try
                    {
                        CurrentPlayer.Attack(turnManager);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }

                    if (PlayerHasWon())
                    {
                        Log.AddMessage(string.Format("----- {0} has won the game with {1} countries", CurrentPlayer.Name,
                                                     turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(CurrentPlayer).Count));
                        statistics.AddCurrentGameResults(CurrentPlayer);
                        GameEnded = true;
                        return;
                    }
                }
                else if (CurrentPhase == EPhase.Move)
                {
                    Log.AddGameInfo(CurrentPhase);
                    TroopsToMove = 7;

                    try
                    {
                        CurrentPlayer.Move(turnManager);
                    }
                    catch (Exception e)
                    {
                        Log.AddException(e);
                    }

                    SetNextPlayer();
                }

                SetNextPhase();
            }
        }