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"); }
public static void Main(string[] args) { var jetski = new JetSki(); var waterCraft1 = new WaterCraft(jetski); waterCraft1.Move(); waterCraft1.Start(); waterCraft1.Stop(); Console.WriteLine("------------------------------------------------"); var submarine = new SubMarine(); var waterCraft2 = new WaterCraft(submarine); waterCraft2.Move(); waterCraft2.Start(); waterCraft2.Stop(); Console.WriteLine("------------------------------------------------"); var cessna = new Cessna(); var airCraft1 = new AirCraft(cessna); airCraft1.Move(); airCraft1.Start(); airCraft1.Stop(); Console.WriteLine("------------------------------------------------"); var airplane = new Airplane(); var airCraft2 = new AirCraft(airplane); airCraft2.Move(); airCraft2.Start(); airCraft2.Stop(); Console.WriteLine("------------------------------------------------"); var motorcycle = new Motorcycle(); var landCraft1 = new LandCraft(motorcycle); landCraft1.Move(); landCraft1.Start(); landCraft1.Stop(); Console.WriteLine("------------------------------------------------"); var bike = new Bike(); var landCraft2 = new LandCraft(bike); landCraft2.Move(); landCraft2.Start(); landCraft2.Stop(); Console.WriteLine("------------------------------------------------"); // Build a collection of all vehicles that fly // With a single `foreach`, have each vehicle Fly() var airCrafts = new List <AirCraft>() { airCraft1, airCraft2 }; foreach (var airCraft in airCrafts) { airCraft.Move(); } // Build a collection of all vehicles that operate on roads // With a single `foreach`, have each road vehicle Drive() var landCrafts = new List <LandCraft>() { landCraft1, landCraft2 }; foreach (var landCraft in landCrafts) { landCraft.Move(); } // Build a collection of all vehicles that operate on water // With a single `foreach`, have each water vehicle Drive() var waterCrafts = new List <WaterCraft>() { waterCraft1, waterCraft2 }; foreach (var waterCraft in waterCrafts) { waterCraft.Move(); } }
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; }