//Main factory where all the beings will be created public override IAlive CreateLive(string AliveBeing,DNA dna, Ground parent) { switch (AliveBeing) { case "plant": Plant newplant = new Plant(dna, parent); return newplant; default: throw new ApplicationException(string.Format("Being '{0}' cannot be created", AliveBeing)); } }
public static List<IPlant> load_plants(Ground parent,kindstatus status) { DPLANT dna = new DPLANT(); List<IPlant> List = new List<IPlant>(); List<DPLANT> query; if(status == kindstatus.Growup || status ==kindstatus.Reproduction){ query = Context.DPLANT.Where(S => S.PARENT_ID == parent.GroundID && !S.STATUS.Contains( kindstatus.Seed.ToString()) ).ToList(); } else{ query = Context.DPLANT.Where(S => S.PARENT_ID == parent.GroundID && S.STATUS.Contains( kindstatus.Seed.ToString()) ).ToList(); } foreach (DPLANT item in query) { Plant newplant = new Plant(parent, item.aliveID); newplant.CurrentLifeCycle = (int)item.CURRENTLIFECYCLE; newplant.Generation = (int)item.GENERATION; newplant.NextReproductionCycle = (int)item.NEXTREPRODUCTIONCYCLE; newplant.Size = (int)item.SIZE; newplant.Waterdeposit = (int)item.WATERDEPOSIT; switch (item.STATUS) { case "Seed": newplant.Status = kindstatus.Seed; break; case "Growup": newplant.Status = kindstatus.Growup; break; case "Reproduction": newplant.Status = kindstatus.Reproduction; break; } List.Add(newplant); } return List; }
public static void save_plant(Plant Plant) { DPLANT plant = new DPLANT(); plant.PARENT_ID = Plant.Parent; plant.aliveID = Plant.AliveID; plant.CURRENTLIFECYCLE = Plant.CurrentLifeCycle; plant.GENERATION = Plant.Generation; plant.SIZE = (int) Plant.Size; plant.STATUS = Plant.Status.ToString(); plant.WATERDEPOSIT = Plant.Waterdeposit; plant.NEXTREPRODUCTIONCYCLE = Plant.NextReproductionCycle; Context.AddToDPLANT(plant); Console.WriteLine(Context.SaveChanges()); }