コード例 #1
0
ファイル: WinCondition.cs プロジェクト: p-svacha/TheWorldGame
 protected override void SetInitialRandomValues()
 {
     Type = WinConditionType.TotalElectionsWon; // GetRandomType();
     Time = WinConditionTime.Value;             // GetRandomTime();
     if (Time == WinConditionTime.Year)
     {
         ConditionValue = GetRandomConditionValue(MinYear, MaxYear, StepYear);
     }
     else
     {
         if (Type == WinConditionType.TotalElectionsWon)
         {
             ConditionValue = GetRandomConditionValue(MinElectionWins, MaxElectionWins, StepElectionWins);
         }
         else if (Type == WinConditionType.TotalSeatsWon)
         {
             ConditionValue = GetRandomConditionValue(MinSeatWins, MaxSeatWins, StepSeatWins);
         }
         else if (Type == WinConditionType.TotalDistrictsWon)
         {
             ConditionValue = GetRandomConditionValue(MinDistrictWins, MaxDistrictWins, StepDistrictWins);
         }
         else if (Type == WinConditionType.TotalVotes)
         {
             ConditionValue = GetRandomConditionValue(MinTotalVotes, MaxTotalVotes, StepTotalVotes);
         }
     }
 }
コード例 #2
0
ファイル: WinCondition.cs プロジェクト: p-svacha/TheWorldGame
        private Party GetCurrentLeader(WinConditionType type)
        {
            switch (type)
            {
            case WinConditionType.TotalElectionsWon:
                return(Game.Parties.OrderByDescending(x => x.TotalElectionsWon).First());

            case WinConditionType.TotalDistrictsWon:
                return(Game.Parties.OrderByDescending(x => x.TotalDistrictsWon).First());

            case WinConditionType.TotalSeatsWon:
                return(Game.Parties.OrderByDescending(x => x.TotalSeatsWon).First());

            case WinConditionType.TotalVotes:
                return(Game.Parties.OrderByDescending(x => x.TotalVotes).First());
            }
            throw new System.Exception("Win condition type not handled");
        }
コード例 #3
0
ファイル: WinCondition.cs プロジェクト: p-svacha/TheWorldGame
        /// <summary>
        /// Returns the winner party. If the game is not over yet, returns null.
        /// </summary>
        private Party GetWinner(WinConditionType type, WinConditionTime time, int conditionValue)
        {
            switch (time)
            {
            case WinConditionTime.Year:
                if (Game.Year < conditionValue)
                {
                    return(null);
                }
                else
                {
                    return(GetCurrentLeader(type));
                }

            case WinConditionTime.Value:
                Party leader = GetCurrentLeader(type);
                switch (type)
                {
                case WinConditionType.TotalElectionsWon:
                    if (leader.TotalElectionsWon < conditionValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(leader);
                    }

                case WinConditionType.TotalSeatsWon:
                    if (leader.TotalSeatsWon < conditionValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(leader);
                    }

                case WinConditionType.TotalDistrictsWon:
                    if (leader.TotalDistrictsWon < conditionValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(leader);
                    }

                case WinConditionType.TotalVotes:
                    if (leader.TotalVotes < conditionValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(leader);
                    }
                }
                throw new System.Exception("Win condition type not handled");
            }
            throw new System.Exception("Win condition time not handled");
        }