Exemple #1
0
        public override MissionBase Generate()
        {
            while (true)
            {
                try
                {
                    LogicMission logicMission = new LogicMission();

                    logicMission.SetAllRandomValues();

                    List <int> right = new List <int>();
                    List <int> wrong = new List <int>();

                    for (int i = logicMission.numInFirst - 15; i < logicMission.numInFirst + 15; i++)
                    {
                        if (logicMission.IsRight(i))
                        {
                            right.Add(i);
                        }
                        else
                        {
                            wrong.Add(i);
                        }
                    }

                    int    rightAnswer = rnd.Next(0, 4);
                    string nums        = "";
                    for (int i = 0; i < 4; i++)
                    {
                        if (i == rightAnswer)
                        {
                            nums += $"{i + 1}. {right.OrderBy(x => rnd.Next()).ToArray()[0]}\n";
                            continue;
                        }
                        int w = wrong.OrderBy(x => rnd.Next()).ToArray()[0];
                        wrong.Remove(w);
                        nums += $"{i + 1}. {w}\n";
                    }

                    string q = $"Среди чисел выберите те, которые удовлетворяют условию\n" +
                               $"{logicMission.GetString()}\n{nums}";

                    var mission = new TextMission(NumOfMission, MissionName, q, (rightAnswer + 1).ToString());
                    return(mission);
                }
                catch { }
            }
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._missionData != null)
            {
                LogicMission mission = level.GetMissionManager().GetMissionByData(this._missionData);

                if (mission != null)
                {
                    mission.StateChangeConfirmed();
                    return(0);
                }

                return(-2);
            }

            return(-1);
        }