public override void ExecuteCommand(GameModel model)
        {
            ValidateCommand(model);

            model.CurrentMission.ValuateMissionVote();

            int succeedCount = model.Missions.
                               Where(mis => mis != null).
                               Count(mis => mis.MissionResult == MissionResult.Succeed);

            int failCount = model.Missions.
                            Where(mis => mis != null).
                            Count(mis => mis.MissionResult == MissionResult.Fail);

            if (succeedCount < 3 && failCount < 3)
            {
                model.CurrentLeader =
                    Utilities.NextOrFirst <Player>(model.CurrentLeader, model.Players);
                ++model.MissionNumber;
                model.GamePhase = GamePhase.TeamPicking;
            }
            else
            {
                InvokedCommand = new EvaluateGameResult();
            }
        }
Exemple #2
0
        public override void ExecuteCommand(GameModel model)
        {
            ValidateCommand(model);

            model.CurrentVote.ValuateTeamVote();

            Vote vote = model.Missions[(int)MissionNumber].Votes[(int)VoteNumber];

            if (vote.VoteResult == VoteType.Approved)
            {
                model.CurrentMission.SetTeam(vote.Team);
                model.GamePhase = GamePhase.MissionVoting;
                //ConsoleLog = "The team is approved. \n Now the mission team should vote on mission success.";
            }
            else if (vote.VoteResult == VoteType.Rejected &&
                     model.CurrentMission.VoteNumber < VoteNumber.Last)
            {
                ++model.CurrentMission.VoteNumber;
                model.CurrentLeader = Utilities.NextOrFirst <Player>(model.CurrentLeader, model.Players);
                model.GamePhase     = GamePhase.TeamPicking;
                //ConsoleLog = "The team is rejected. \n Now " + model.CurrentLeader + "can pick a mission team.";
            }
            else
            {
                model.GamePhase  = GamePhase.GameOver;
                model.GameResult = MissionResult.Fail;

                InvokedCommand = new EvaluateGameResult();

                //string ConsoleLog = "The team is rejected \n" +
                //            "Forces of Good failed to choose a mission team. Forces of Evil prevail.";
                //Utilities.LogToFile(ConsoleLog);
            }
        }
Exemple #3
0
        public static BaseCommand CommandFromString(String strCommand, GameModel model)
        {
            if (strCommand.StartsWith("EvaluateGameResult "))
            {
                String[]      split      = strCommand.Split(' ');
                MissionResult gameResult = (MissionResult)Int32.Parse(split[1]);
                DefeatType    defeatType = (DefeatType)Int32.Parse(split[2]);

                EvaluateGameResult command = new EvaluateGameResult();
                command.GameResult   = gameResult;
                command.DefeatReason = defeatType;

                return(command);
            }

            if (strCommand.StartsWith("EvaluateMissionVote "))
            {
                String[]            split         = strCommand.Split(' ');
                MissionNumber       missionNumber = (MissionNumber)Int32.Parse(split[1]);
                EvaluateMissionVote command       = new EvaluateMissionVote(missionNumber);
                return(command);
            }

            if (strCommand.StartsWith("EvaluateTeamVote "))
            {
                String[]         split         = strCommand.Split(' ');
                MissionNumber    missionNumber = (MissionNumber)Int32.Parse(split[1]);
                VoteNumber       voteNumber    = (VoteNumber)Int32.Parse(split[2]);
                EvaluateTeamVote command       = new EvaluateTeamVote(missionNumber, voteNumber);
                return(command);
            }

            if (strCommand.StartsWith("PickTeam "))
            {
                String[] split     = strCommand.Split(' ');
                int      leaderId  = Int32.Parse(split[1]);
                string   teamCode  = split[2];
                int      playerNum = teamCode.Length;

                HashSet <int> playerTeamIds = new HashSet <int>();
                for (int i = 0; i < teamCode.Length; i++)
                {
                    if (teamCode[i] == '1')
                    {
                        playerTeamIds.Add(i);
                    }
                }

                PickTeamCommand command = new PickTeamCommand(leaderId, playerTeamIds, playerNum);
                return(command);
            }

            if (strCommand.StartsWith("VoteMission "))
            {
                String[]           split       = strCommand.Split(' ');
                int                playerId    = Int32.Parse(split[1]);
                MissionResult      missionVote = (MissionResult)Int32.Parse(split[2]);
                VoteMissionCommand command     = new VoteMissionCommand(playerId, missionVote);
                return(command);
            }

            if (strCommand.StartsWith("VoteTeam "))
            {
                String[]        split    = strCommand.Split(' ');
                int             playerId = Int32.Parse(split[1]);
                VoteType        teamVote = (VoteType)Int32.Parse(split[2]);
                VoteTeamCommand command  = new VoteTeamCommand(playerId, teamVote);
                return(command);
            }

            if (strCommand.StartsWith("ChangePlayer "))
            {
                String[]            split      = strCommand.Split(' ');
                int                 playerId   = Int32.Parse(split[1]);
                PlayerType          playerType = (PlayerType)Int32.Parse(split[2]);
                String              playerName = split[3];
                ChangePlayerCommand command    = new ChangePlayerCommand(playerId, playerType, playerName);
                return(command);
            }

            throw new ArgumentException("Command string not found: " + strCommand);
        }