コード例 #1
0
ファイル: Program.cs プロジェクト: stambi4a/AdvancedOOP
        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var soldiersWithIds = new Dictionary <string, ISoldier>();

            while (true)
            {
                try
                {
                    var input = Console.ReadLine();
                    if (input == "End")
                    {
                        break;
                    }

                    var soldierParams = input.Split();
                    var soldier       = SoldierFactory.CreateSoldier(soldierParams, soldiersWithIds);
                    Console.WriteLine(soldier);
                    soldiersWithIds.Add(soldier.Id, soldier);
                }
                catch (InvalidCorpsTypeException)
                {
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var soldiers = new List <ISoldier>();

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                var tokens      = input.Split();
                var soldierType = tokens[0];
                var id          = int.Parse(tokens[1]);
                var firstName   = tokens[2];
                var lastName    = tokens[3];
                var salary      = decimal.Parse(tokens[4]);

                ISoldier soldier = null;

                try
                {
                    soldier = SoldierFactory.CreateSoldier(soldiers, tokens, soldierType, id, firstName, lastName, salary);
                }
                catch
                {
                }
                soldiers.Add(soldier);
            }

            foreach (var soldier in soldiers)
            {
                Console.WriteLine(soldier);
            }
        }
コード例 #3
0
    public void GiveInputToGameController(string input)
    {
        var data = input.Split();

        if (data[0] == "Soldier")
        {
            if (data.Length == 6)
            {
                SoldierFactory soldiersFactory = new SoldierFactory();

                string soldierType = data[1];
                string name        = data[2];
                int    age         = int.Parse(data[3]);
                double experience  = double.Parse(data[4]);
                double endurance   = double.Parse(data[5]);

                ISoldier soldier = soldiersFactory.CreateSoldier(soldierType, name, age, experience, endurance);

                if (weraHouse.TryEquipSoldier(soldier) == true)
                {
                    AddSoldierToArmy(soldier);
                }
                else
                {
                    string massage = string.Format(OutputMessages.SoldierCannotBeEquiped, soldier.GetType().Name, soldier.Name);
                    throw new System.ArgumentException(massage);
                }
            }
            else if (data[1] == "Regenerate")
            {
                string soldiersType = data[2];

                army.RegenerateTeam(soldiersType);
            }
        }
        else if (data[0].Equals("WareHouse"))
        {
            AmmunitionFactory ammunitionFactory = new AmmunitionFactory();

            string name   = data[1];
            int    number = int.Parse(data[2]);

            AddAmmunitions(ammunitionFactory.CreateAmmunition(name), number);
        }
        else if (data[0].Equals("Mission"))
        {
            IMissionFactory missionFactory = new MissionFactory();

            string type            = data[1];
            double scoreToComplete = double.Parse(data[2]);

            IMission mission = missionFactory.CreateMission(type, scoreToComplete);

            consoleWriter.AppendLine(missionController.PerformMission(mission).Trim());
        }
    }
コード例 #4
0
ファイル: TestClass.cs プロジェクト: tanyta78/CSharpOOPAdv
    public void TestMethod()
    {
        Type missContType = typeof(MissionController);

        this.army = new Army();
        var ranker   = SoldierFactory.CreateSoldier("Ranker", "Ivan", 47, 23, 100);
        var corporal = SoldierFactory.CreateSoldier("Corporal", "Ivaylo", 21, 78, 100);

        this.army.AddSoldier(ranker);
        this.army.AddSoldier(corporal);
        var missionEasy = MissionFactory.CreateMission("Easy", 1);
    }
コード例 #5
0
    public void Run()
    {
        string inputLine;

        while ((inputLine = this.reader.ReadLine()) != TerminatingCommand)
        {
            string[] cmdArgs = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            switch (cmdArgs[0])
            {
            case "Soldier":
                //to do soldier Soldier Ranker Ivan 28 55 100

                if (cmdArgs.Length == 3)
                {
                    //to do soldier regenerate
                }
                else
                {
                    string   type           = cmdArgs[1];
                    string   name           = cmdArgs[2];
                    int      age            = int.Parse(cmdArgs[3]);
                    double   experience     = double.Parse(cmdArgs[4]);
                    double   endurance      = double.Parse(cmdArgs[6]);
                    ISoldier currentSoldier = SoldierFactory.CreateSoldier(type, name, age, experience, endurance);
                    foreach (var weapon in currentSoldier.Weapons)
                    {
                    }
                }

                break;

            case "WareHouse":
                string ammunitionName = cmdArgs[1];
                int    number         = int.Parse(cmdArgs[2]);

                IAmmunition currentAmmunition = AmmunitionFactory.CreateAmmunition(ammunitionName);

                if (!this.WareHouse.Storage.ContainsKey(currentAmmunition))
                {
                    this.WareHouse.Storage.Add(currentAmmunition, 0);
                }

                this.WareHouse.Storage[currentAmmunition] += number;

                break;

            case "Mission":
                //to do mission
                break;
            }
        }
    }
コード例 #6
0
    public void Run()
    {
        string input = Console.ReadLine();

        while (input != "End")
        {
            List <string> cmdArg = input.Split().ToList();
            string        type   = cmdArg[0];
            cmdArg.RemoveAt(0);
            soldierFactory.CreateSoldier(type, cmdArg);
            input = Console.ReadLine();
        }
        soldierFactory.PrintResult();
    }
コード例 #7
0
    private static void GatheringArmy(List <Soldier> soldiers)
    {
        while (true)
        {
            string[] cmdArgs = Console.ReadLine().Split();

            if (cmdArgs[0] == "End")
            {
                break;
            }

            Soldier currentSoldier = SoldierFactory.CreateSoldier(cmdArgs, soldiers);

            if (currentSoldier != null)
            {
                soldiers.Add(currentSoldier);
            }
        }
    }
コード例 #8
0
    public void TestSuccessMissionCounter()
    {
        //Arrange
        //IWareHouse wareHouse = new WareHouse();
        //IArmy army = new Army();
        ISoldierFactory soldierFactory = new SoldierFactory();

        //Act
        this.wareHouse.AddAmmunitions("AutomaticMachine", 4);
        this.wareHouse.AddAmmunitions("Gun", 6);
        this.wareHouse.AddAmmunitions("Helmet", 20);
        var soldier = soldierFactory.CreateSoldier("Ranker", "Ivan", 28, 55, 100);

        this.army.AddSoldier(soldier);

        this.stu.PerformMission(new Easy(1));

        //Assert
        Assert.AreEqual(1, this.stu.SuccessMissionCounter);
    }
コード例 #9
0
ファイル: LastArmyMain.cs プロジェクト: nayots/SoftUni
    private static void Main()
    {
        SoldierFactory    fac  = new SoldierFactory();
        AmmunitionFactory afac = new AmmunitionFactory();
        MissionFactory    mfac = new MissionFactory();

        var sold = fac.CreateSoldier("Ranker", "Ivan", 10, 10, 10);

        var ammo = afac.CreateAmmunition("Gun");

        var m = mfac.CreateMission("Easy", 100);

        IReader reader = new ConsoleReader();
        IWriter writer = new ConsoleWriter();

        IEngine engine = new Engine(reader, writer);

        engine.Run();

        //TryToGetSomePointsFromJudge();
    }
コード例 #10
0
    public static void Main(string[] args)
    {
        string input = Console.ReadLine();

        List <ISoldier> army = new List <ISoldier>();

        while (input != "End")
        {
            try
            {
                army.Add(SoldierFactory.CreateSoldier(input));
            }
            catch (Exception)
            {
            }
            input = Console.ReadLine();
        }

        foreach (var soldier in army)
        {
            Console.WriteLine(soldier);
        }
    }
コード例 #11
0
    //Метод на който подаваме инпута
    public void GiveInputToGameController(string input)
    {
        // сплитваме
        var data = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        //проверяваме каква е командата от инпута
        if (data[0].Equals("Soldier"))
        {
            string type       = string.Empty;
            string name       = string.Empty;
            int    age        = 0;
            int    experience = 0;

            //double speed = 0d; // ненужна променлива
            double endurance = 0d;
            //double motivation = 0; // ненужна променлива
            //double maxWeight = 0d; // ненужна променлива

            if (data.Length == 3)
            {
                type = data[1];
                name = data[2];
            }
            else
            {
                type       = data[1];
                name       = data[2];
                age        = int.Parse(data[3]);
                experience = int.Parse(data[4]);
                //speed = double.Parse(data[5]);
                endurance = double.Parse(data[6]);
                // motivation = double.Parse(data[7]);
                //maxWeight = double.Parse(data[8]);
            }

            var soldiersFactory = new SoldierFactory();
            var soldier         = soldiersFactory.CreateSoldier(type, name, age, experience, endurance);
            //switch (type)
            //{
            //    case "Ranker":
            //        var ranker = soldiersFactory.GenerateRanker(name, age, experience, endurance);

            //        //AddSoldierToArmy(ranker, type);
            //        break;
            //    case "Corporal":
            //        var corporal = soldiersFactory.GenerateCorporal(name, age, experience, endurance);
            //        // AddSoldierToArmy(corporal, type);
            //        break;
            //    case "Special-Force":
            //        var specialForce = soldiersFactory.GenerateSpecialForce(name, age, experience, endurance);
            //        // AddSoldierToArmy(specialForce, type);
            //        break;
            //    case "Regenerate":
            //        var soldierController = new SoldierController(); ;
            //        soldierController.TeamRegenerate(army, name);
            //        break;
            //        //case "Vacation": // излишни методи
            //        //    SoldierController.TeamGoesOnVacation(army, name);
            //        //    break;
            //        //case "Bonus":
            //        //    SoldierController.TeamGetBonus(army, name);
            //        //    break;
            //}
        }
        else if (data[0].Equals("WareHouse"))
        {
            string name              = data[1];
            int    number            = int.Parse(data[2]);
            var    ammunitionFactory = new AmmunitionFactory();
            var    ammunition        = ammunitionFactory.CreateAmmunition(name);
            this.AddAmmunitions(ammunition);
            // AddAmmunitions(ammunitionFactory.CreateAmmunitions(name, number));
        }
        else if (data[0].Equals("Mission"))
        {
            //Трябва да се направи проверка за това каква мисия да бъде стартирана и изобщо
            //има ли смисъл от тези няколко вида мисии и как да се разбере кога коя мисия да бъде изпълнена
            //this.MissionControllerField.PerformMission(new Easy());
            var missionFactory = new MissionFactory();
            var mission        = missionFactory.CreateMission(data[1], double.Parse(data[2]));
        }
    }
コード例 #12
0
    public void GiveInputToGameController(string input)
    {
        var data = input.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries);
        var cmd  = data[0];

        data = data.Skip(1).ToArray();

        if (data[0].Equals("Soldier"))
        {
            string type = string.Empty;

            if (data[1].Equals("Regenerate"))
            {
                type = data[2];

                army.RegenerateTeam(type);
            }

            string name       = string.Empty;
            int    age        = 0;
            int    experience = 0;
            double speed      = 0d;
            double endurance  = 0d;
            double motivation = 0;
            double maxWeight  = 0d;

            if (data.Length == 3)
            {
                type = data[1];
                name = data[2];
            }
            else
            {
                type       = data[0];
                name       = data[1];
                age        = int.Parse(data[2]);
                experience = int.Parse(data[3]);
                speed      = double.Parse(data[4]);
                endurance  = double.Parse(data[5]);
            }

            soldierFactory.CreateSoldier(type, name, age, experience, endurance);
        }
        else if (data[0].Equals("WareHouse"))
        {
            string name   = data[1];
            int    number = int.Parse(data[2]);

            for (int i = 0; i < number; i++)
            {
                Type        ammoType     = Type.GetType(name);
                IAmmunition ammoInstance = Activator.CreateInstance(ammoType) as IAmmunition;

                AddAmmunitions(ammoInstance);
            }
        }
        else if (data[0].Equals("Mission"))
        {
            string type  = data[1];
            double score = double.Parse(data[2]);

            switch (type)
            {
            case "Easy":
                this.MissionControllerField.PerformMission(new Easy(score));
                break;

            case "Medium":
                this.MissionControllerField.PerformMission(new Medium(score));
                break;

            case "Hard":
                this.MissionControllerField.PerformMission(new Hard(score));
                break;
            }
        }
    }