static void Main() { Bunny vankataBunny = new Bunny("Vankata"); ulong currentVankataCarrots = vankataBunny.AddCarrots(100); Bunny peshoBunny = new Bunny("Pesho00", ColorType.Blue); ulong currentPEshoCarrots = peshoBunny.AddCarrots(2000); vankataBunny.Health -= 250; vankataBunny.Retire(); vankataBunny.Color = ColorType.Red; var baiGosho = new Bunny("Goshoo"); ChangeBunny(baiGosho); Console.WriteLine(baiGosho.Health); Random random = new Random(); var bunnies = new List<Bunny>(); for (int i = 0; i < 100; i++) { Bunny currentBunny = new Bunny(new string((char)i, 10)); currentBunny.Health = random.Next(0, 100); bunnies.Add(currentBunny); } //foreach (var bunny in bunnies) //{ // Console.WriteLine(bunny.Name + " " + bunny.Health); //} var vankataAndPesho = new List<Bunny> { vankataBunny, peshoBunny }; foreach (var bunnyes in vankataAndPesho) { Console.WriteLine(bunnyes.Name); } AirCraft firstAircraft = new AirCraft(vankataBunny, 50); AirCraft secondAircraft = new AirCraft(peshoBunny, 100); firstAircraft.Attack(secondAircraft); Console.WriteLine(secondAircraft.Pilot.Health); firstAircraft.Move(new Coordinates(15, 20)); secondAircraft.Move(new Coordinates(25, 40)); double distance = AirCraft.CalculateDistance(firstAircraft, secondAircraft); Console.WriteLine(distance); Console.WriteLine(vankataBunny.DamageTaken); }
static void Main() { //Bunnies.Bunny ivanBunny = new Bunnies.Bunny(); // constructor, if there is not namespace using Bunnies; //Bunny peshoBunny = new Bunny(); // constructor => create new object bunny //Console.WriteLine(peshoBunny); // Bunnies.Bunny Bunny blueBunny = new Bunny("Ivan", ColorType.Blue); Bunny zayoBunny = new Bunny("Zayo"); //Console.WriteLine(zayoBunny); // Bunnies.Bunny //zayoBunny.ChangeColor("Red"); // this could be made by properties also ulong currentZayoCarrots = zayoBunny.AddCarrots(100); Console.WriteLine("Zayo carrots = " + currentZayoCarrots); Bunny bugsBunny = new Bunny("Bugs", ColorType.Red); ulong currentBugsCarrots = bugsBunny.AddCarrots(2000); Console.WriteLine("Bugs carrots = " + currentBugsCarrots); string zayoName = zayoBunny.Name; // we need property for that Console.WriteLine(zayoName); //zayoBunny.Name = "Koko"; // won't work because the property is read only (only get) ColorType color = zayoBunny.Color; // get zayoBunny.Color = ColorType.Red; // set zayoBunny.Health = 150; Console.WriteLine(zayoBunny.Health); Console.WriteLine(zayoBunny.isRetired); //zayoBunny.Retire(); zayoBunny.Health -= 250; zayoBunny.Retire(); Console.WriteLine(zayoBunny.isRetired); //Animal animal = new Animal(); // won't work because the class Animal is abstract //Console.WriteLine(Bunny.NumberOfLegs); //doesn't work because it's private //works, if it's: public static int NumberOfLegs = 4; but it's not ok to be public var chipiBunny = new Bunny("Chipi"); //Bunny chipiBunny = new Bunny("Chipi"); Console.WriteLine(chipiBunny.Health); // 100 ChangeBunny(chipiBunny); Console.WriteLine(chipiBunny.Health); // 0 // create a Bunny collection List <Bunny> bunnies = new List <Bunny>(); Random random = new Random(); for (int i = 0; i < 100; i++) { Bunny currentBunny = new Bunny(new string((char)i, 10)); currentBunny.Health = random.Next(0, 100); bunnies.Add(currentBunny); } //foreach (var bunny in bunnies) //{ // Console.WriteLine(bunny.Name + " " + bunny.Health); //} // initialize a list zayoAndChipi var zayoAndChipi = new List <Bunny> { zayoBunny, chipiBunny }; foreach (var bunny in zayoAndChipi) { Console.WriteLine(bunny.Name); } AirCraft firstAirCraft = new AirCraft(chipiBunny, 60); AirCraft secondAirCraft = new AirCraft(bugsBunny, 80); Console.WriteLine(secondAirCraft.Pilot.Health); // 100 firstAirCraft.Attack(secondAirCraft); // 40 Console.WriteLine(secondAirCraft.Pilot.Health); //AirCraft.Speed(); // this method exist, but firstAirCraft.Speed() don't, because the method Speed() is static firstAirCraft.Move(new Coordinates(15, 20)); secondAirCraft.Move(new Coordinates(25, 40)); double distance = AirCraft.CalculateDistance(firstAirCraft, secondAirCraft); Console.WriteLine(distance); Console.WriteLine(bugsBunny.Damage); ColorType colorType = ColorType.Red; Console.WriteLine(colorType); // Red Console.WriteLine((int)colorType); // 1 Bunny darkoBunny = new Bunny("Darko"); //Animal darkoBunny = new Bunny("Darko"); // works too, but not the same way, because Bunny is subclass to Animal //Console.WriteLine(darkoBunny); // Bunnies.Bunny - if there is not public override string ToString() in Bunny.cs Console.WriteLine(darkoBunny); // Darko 100 object bunnyAsObject = new Bunny("Obi"); Bunny obiBunny = bunnyAsObject as Bunny; // it's safer - if cast is impossible, returns null //Bunny obiBunny = (Bunny)bunnyAsObject; // if cast is impossible => exception Console.WriteLine(obiBunny.Name); // Obi if (obiBunny is Animal) { Console.WriteLine("Is animal"); } }
static void Main() { Bunny vankataBunny = new Bunny("Vankata"); ulong currentVankataCarrots = vankataBunny.AddCarrots(100); Bunny peshoBunny = new Bunny("Peshoooo", ColorType.Blue); ulong currentPeshoCarrots = peshoBunny.AddCarrots(2000); string vankataName = vankataBunny.Name; vankataBunny.Color = ColorType.Red; ColorType color = vankataBunny.Color; vankataBunny.Retire(); vankataBunny.Health -= 250; vankataBunny.Retire(); string someString = "Somethin"; string anotherString = someString ?? "Default"; Bunny baiGosho = new Bunny("Goshooo"); // Console.WriteLine(baiGosho.Health); ChangeBunny(baiGosho); // Console.WriteLine(baiGosho.Health); var bunnies = new List <Bunny>(); Random random = new Random(); for (int i = 0; i < 100; i++) { Bunny currentBunny = new Bunny(new string((char)i, 10)); currentBunny.Health = random.Next(0, 100); bunnies.Add(currentBunny); } //foreach (var bunny in bunnies) //{ // Console.WriteLine(bunny.Name + " " + bunny.Health); //} var vankataAndPesho = new List <Bunny> { vankataBunny, peshoBunny }; //foreach (var bunny in vankataAndPesho) //{ // Console.WriteLine(bunny.Name); //} AirCraft firstAirCraft = new AirCraft(vankataBunny, 50); AirCraft secondAirCraft = new AirCraft(peshoBunny, 100); firstAirCraft.Attack(secondAirCraft); Console.WriteLine(secondAirCraft.Pilot.Health); firstAirCraft.Move(new Coordinates(15, 20)); secondAirCraft.Move(new Coordinates(25, 40)); double distance = AirCraft.CalculateDistance(firstAirCraft, secondAirCraft); Console.WriteLine(distance); Console.WriteLine(vankataBunny.Damage); ColorType colorType = ColorType.Blue; Console.WriteLine((int)colorType); Bunny bunny = new Bunny("Bunnyyy"); Console.WriteLine(bunny); object bunny2 = new Bunny("dsadsadsadas"); }
static void Main() { Bunny vankataBunny = new Bunny("Vankata"); ulong currentVankataCarrots = vankataBunny.AddCarrots(100); Console.WriteLine(currentVankataCarrots); Bunny peshoBunny = new Bunny("Pesho", "Zelen"); ulong currentPeshoCarrots = peshoBunny.AddCarrots(2000); Console.WriteLine(currentPeshoCarrots); vankataBunny.Color = "Blue"; Console.WriteLine(vankataBunny.IsRetire); vankataBunny.Retire(); vankataBunny.Health -= 250; vankataBunny.Retire(); Console.WriteLine(vankataBunny.IsRetire); string empty = null; string secoundString = empty ?? "Full"; Console.WriteLine(secoundString); Bunny baiGosho = new Bunny("Goshooooo"); ChangeBunny(baiGosho); Console.WriteLine(baiGosho.Health); //List<Bunny> bunnies = new List<Bunny>(); //for (int i = 0; i < 100; i++) //{ // Bunny currentBunny = new Bunny(new string((char)i,10)); // bunnies.Add(currentBunny); //} //foreach (var item in bunnies) //{ // Console.WriteLine(item.Name); //} var vankataAndPesho = new List <Bunny> { vankataBunny, peshoBunny }; foreach (var item in vankataAndPesho) { Console.WriteLine(item.Name); } AirCraft firstAirCraft = new AirCraft(vankataBunny, 50); AirCraft secondAirCraft = new AirCraft(peshoBunny, 100); firstAirCraft.Attack(secondAirCraft); Console.WriteLine(secondAirCraft.Pilot.Health); firstAirCraft.Move(new Map(15, 20)); secondAirCraft.Move(new Map(25, 40)); double distance = AirCraft.CalculateDistance(firstAirCraft, secondAirCraft); Console.WriteLine(distance); Console.WriteLine(vankataBunny.Damage); ColorType color = ColorType.Red; }