public static List <AppleTree> InitialiseTrees() { //Initalise return value List <AppleTree> result = new List <AppleTree>(); //Random number generator Random random = new Random(); //Loop to create 10 trees for (int i = 1; i <= 10; i++) { //Add tree with random properties AppleTree tree = new AppleTree() { AppleYield = random.Next(50, 150), WaterConsumption = random.Next(800, 1200), FertilizingAgent = (Fertilizer)random.Next(Enum.GetNames(typeof(Fertilizer)).Length) }; result.Add(tree); } //return the List return(result); }
public void CreateAppleTreeTestsWithObjectAsParameter() { //Instantiate a new DbContext with the in memory database var InMemoryContext = new AppleTreeDbContext(options); //Create an instance of AppleTreeHelper and pass the in memory context as a parameter AppleTreeHelper appleTreeHelper = new AppleTreeHelper(InMemoryContext); appleTreeHelper.DeleteAppleTreeAll(); //Check if the database is empty Assert.AreEqual(InMemoryContext.AppleTrees.Count(), 0); //Create an in memory tree var tree = new AppleTree { AppleYield = 200, WaterConsumption = 220, FertilizingAgent = Fertilizer.Strong }; appleTreeHelper.CreateAppleTree(tree); //Check if tree was inserted Assert.AreEqual(InMemoryContext.AppleTrees.Count(), 1); //Check the inserted tree's properties Assert.AreEqual(200, InMemoryContext.AppleTrees.FirstOrDefault().AppleYield); Assert.AreEqual(220, InMemoryContext.AppleTrees.FirstOrDefault().WaterConsumption); Assert.AreEqual(Fertilizer.Strong, InMemoryContext.AppleTrees.FirstOrDefault().FertilizingAgent); }
public AppleTree CreateAppleTree(AppleTree f) { //Save db.AppleTrees.Add(f); db.SaveChanges(); return(f); }
public static void Main() { System.Console.WriteLine("assignment 5 has started"); AppleTree at = new AppleTree(); Application.Run(at); System.Console.WriteLine("end of assignment 5"); }
public void UpdateTree(AppleTree appletree) { var tree = db.AppleTrees.FirstOrDefault(c => c.Id == appletree.Id); tree.AppleYield = appletree.AppleYield; tree.FertilizingAgent = appletree.FertilizingAgent; tree.WaterConsumption = appletree.WaterConsumption; db.SaveChanges(); }
// Use this for initialization void Start() { // Находим ссылку на счётчик GameObject scoreGO = GameObject.Find("ScoreCounter"); // Извлекаем GUI компонет scoreGT = scoreGO.GetComponent <Text>(); // Задаём стартовый счёт от 0 scoreGT.text = "0"; // Находим скрипт дерева appleTree = GameObject.Find("AppleTree").GetComponent <AppleTree>(); }
static void Main(string[] args) { var weko = new Person { FirstName = "Wekoslav", LastName = "Stefanovski" }; Console.WriteLine(weko.GetType().FullName); Console.WriteLine(weko); Console.WriteLine("------------"); Tree myTree = new AppleTree(); var result = myTree.GetSeedsMultiple(3); Console.WriteLine(string.Join("\n", result)); Console.WriteLine("------------"); var trees = new List <Tree> { new AppleTree(), new PearTree(), new BananaTree(), new WalnutTree(), new EvergreenTree(EvergreenType.Pine) }; var fruits = trees.Select(tree => tree.GetSeeds()); Console.WriteLine(string.Join("\n", fruits)); Console.WriteLine("------------"); var climbables = new List <IClaimable>(); climbables.Add(new AppleTree()); climbables.Add(new WoodyHill("Ljubash")); climbables.Add(new WoodyMountain("Baba")); foreach (var item in climbables) { //Console.WriteLine(item is Tree); //Console.WriteLine(item is Mountain); //Console.WriteLine(item is WoodyMountain); if (item is Mountain mountain) { Console.WriteLine("Is item mountain?"); Console.WriteLine(item == mountain); // Console.WriteLine(item.Name); Console.WriteLine(mountain.Name); } item.Climb(); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } AppleTree g = obj as AppleTree; if (g as AppleTree == null) { return(false); } return(g.m_color == this.m_color && g.m_yield == this.m_yield && g.m_ripeningTime == this.m_ripeningTime && g.m_plantVariety == this.m_plantVariety); }
public AppleTree CreateAppleTree(double appleYield, double waterConsumption, Fertilizer fertilizingAgent) { var f = new AppleTree(); f.AppleYield = appleYield; f.WaterConsumption = waterConsumption; f.FertilizingAgent = fertilizingAgent; //Add to Database db.AppleTrees.Add(f); //Save db.SaveChanges(); return(f); }
public void TestMethod1() { using (ShimsContext.Create()) { MyLib.Fakes.ShimFruit.ConstructorString = delegate(Fruit f, string s) { var shimFruit = new MyLib.Fakes.ShimFruit(f); shimFruit.ToString = () => { return("Orange"); }; }; AppleTree tree = new AppleTree(); string expected = "Orange"; Assert.AreEqual(expected, tree.GetApple()); } }
static void Main(string[] args) { Parent man = new Parent("Мужик", "Мужской", 52); Parent woman = new Parent("Баба", "Женский", 44); Child daughter = new Child("Доченька", "Женский", 12); Child son = new Child("Сынок", "Мужской", 8); Goose goose = new Goose("Гуси-лебеди", "Птица", "Коричневые", 1, 1, 2); Oven oven = new Oven("Печка", "Еда"); AppleTree apple_tree = new AppleTree("Яблоня", "Фрукты", 21); MilkRiver milk_river = new MilkRiver("Молочная река", 100, 21); GrandParent granny_yaga = new GrandParent("Баба-Яга", "Женский", 119); Mouse mouse = new Mouse("Мышка", "Грызун", "Серый", 1, 1, 4); Swan_geese_story(man, woman, daughter, son, goose, oven, apple_tree, milk_river, granny_yaga, mouse); //правильная концвока при 2, 2, 2, 2, 1, 1, 1, 1 включая рандомы Console.ReadKey(); }
static void Main(string[] args) { Rectangle rectangle = new Rectangle(); int area; rectangle.SetHeight(6); rectangle.SetWidth(7); area = rectangle.getArea(); Console.WriteLine("总面积:" + area); Console.WriteLine("油漆总价:" + rectangle.getCost(area)); //调用子类 AppleTree appleTree = new AppleTree("苹果树"); string amyName = appleTree.MyFruitName(); //调用子类 OrangeTree orangeTree = new OrangeTree("桔子树"); string omyName = orangeTree.MyFruitName(); Console.ReadKey(); }
void Start() { audioSource = GetComponent <AudioSource> (); menuM = eventS.GetComponent <MenuManager>(); //*defining script for menu manager //*added stuff - locating the scipt reference tree = GameObject.Find("AppleTree"); //*added stuff - difficulty treeScript = tree.GetComponent <AppleTree> (); //*added stuff - difficulty //*added stuff - locating the scipt reference appleScript = sceneApples.GetComponent <Apple> (); //*added stuff - difficulty //score obj reference GameObject scoreGO = GameObject.Find("ScoreCounter"); //get the GUIText component of found obj scoreGT = scoreGO.GetComponent <GUIText>(); //set start points to 0 scoreGT.text = "0"; }
static void Main(string[] args) { Parent man = new Parent("Мужик", "Мужской", 52); Parent woman = new Parent("Баба", "Женский", 44); Child daughter = new Child("Доченька", "Женский", 12, 4); Child son = new Child("Сынок", "Мужской", 8, 1); Goose goose = new Goose("Гуси-лебеди", "Птица", "Коричневые", 1, 1, 2); Oven oven = new Oven("Печка", "Еда"); AppleTree apple_tree = new AppleTree("Яблоня", "Фрукты", 21); MilkRiver milk_river = new MilkRiver("Молочная река", 100, 21); GrandParent <Human> granny_yaga = new GrandParent <Human>("Баба-Яга", "Женский", 119); Mouse mouse = new Mouse("Мышка", "Грызун", "Серый", 1, 1, 4); //правильная концвока при 2, 2, 2, 2, 1, 1, 1, 1 включая рандомы //Класс Zmey(в нем находится так же dictionary) и GrandParent обобщенные StoryTeller storyTeller = new StoryTeller(); storyTeller.TellStrory(man, woman, daughter, son, goose, oven, apple_tree, milk_river, granny_yaga, mouse); Console.ReadKey(); }
static public void ChangeProperty() { GameObject appleTreeGO = GameObject.Find("AppleTree"); AppleTree apScript = appleTreeGO.GetComponent <AppleTree>(); int levelIndex = (int)level; apScript.speed *= speedParam[levelIndex]; //switch (level) //{ // case DifficultyLevel.Easy: // default: // break; // case DifficultyLevel.Normal: // apScript.speed *= speedParam[levelIndex]; // break; // case DifficultyLevel.Nightmare: // apScript.speed *= 2; // break; // case DifficultyLevel.Hell: // apScript.speed *= 2; // break; //} }
public void Awake() { appleTree = GameObject.Find("Tree").GetComponent <AppleTree>(); }
void Start() { rb = GetComponent <Rigidbody>(); AT = GetComponentInParent <AppleTree>(); rb.constraints = RigidbodyConstraints.FreezeAll; }
static void Main(string[] args) { Fruit fruit = new Fruit("Tomato", 10, KnownColor.Red, true); // Uncomment this line and see that C# doesn't allow the default construct as we already have definited at least one constructor. //fruit = new Fruit(); Pear pear1 = new Pear(); // This is the oposite of the first example. You cannot call a constructor this undefinited or definited only on the parent. //pear1 = new Pear("Pear", 10, KnownColor.Green, true); AsianPear asianPear = new AsianPear(); Console.WriteLine(asianPear.ToString()); Console.WriteLine(asianPear.Origin); Console.WriteLine(); // Here I am convecting back the asianPear into it parent class Pear pear2 = (Pear)asianPear; // See here that the method toString still keep the new implementation specific to AsianPear Console.WriteLine(pear2.ToString()); //Now the following line is now throwing an error as the property hasn't been defined either on Fruit Class or the Pear Class //Console.WriteLine(pear2.Origin); //Here the normal Pear object is using the behavior defined in the Fruit object instead. Console.WriteLine(pear1.ToString()); Console.WriteLine(); //This is an example of using interface. IPlant plant = new Pyrus(); plant.Harvest(); plant.Harvest(DateTime.Today); plant.Harvest(DateTime.Today.AddDays(10)); plant.Harvest(DateTime.Today.AddDays(-10)); // Here I am trying to access a function undefined by the Interface. Visual studio won't let me compile this line. //Console.WriteLine(plant.GetLocation()); // But this line does work as we are casting first into the proper object. Console.WriteLine(((Pyrus)plant).GetLocation()); Console.WriteLine(); // Now see the difference with the appletree interface. var appleTree = new AppleTree(); // Here is checkin if the appletree does implement the interface IPlant if (appleTree is IPlant) { // This casting into IPlant. plant = (IPlant)appleTree; plant.Harvest(); plant.Harvest(DateTime.Today); plant.Harvest(DateTime.Today.AddDays(10)); plant.Harvest(DateTime.Today.AddDays(-10)); Console.WriteLine(); } //Here plant should be an appleTree. But we don't know the base type. //So we are trying to cast it into a Pyrus Pyrus applePear = plant as Pyrus; // If the conversion failed, there won't be an error but the value will be null if (applePear != null) { // See are it isn't been run. applePear.Harvest(); applePear.Harvest(DateTime.Today); applePear.Harvest(DateTime.Today.AddDays(10)); applePear.Harvest(DateTime.Today.AddDays(-10)); } //But this casting will fail at runtime applePear = (Pyrus)plant; }
public void TellStrory(Parent parent1, Parent parent2, Child child1, Child brother, Goose goose, Oven oven, AppleTree appleTree, MilkRiver milkRiver, GrandParent <Human> grandParent, Mouse mouse) { Order order = Answers; order.Invoke(); Random rnd = new Random(); Zmey <Goose, Human> zmey_gorinich = new Zmey <Goose, Human>(3, 213321); parent1.Keep_live(); parent2.Ask(child1); parent1.Go_out_from_home(); Console.WriteLine(" Остаться и поиграть с братиком/Пойти гулять? Введите 1 или 2..."); string number1 = Console.ReadLine(); if (number1 == "1") { Order order1 = child1.Stay_at_home; order1(); } else { Order order2 = child1.Forget; order2 += child1.Go_out_from_home; order2 += goose.Steal_child; order2 += child1.Cry; order2 += child1.Search; order2 += child1.Run; order2 += oven.Keep_staying; order2 += child1.Where_brother; order2 += oven.Eat_my_cake; order2(); Console.WriteLine(" Скушать пирожок/Пойти дальше? Введите 1 или 2..."); string number2 = Console.ReadLine(); if (number2 == "1") { try { oven.Drop_cake(5, 20); Display_delegate("Печь дала 5 пирожков."); order2 -= child1.Forget; order2 -= child1.Go_out_from_home; order2 -= goose.Steal_child; order2 -= child1.Cry; order2 -= child1.Search; order2 -= child1.Run; order2 -= oven.Keep_staying; order2 -= child1.Where_brother; order2 -= oven.Eat_my_cake; order2 += child1.Eat_cake; order2(); } catch (NullReferenceException ex) { Console.WriteLine(ex.Message + "Девочка заблудилась в лесу..."); } finally { child1.Come_to_hut(); } Order orderfact = delegate { Console.WriteLine("Interested fact: granny Yaga is not just granny =)"); }; orderfact(); // анонимный метод child1.Do("-Девочка зашла в дом, говорит"); child1.Say("-Здравствуй бабушка!"); grandParent.Say("-Здравствуй, девица! Зачем на глаза явилась?"); child1.Say("-Я по мхам, по болотам ходила, платье измочила, пришла погреться."); grandParent.Say("Садись покуда кудель прясть."); grandParent.Give_spin(grandParent); child1.Spin(); mouse.Run(); mouse.Ask_to_eat(); child1.Give_to_eat(); mouse.Ask_to_run(); //лямбда Order order3 = () => Console.WriteLine(" Забрать братика и сбежать/Не поверить мышке и ждать бабулю? Введите 1 или 2..."); order3(); int c = rnd.Next(1, 2); if (c == 1) { child1.Say("-Спасибо тебе большое, мышка!"); child1.Go_out_from_hut(); grandParent.Ask_girl(grandParent); mouse.Lie(); grandParent.Come_to_hut(grandParent); child1.Ask_oven(oven); oven.Save_children(); goose.Not_see(); child1.Come_to_home(); parent1.Come_to_home(); } else { child1.Stay_at_hut(); } } else { child1.Not_eat_cake(); oven.Go_out_child(); appleTree.Keep_staying(); child1.Where_brother(); appleTree.Eat_my_apple(); Console.WriteLine(" Не хочу/С радостью! Введите 1 или 2..."); int h = rnd.Next(1, 2); if (h == 2) { child1.Eat_apple(); child1.Come_to_hut(); child1.Do("-Девочка зашла в дом, говорит"); child1.Say("-Здравствуй бабушка!"); grandParent.Say("-Здравствуй, девица! Зачем на глаза явилась?"); child1.Say("-Я по мхам, по болотам ходила, платье измочила, пришла погреться."); grandParent.Say("Садись покуда кудель прясть."); grandParent.Give_spin(grandParent); child1.Spin(); mouse.Run(); mouse.Ask_to_eat(); child1.Give_to_eat(); mouse.Ask_to_run(); Console.WriteLine(" Забрать братика и сбежать/Не поверить мышке и ждать бабулю? Введите 1 или 2..."); string c = Console.ReadLine(); if (c == "1") { child1.Say("-Спасибо тебе большое, мышка!"); child1.Go_out_from_hut(); grandParent.Ask_girl(grandParent); mouse.Lie(); grandParent.Come_to_hut(grandParent); child1.Ask_apple_tree(appleTree); appleTree.Save_children(); goose.Not_see(); goose.Fly(); oven.Keep_staying(); child1.Ask_oven(oven); oven.Eat_my_cake(); Console.WriteLine(" Скушать пирожок/Пойти дальше? Введите 1 или 2..."); string number3 = Console.ReadLine(); if (number3 == "1") { child1.Eat_cake(); oven.Save_children(); goose.Not_see(); appleTree.Keep_staying(); child1.Ask_apple_tree(appleTree); appleTree.Save_children(); goose.Not_see(); child1.Come_to_home(); parent1.Come_to_home(); } else { child1.Not_eat(); } } else { child1.Stay_at_hut(); } } else { child1.Not_eat_apple(); appleTree.Go_out_child(); milkRiver.Keep_staying(); child1.Where_brother(); milkRiver.Drink_my_kissel(); Console.WriteLine(" Попить киселя/Пойти дальше? Введите 1 или 2..."); string number4 = Console.ReadLine(); if (number4 == "1") { child1.Drink_kissel(); child1.Come_to_hut(); child1.Do("-Девочка зашла в дом, говорит"); child1.Say("-Здравствуй бабушка!"); grandParent.Say("-Здравствуй, девица! Зачем на глаза явилась?"); child1.Say("-Я по мхам, по болотам ходила, платье измочила, пришла погреться."); grandParent.Say("Садись покуда кудель прясть."); grandParent.Give_spin(grandParent); child1.Spin(); mouse.Run(); mouse.Ask_to_eat(); child1.Give_to_eat(); mouse.Ask_to_run(); Console.WriteLine(" Забрать братика и сбежать/Не поверить мышке и ждать бабулю? Введите 1 или 2..."); int c = rnd.Next(1, 2); if (c == 1) { child1.Say("-Спасибо тебе большое, мышка!"); child1.Go_out_from_hut(); grandParent.Ask_girl(grandParent); mouse.Lie(); grandParent.Come_to_hut(grandParent); child1.Ask_oven(oven); oven.Eat_my_cake(); Console.WriteLine(" Скушать пирожок/Пойти дальше? Введите 1 или 2..."); string number5 = Console.ReadLine(); if (number5 == "1") { try { child1.Eat_cake();; } catch (NullReferenceException ex) { Console.WriteLine(ex.Message + "Налетели гуси-лебеди..."); child1.Not_eat(); } finally { oven.Save_children(); } goose.Not_see(); appleTree.Keep_staying(); child1.Ask_apple_tree(appleTree); appleTree.Eat_my_apple(); Console.WriteLine(" Скушать яблочко/Пойти дальше? Введите 1 или 2..."); string number6 = Console.ReadLine(); if (number6 == "1") { appleTree.Drop_apple(3, 32); child1.Eat_apple(); appleTree.Save_children(); goose.Not_see(); milkRiver.Keep_staying(); child1.Ask_river(milkRiver); milkRiver.Save_children(); goose.Not_see(); child1.Come_to_home(); parent1.Come_to_home(); } else { zmey_gorinich.Fire(goose); zmey_gorinich.Description("Была умной", "Была глупой", "Самой младшей"); zmey_gorinich.Speak_to_human(child1); child1.Come_to_home(); parent1.Come_to_home(); } } else { zmey_gorinich.Fire(goose); zmey_gorinich.Description("Была умной", "Была глупой", "Самой младшей"); zmey_gorinich.Speak_to_human(child1); child1.Come_to_home(); parent1.Come_to_home(); } } else { child1.Stay_at_hut(); } } else { child1.Not_drink_kissel(); milkRiver.Go_out_child(); child1.Search_in_fields(); child1.Come_to_hut(); child1.Do("-Девочка зашла в дом, говорит"); child1.Say("-Здравствуй бабушка!"); grandParent.Say("-Здравствуй, девица! Зачем на глаза явилась?"); child1.Say("-Я по мхам, по болотам ходила, платье измочила, пришла погреться."); grandParent.Say("Садись покуда кудель прясть."); grandParent.Give_spin(grandParent); child1.Spin(); mouse.Run(); mouse.Ask_to_eat(); child1.Give_to_eat(); mouse.Ask_to_run(); Console.WriteLine(" Забрать братика и сбежать/Не поверить мышке и ждать бабулю? Введите 1 или 2..."); string c = Console.ReadLine(); if (c == "1") { try { child1.Say("-Спасибо тебе большое, мышка!"); } catch when(c == "2") { child1.Stay_at_hut(); } finally { child1.Go_out_from_hut(); } grandParent.Ask_girl(grandParent); mouse.Lie(); grandParent.Come_to_hut(grandParent); oven.Keep_staying(); child1.Ask_oven(oven); oven.Eat_my_cake(); Console.WriteLine(" Скушать пирожок/Пойти дальше?? Введите 1 или 2..."); int number5 = rnd.Next(1, 2); if (number5 == 1) { child1.Eat_cake(); oven.Save_children(); goose.Not_see(); appleTree.Keep_staying(); child1.Ask_apple_tree(appleTree); appleTree.Eat_my_apple(); Console.WriteLine(" Скушать яблочко/Пойти дальше? Введите 1 или 2..."); string number6 = Console.ReadLine(); if (number6 == "1") { try { child1.Eat_apple(); } catch when(number6 == "2") { child1.Not_eat(); } finally { appleTree.Save_children(); } goose.Not_see(); milkRiver.Keep_staying(); child1.Ask_river(milkRiver); milkRiver.Flowing("речечка"); milkRiver.Drink_my_kissel(); Console.WriteLine(" Попить киселю/Пойти дальше? Введите 1 или 2..."); string number7 = Console.ReadLine(); if (number7 == "1") { child1.Drink_kissel(); milkRiver.Save_children(); goose.Not_see(); child1.Come_to_home(); parent1.Come_to_home(); } else { child1.Not_eat(); } } } else { child1.Not_eat(); } } else { child1.Stay_at_hut(); } } } } } }