Exemple #1
0
        static void Main(string[] args)
        {
            Hunter hunter1 = new Hunter();

            Console.WriteLine(hunter1.ToString());
            hunter1.WriteToFile();
            hunter1 += 3;
            hunter1.Go(hunter1);
            Console.WriteLine(hunter1.ToString());
            Console.WriteLine("hunter1.GetHashCode() - " + hunter1.GetHashCode() + "\n");

            Hunter hunter2 = new Hunter();

            Console.WriteLine(hunter2.ToString() + "\n");

            Console.WriteLine("hunter1 > hunter2?");
            Console.WriteLine(hunter1 > hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 < hunter2?");
            Console.WriteLine(hunter1 < hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 == hunter2?");
            Console.WriteLine(hunter1 == hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 != hunter2?");
            Console.WriteLine(hunter1 != hunter2);
            Console.WriteLine();

            Shaman shaman = new Shaman();

            Console.WriteLine(shaman.ToString());
            shaman += 2;
            Console.WriteLine(shaman.ToString() + "\n");

            try
            {
                Hunter hunter3 = new Hunter();
                hunter3.HP = -30;
            }
            catch (InvalidParam exp)
            {
                Console.WriteLine(new String('!', 53));
                Console.WriteLine(exp.What());
            }
            finally
            {
                Console.WriteLine("\n----------Блок finally");

                GameHistory game = new GameHistory();

                Console.WriteLine(shaman.ToString() + "\n");

                game.History.Push(shaman.SaveState());
                shaman.RestoreState(game.History.Pop());
                Console.WriteLine("");
            }
        }
Exemple #2
0
 public bool Equals(ref Hunter obj)
 {
     if (this.Damage == obj.Damage && this.Dexterity == obj.Dexterity &&
         this.HP == obj.HP && this.Level == obj.Level)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #3
0
        static void Main(string[] args)
        {
            Hunter hunter1 = new Hunter();

            Console.WriteLine(hunter1.ToString());
            hunter1.WriteToFile();
            hunter1 += 3;
            hunter1.Go(hunter1);
            Console.WriteLine(hunter1.ToString());
            Console.WriteLine("hunter1.GetHashCode() - " + hunter1.GetHashCode() + "\n");

            Hunter hunter2 = new Hunter();

            Console.WriteLine(hunter2.ToString() + "\n");

            Console.WriteLine("hunter1 > hunter2?");
            Console.WriteLine(hunter1 > hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 < hunter2?");
            Console.WriteLine(hunter1 < hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 == hunter2?");
            Console.WriteLine(hunter1 == hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 != hunter2?");
            Console.WriteLine(hunter1 != hunter2);
            Console.WriteLine();

            Shaman shaman = new Shaman();

            Console.WriteLine(shaman.ToString());
            shaman += 2;
            Console.WriteLine(shaman.ToString() + "\n");

            try
            {
                Hunter hunter3 = new Hunter();
                hunter3.HP = -30;
            }
            catch (InvalidParam exp)
            {
                Console.WriteLine(new String('!', 53));
                Console.WriteLine(exp.What());
            }
            finally
            {
                Console.WriteLine("\n----------Блок finally");

                GameHistory gameHistory = new GameHistory();

                Console.WriteLine(shaman.ToString() + "\n");

                gameHistory.History.Push(shaman.SaveState());
                shaman.RestoreState(gameHistory.History.Pop());
                Console.WriteLine("");


                Game game = new Game();

                game.Attacked += Attack; //добавляем обработчик события
                Console.WriteLine("\t~~~~~Событие Attacked~~~~~");
                Console.WriteLine(hunter1.ToString());
                Console.WriteLine(shaman.ToString());
                Console.ReadLine();

                game.Battle(hunter1, shaman);
                Console.WriteLine(hunter1.ToString());
                Console.WriteLine(shaman.ToString());
                Console.ReadLine();

                game.Treated += Treat;
                Console.WriteLine("\t~~~~~Событие Treated~~~~~");
                Console.WriteLine(hunter2.ToString());
                Console.ReadLine();

                game.Treatment(shaman, hunter2);
                Console.WriteLine(hunter2);

                Console.ReadLine();

                Reflector.Write("Fighter");                                        //a
                Reflector.WriteAllPublicMethods("IAtack");                         //b
                Reflector.WriteFieldAndProperties("Memento");                      //c
                Reflector.WriteImplementedInterfaces("Hunter");                    //d
                Reflector.WriteNameOfMethodsWithSpecifiedType("Game", "Fighter");  //e
                Reflector.ReadArgsMethodFromFile("lab3.MyClass", "Color_Message"); //f
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string WritePath    = @"./info/text.json";
            string WritePathXml = @"./info/text.xml";

            try
            {
                City     c      = new City();
                City     c1     = new City("Ukraine", "Kyiv Region", "Vishgorod");
                City     c2     = new City(c1);
                CityList c_list = new CityList();
                c_list.addCity(c.name_c);
                c_list.addCity(c1.name_c);
                c_list.addCity(c2.name_c);
                c_list.destroyCity(c1.name_c);


                c_list.lookupCities();
                Console.WriteLine("");
                Console.WriteLine("LIST WITH ENUMERATE INTERFACE:");
                Console.WriteLine("==============");

                Transformer[] transArray = new Transformer[4]
                {
                    new Transformer()
                    {
                        name = "Transformer John", velocity = 165
                    },
                    new Transformer()
                    {
                        name = "Transformer  Jim", velocity = 155
                    },
                    new Transformer()
                    {
                        name = "Transformer  Sue", velocity = 145
                    },
                    new Transformer()
                    {
                        name = "Transformer  Sue", velocity = 121
                    }
                };

                TransformerList transList = new TransformerList(transArray);
                foreach (Transformer p in transList)
                {
                    Console.WriteLine(p.name + " " + p.velocity);
                }

                Console.WriteLine("LIST WITH ICOMPATIBLE INTERFACE:");

                var transf = new List <Transformer>
                {
                    new Transformer()
                    {
                        name = "Transformer John", velocity = 165
                    },
                    new Transformer()
                    {
                        name = "Transformer  Jim", velocity = 155
                    },
                    new Transformer()
                    {
                        name = "Transformer  Sue", velocity = 145
                    },
                    new Transformer()
                    {
                        name = "Transformer  Sue", velocity = 121
                    }
                };
                transf.Sort();
                foreach (Transformer p in transf)
                {
                    Console.WriteLine("name: " + p.name + ", " + "velocity: " + p.velocity);
                }
                Console.WriteLine("===================");
                Console.WriteLine("");

                Transformer        tr   = new Transformer(new City(), 0, 0, "Slide", 100, 41);
                OperateTransformer city = new OperateTransformer();
                city.killTransformer("Bee");
                city.newProtokolTransformer(tr);
                city.CompareTo(4);

                List <Transformer> copy = city.getTransformers();

                Console.WriteLine("Army of transformers just of " + copy.NumOfTrans() + " members.");
                ///////////
                Console.WriteLine("\nJSON SERIALIZE\n");
                JsonSerializerOptions op = new JsonSerializerOptions
                {
                    WriteIndented = true,
                };

                using (StreamWriter sw = new StreamWriter(WritePath, false, System.Text.Encoding.Default))
                {
                    sw.WriteLine(JsonSerializer.Serialize <List <Transformer> >(transf, op));
                }
                using (StreamReader sr = new StreamReader(WritePath, System.Text.Encoding.Default))
                {
                    string txt  = null;
                    string line = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        txt = txt + line;
                    }
                    List <Transformer> t = JsonSerializer.Deserialize <List <Transformer> >(txt, op);
                    Console.WriteLine("    NAME       " + " " + "AGE" + " " + "VELOCITY");
                    foreach (Transformer i in t)
                    {
                        Console.WriteLine(i.Name + " " + i.Age + "    " + i.Vel);
                    }
                }
                ////////////////////////
                Console.WriteLine("\nXML SERIALIZE\n");
                XmlSerializer formatter = new XmlSerializer(typeof(List <Transformer>));
                using (FileStream fs = new FileStream(WritePathXml, FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, transf);
                }

                using (FileStream fs = new FileStream(WritePathXml, FileMode.OpenOrCreate))
                {
                    List <Transformer> t = (List <Transformer>)formatter.Deserialize(fs);
                    Console.WriteLine("    NAME       " + " " + "AGE" + " " + "VELOCITY");
                    foreach (Transformer i in t)
                    {
                        Console.WriteLine(i.Name + " " + i.Age + "    " + i.Vel);
                    }
                }
                Console.Write("\n");
                /////////////////////////////////////////////////////////////////////
                Hunter <Transformer> hunt = new Hunter <Transformer> {
                    name = "Turuk", targets = transf, velocity = 1000, strength = 2
                };
                if (hunt.velocity > tr.velocity)
                {
                    Console.WriteLine(tr.name + " was killed by hunter " + hunt.name);
                }
            }
            catch (ExceptionFind ex)
            {
                Console.WriteLine($"Error occured: {ex.Message}{ex.Value}");
            }
            finally
            {
                Console.WriteLine("");
                Console.WriteLine("Fin");
            }
        }