Beispiel #1
0
        public void TestMinerLieutenant()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            Piece def = new Lieutenant(Ownership.SecondPlayer);

            Assert.True(def == ConflictHandler.Handle(att, def));
        }
Beispiel #2
0
    public void Screenshot()
    {
        string filename = Lieutenant.NextFile("Logs\\screen", ".png");

        filename = filename.Substring(0, filename.IndexOf(".png"));
        Screenshot(filename);
    }
Beispiel #3
0
        static void Main(string[] args)
        {
            Lieutenant lieutenant = new Lieutenant();
            Major      major      = new Major();
            General    general    = new General();

            List <Officer> officers = new List <Officer> {
                lieutenant, major, general
            };

            foreach (var officer in officers)
            {
                Type       officerType = officer.GetType();                                                    //Get Officer Type
                object[]   attributes  = officerType.GetCustomAttributes(typeof(OfficerAttribut), false);      //Boxing officer Attributes
                MethodInfo methodInfo  = officerType.GetMethod("Manage");                                      //Get Officers Method info
                object[]   methodAttr  = methodInfo.GetCustomAttributes(typeof(OfficerManageAttribut), false); //Boxing Method Attributes

                //After unboxing show Officers Attributes
                foreach (OfficerAttribut attribute in attributes)
                {
                    Console.WriteLine($"{officerType.Name} has attribute {attribute.Responsibility}");
                }
                //After unboxing show Officers Method Attributes
                foreach (OfficerManageAttribut manageAttribut in methodAttr)
                {
                    Console.WriteLine($"\t{officerType.Name} Method \"{methodInfo.Name}\" has attribute {manageAttribut.Responsibility}");
                }
            }
        }
Beispiel #4
0
        protected static Dictionary <Type, MethodInfo> _convert = new Dictionary <Type, MethodInfo>(); // type -> convert. Used to easily convert strings into other types

        #endregion

        #region Lifetimes

        public void AddLieutenant(object uses)
        {
            string classname = uses.GetType().Name.ToLower();

            if (_lieutenants.ContainsKey(classname))
            {
                Console.WriteLine(classname + " already exists");
                return;
            }
            Lieutenant ret = new Lieutenant(uses);

            _lieutenants.Add(classname, ret);
            foreach (List <MethodInfo> LMI in ret.Methods.Values)
            {
                foreach (MethodInfo mis in LMI)
                {
                    string name = mis.Name.ToLower();
                    if (!_methodtolieutenant.ContainsKey(name))
                    {
                        _methodtolieutenant.Add(name, new List <Lieutenant>());
                    }
                    if (!_methodtolieutenant[name].Contains(ret))
                    {
                        _methodtolieutenant[name].Add(ret);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Converts an input (eg. "math.sin" or "sin") into its lt and method (in this case, math lieuteneant and "sin")
        /// Returns true if found class and method
        /// Returns false otherwise, with a message explaining what went wrong
        /// </summary>
        /// <param name="input"></param>
        /// <param name="lt"></param>
        /// <param name="methodname"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        bool _dotnotation(string input, out Lieutenant lt, out string methodname, out string message)
        {
            message    = "";
            input      = input.ToLower();
            lt         = null;
            methodname = "";
            int indexofdot = input.IndexOf('.');

            if (indexofdot == input.Length - 1)
            {
                return(false);
            }
            if (indexofdot != -1)
            {
                string classname = input.Substring(0, indexofdot);
                if (!_lieutenants.ContainsKey(classname))
                {
                    message = "No classname " + classname;
                    return(false);
                }
                lt = _lieutenants[input.Substring(0, indexofdot)];

                methodname = input.Substring(indexofdot + 1);
            }
            else
            {
                methodname = input;
                if (_methodtolieutenant.ContainsKey(input))
                {
                    if (_methodtolieutenant[input].Count != 1)
                    {
                        string s = "";
                        foreach (Lieutenant l in _methodtolieutenant[input])
                        {
                            s += " " + l.CSObject.GetType().Name;
                        }
                        message = "Class options: " + s;
                        return(false);
                    }
                    else
                    {
                        lt = _methodtolieutenant[input][0];
                    }
                }
                else
                {
                    message = input + " is unknown class or method";
                    return(false);
                }
            }

            if (string.IsNullOrWhiteSpace(methodname) || lt == null)
            {
                message = "null class or methodname";
                return(false);
            }
            return(true);
        }
Beispiel #6
0
 public void Remove(Lieutenant lieutenantIn)
 {
     lieutenants.DeleteOne(lieutenant => lieutenant.Id == lieutenantIn.Id);
 }
Beispiel #7
0
 public void Update(string id, Lieutenant lieutenantIn)
 {
     lieutenants.ReplaceOne(lieutenant => lieutenant.Id == id, lieutenantIn);
 }
Beispiel #8
0
 public Lieutenant Create(Lieutenant lieutenant)
 {
     lieutenants.InsertOne(lieutenant);
     return(lieutenant);
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Here are the enlisted personnel in your military unit!\n");
            Private pvt = new Private();

            Console.WriteLine(pvt.assignRank(1));
            Console.WriteLine(pvt.assignQuote(1));
            Console.WriteLine($"My billet is {pvt.assignBillet(1)}");
            Console.WriteLine(pvt.myUniformQuality());
            Console.Write("\n");
            Sergeant sgt = new Sergeant();

            Console.WriteLine(sgt.assignRank(2));
            Console.WriteLine(sgt.assignQuote(2));
            Console.WriteLine($"My billet is {sgt.assignBillet(2)}");
            Console.WriteLine(sgt.myUniformQuality());
            Console.Write("\n");
            GunnerySergeant gysgt = new GunnerySergeant();

            Console.WriteLine(gysgt.assignRank(3));
            Console.WriteLine(gysgt.assignQuote(3));
            Console.WriteLine($"My billet is {gysgt.assignBillet(3)}");
            Console.WriteLine(gysgt.myUniformQuality());
            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("Here are the officer personnel in your military unit!\n");
            Lieutenant lt = new Lieutenant();

            Console.WriteLine(lt.assignRank(4));
            Console.WriteLine(lt.assignQuote(4));
            Console.WriteLine($"My billet is {lt.assignBillet(4)}");
            Console.WriteLine(lt.myUniformQuality());
            Console.Write("\n");
            Captain capt = new Captain();

            Console.WriteLine(capt.assignRank(5));
            Console.WriteLine(capt.assignQuote(5));
            Console.WriteLine($"My billet is {capt.assignBillet(5)}");
            Console.WriteLine(capt.myUniformQuality());
            Console.Write("\n");
            Major maj = new Major();

            Console.WriteLine(maj.assignRank(6));
            Console.WriteLine(maj.assignQuote(6));
            Console.WriteLine($"My billet is {maj.assignBillet(6)}");
            Console.WriteLine(maj.myUniformQuality());
            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("Here are the avalible vehicles in your unit");
            Console.Write("\n");
            Humvee humvee = new Humvee();

            Console.WriteLine(humvee.vehicleName(1));
            Console.WriteLine($"The amount of personnel required is {humvee.amtOfPersonnel()}");
            Console.WriteLine($"The {humvee.vehicleName(1)} operates on {humvee.vehicleTerrain(3)}.");
            Console.WriteLine($"The start noise is {humvee.strNoise()}.\nThe drive noise is {humvee.driNoise()}.\nThe stop noise is {humvee.stoNoise()}.");
            Console.Write("\n");
            Helicopter helicopter = new Helicopter();

            Console.WriteLine(helicopter.vehicleName(2));
            Console.WriteLine($"The amount of personnel required is {helicopter.amtOfPersonnel()}");
            Console.WriteLine($"The {helicopter.vehicleName(1)} operates on {helicopter.vehicleTerrain(2)}.");
            Console.WriteLine($"The start noise is {helicopter.strNoise()}.\nThe drive noise is {helicopter.driNoise()}.\nThe stop noise is {helicopter.stoNoise()}.");
            Console.Write("\n");
            Ship ship = new Ship();

            Console.WriteLine(ship.vehicleName(3));
            Console.WriteLine($"The amount of personnel required is {ship.amtOfPersonnel()}");
            Console.WriteLine($"The {ship.vehicleName(3)} operates on {ship.vehicleTerrain(1)}.");
            Console.WriteLine($"The start noise is {ship.strNoise()}.\nThe drive noise is {ship.driNoise()}.\nThe stop noise is {ship.stoNoise()}.");
            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("Here are the weapons your unit uses!");
            Rifle rifle = new Rifle();

            Console.WriteLine(rifle.assignName(1));
            Console.WriteLine(rifle.assignPersonnelAmount(1));
            Console.WriteLine($"Time to load your rifle...{rifle.assignLoadType(1)}");
            Console.Write("\n");
            Pistol pistol = new Pistol();

            Console.WriteLine(pistol.assignName(3));
            Console.WriteLine(rifle.assignPersonnelAmount(1));
            Console.WriteLine($"Time to load your pistol...{pistol.assignLoadType(3)}");
            Console.Write("\n");
            Howitzer howitzer = new Howitzer();

            Console.WriteLine(howitzer.assignName(2));
            Console.WriteLine(rifle.assignPersonnelAmount(4));
            Console.WriteLine($"Time to load your howitzer...{howitzer.assignLoadType(2)}");
            Console.ReadKey();
            Console.Clear();

            Attack attack = new Attack();
            Defend defend = new Defend();
            string test;
            int    check;

            int[] personnel;
            int[] vehicles;

            do
            {
                Console.WriteLine("Please enter the number of the mission you would like to conduct or exit the program!\n1. Attack\n2. Defend\n3. Exit the Program");
                test = Console.ReadLine();
                while (Int32.TryParse(test, out check) == false || check != 1 && check != 2 && check != 3)
                {
                    Console.WriteLine("You have not entered a valid menu option, please try again.");
                    test = Console.ReadLine();
                }
                switch (check)
                {
                case 1:
                    personnel = (int[])attack.amtAndTypeOfPersonnel(15, 5, 1, 3, 1, 1).Clone();     //using the billet structure as indexs where Riflemen starts at 0
                    Console.WriteLine($"The amount of Riflemen used in this is mission is : {personnel[0]}");
                    Console.WriteLine($"The amount of Platoon Sergeants used in this is mission is : {personnel[1]}");
                    Console.WriteLine($"The amount of Company Guns used in this is mission is : {personnel[2]}");
                    Console.WriteLine($"The amount of Lieutenants used in this is mission is : {personnel[3]}");
                    Console.WriteLine($"The amount of Company Comdaners used in this is mission is : {personnel[4]}");
                    Console.WriteLine($"The amount of Battalion Commanders used in this is mission is : {personnel[5]}\n");
                    vehicles = (int[])defend.amtAndTypeOfVehicles(5, 10, 2).Clone();     //using index 0 as Humvees, 1 as Helicopters, 2 as Ships
                    Console.WriteLine($"The amount of Humvees used in this mission is : {vehicles[0]}");
                    Console.WriteLine($"The amount of Helicopters used in this mission is : {vehicles[1]}");
                    Console.WriteLine($"The amount of Ships used in this mission is : {vehicles[2]}");
                    Console.ReadKey();
                    Console.Clear();
                    Console.WriteLine(attack.missStatement());
                    Console.Write("\n");
                    Console.ReadKey();
                    Console.WriteLine(attack.exec());
                    Console.Write("\n");
                    Console.ReadKey();
                    Console.WriteLine(attack.missFinish());
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case 2:
                    personnel = (int[])defend.amtAndTypeOfPersonnel(30, 5, 2, 5, 2, 1).Clone();
                    Console.WriteLine($"The amount of Riflemen used in this is mission is : {personnel[0]}");
                    Console.WriteLine($"The amount of Platoon Sergeants used in this is mission is : {personnel[1]}");
                    Console.WriteLine($"The amount of Company Guns used in this is mission is : {personnel[2]}");
                    Console.WriteLine($"The amount of Lieutenants used in this is mission is : {personnel[3]}");
                    Console.WriteLine($"The amount of Company Comdaners used in this is mission is : {personnel[4]}");
                    Console.WriteLine($"The amount of Battalion Commanders used in this is mission is : {personnel[5]}\n");
                    vehicles = (int[])defend.amtAndTypeOfVehicles(10, 20, 4).Clone();     //using index 0 as Humvees, 1 as Helicopters, 2 as Ships
                    Console.WriteLine($"The amount of Humvees used in this mission is : {vehicles[0]}");
                    Console.WriteLine($"The amount of Helicopters used in this mission is : {vehicles[1]}");
                    Console.WriteLine($"The amount of Ships used in this mission is : {vehicles[2]}");
                    Console.ReadKey();
                    Console.Clear();
                    Console.ReadKey();
                    Console.WriteLine(defend.missStatement());
                    Console.ReadKey();
                    Console.Write("\n");
                    Console.WriteLine(defend.exec());
                    Console.ReadKey();
                    Console.Write("\n");
                    Console.WriteLine(defend.missFinish());
                    Console.ReadKey();
                    Console.Clear();
                    break;
                }
            } while (check != 3);
            Console.WriteLine("Thanks for learning about inheritance with me :) Goodbye!");
        }