/// <summary> /// The add commands should be implemented: /// add CherryTree (id) – adds a new CherryPlant to the farm /// add TobaccoPlant (id) – adds a new TobaccoPlant to the farm /// add Cow (id) – adds a new Cow to the farm /// add Swine (id) – adds a new Swine to the farm /// </summary> /// <param name="inputCommands"></param> protected override void AddObjectToFarm(string[] inputCommands) { string farmUnit = inputCommands[1]; string id = inputCommands[2]; switch (farmUnit) { case "CherryTree": var cherryTree = new CherryTree(id); this.farm.Plants.Add(cherryTree); break; case "TobaccoPlant": var tobaccoPlant = new TobaccoPlant(id); this.farm.Plants.Add(tobaccoPlant); break; case "Cow": var cow = new Cow(id); this.farm.Animals.Add(cow); break; case "Swine": var swine = new Swine(id); this.farm.Animals.Add(swine); break; default: base.AddObjectToFarm(inputCommands); break; } }
protected override void AddObjectToFarm(string[] inputCommands) { string type = inputCommands[1]; string id = inputCommands[2]; switch (type) { case "Grain": var food = new Food(id, ProductType.Grain, FoodType.Organic, 10, 2); this.farm.AddProduct(food); break; case "CherryTree": var cherryTree = new CherryTree(id); this.farm.Plants.Add(cherryTree); break; case "TobaccoPlant": var tobaccoPlant = new TobaccoPlant(id); this.farm.Plants.Add(tobaccoPlant); break; case "Cow": var cow = new Cow(id); this.farm.Animals.Add(cow); break; case "Swine": var swine = new Swine(id); this.farm.Animals.Add(swine); break; default: break; } }
protected override void AddObjectToFarm(string[] inputCommands) { string type = inputCommands[1]; string id = inputCommands[2]; switch (type) { case "CherryTree": { var plant = new CherryTree(id); this.farm.Plants.Add(plant); } break; default: base.AddObjectToFarm(inputCommands); break; } }
protected override void AddObjectToFarm(string[] inputCommands) { string type = inputCommands[1]; string id = inputCommands[2]; switch (type) { case "CherryTree": { CherryTree cheryTree = new CherryTree(id); farm.Plants.Add(cheryTree); break; } case "Cow": { var cow = new Cow(id); farm.Animals.Add(cow); break; } case "Swine": { var swine = new Swine(id); farm.Animals.Add(swine); break; } case "TobaccoPlant": { var tobacco = new TobaccoPlant(id); farm.Plants.Add(tobacco); break; } default: base.AddObjectToFarm(inputCommands); break; } }
protected override void AddObjectToFarm(string[] inputCommands) { string type = inputCommands[1]; string id = inputCommands[2]; switch (type) { case "CherryTree": { var cherryTree = new CherryTree(id); this.farm.Plants.Add(cherryTree); } break; case "Swine": { var swine = new Swine(id); this.farm.Animals.Add(swine); } break; case "Cow": { var cow = new Cow(id); this.farm.Animals.Add(cow); } break; case "TobaccoPlant": { var tobacco = new TobaccoPlant(id); this.farm.Plants.Add(tobacco); } break; default: base.AddObjectToFarm(inputCommands); break; } }
public static Plant ProducePlant(string id, string type) { switch (type) { case "CherryTree": { Plant currentPlant = new CherryTree(id); LoadCherryTreeValues(currentPlant as CherryTree); return currentPlant; } case "TobaccoPlant": { Plant currentPlant = new TobaccoPlant(id); LoadTobaccoPlantValues(currentPlant as TobaccoPlant); return currentPlant; } default: { throw new NotImplementedException("Unknown plant type " + type); } } }
private static void LoadCherryTreeValues(CherryTree currentPlant) { currentPlant.Health = FoodPlantValues.CherryTreeHealth; currentPlant.GrowTime = FoodPlantValues.CherryTreeGrowTime; }