/// <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; } }
private void button5_Click(object sender, EventArgs e) { SwineFabric fabric = new SwineFabric(); Swine swine = new Swine(); swine = fabric.Distribute(textBox1.Text); }
private void btnFalsaPreniez_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtAreteInseminacion.Text) || !string.IsNullOrWhiteSpace(txtAreteInseminacion.Text)) { Swine swine = new Swine(); Main main = new Main(); string arete = txtAreteInseminacion.Text; swine = main.ExisteArete(arete); if (swine.getArete() != null) { if (swine.partos.Count > 0) { DateTime now = DateTime.Now; Birth birth = swine.partos.Last(); string last = birth.getFechaInseminacion(); DateTime fechaConfirmacion = DateTime.ParseExact(birth.getFechaConfirmacion28(), "dd-MM-yyyy", null); int comparacion = now.CompareTo(fechaConfirmacion); if (comparacion > 0) { DateTime dateFalsaPreniez = fechaFalsaP.Value; int comparacion2 = dateFalsaPreniez.CompareTo(fechaConfirmacion); if (comparacion > 0) //Será necesaria? { string date = dateFalsaPreniez.Date.ToString("dd-MM-yyyy"); birth.setFechaFalsaPreniez(date); main.Update(swine); } else { MessageBox.Show("La fecha que ingresó es anterior a la fecha de confirmación"); } } else { MessageBox.Show("Aún no han pasado los 28 días de confirmación"); } } else { MessageBox.Show("La hembra nunca ha iniciado proceso de embarazo"); } } else { MessageBox.Show("El número de arete que ingresó no existe"); } } else { MessageBox.Show("Debe ingresar el arete de una hembra para continuar"); } }
private void btnGuardar_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtHembra.Text) || !string.IsNullOrWhiteSpace(txtHembra.Text)) { Swine swine = new Swine(); Main main = new Main(); string arete = txtHembra.Text; swine = main.ExisteArete(arete); if (swine.getArete() == null) { DateTime dateNacimiento = fechaNacimiento.Value; DateTime dateIngreso = fechaIngreso.Value; swine.setArete(arete); swine.setFechaIngreso(dateIngreso.Date.ToString("dd-MM-yyyy")); swine.setfechaNacimiento(dateNacimiento.Date.ToString("dd-MM-yyyy")); swine.setActiva(1); if (string.IsNullOrWhiteSpace(txtAreteMadre.Text) == true || string.IsNullOrEmpty(txtAreteMadre.Text) == true || string.IsNullOrWhiteSpace(txtAretePadre.Text) == true || string.IsNullOrEmpty(txtAretePadre.Text) == true || string.IsNullOrWhiteSpace(txtHembra.Text) == true || string.IsNullOrEmpty(txtHembra.Text) == true) { MessageBox.Show("Hay campos sin llenar en el formulario"); } else { if (txtAreteMadre.Text == txtAretePadre.Text || txtAreteMadre.Text == txtHembra.Text || txtAretePadre.Text == txtHembra.Text) { MessageBox.Show("Error en ingreso de datos, valores repetidos"); } else { swine.setAreteMadre(txtAreteMadre.Text); swine.setIdPadre(txtAretePadre.Text); main.Insert(swine.ConvertString()); MessageBox.Show("Ingreso con éxito"); fechaIngreso.ResetText(); fechaNacimiento.ResetText(); txtHembra.Clear(); txtAreteMadre.Clear(); txtAretePadre.Clear(); } } } else { MessageBox.Show("El arete que ingresó ya existe"); } } else { MessageBox.Show("Debe ingresar el arete de una hembra para continuar"); } }
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 Animal ProduceAnimal(string id, string type) { switch (type) { case "Cow": { Animal currentAnimal = new Cow(id); LoadCowValues(currentAnimal); return currentAnimal; } case "Swine": { Animal currentAnimal = new Swine(id); LoadSwineValues(currentAnimal); return currentAnimal; } default: { throw new NotImplementedException("Unknown animal type " + type); } } }
public Event(DateTime ClockStart, DateTime ClockEnd, int ClockRunTime, System.Xml.Linq.XDocument XMLEvents, ref CrashHandler Crash) { ch = Crash; events = new Dictionary<string, List<EventItem>>(); clock = new PartyClock(ClockStart, ClockEnd, ClockRunTime); Util.ShowClock = true; sound = new Sound(true); text = new Text2D(); chess = new Chess(); sf = new Starfield(150); intro = new Intro(ref sound, ref text); outro = new Outro(ref sound); advent = new Advent(ref sound); birthday = new Birthday(ref sound, ref text, ref chess); xmas = new Christmas(ref sound); smurf = new Datasmurf(ref sound, ref text); // random dif = new Dif(ref chess, ref sound); // random fbk = new Fbk(ref sound); // random hw = new Halloween(ref chess, ref sound, 25); lucia = new Lucia(ref chess, ref sound); newyear = new NewYear(); richard = new RMS(ref sound, ref text); // random scroller = new Scroller(ref chess, ref sf, ref text); // random semla = new Semla(); sune = new SuneAnimation(ref sound, ref text); tl = new TurboLogo(ref sound, ref chess, (OpenGL.Util.SpringOrFall.Equals("Spring")? true:false)/*((ClockStart.Month >= 1 && ClockStart.Month <= 8)? false:true)*/ ); // vilken termin är det? jan till början av augusti VT, resten HT... random valentine = new Valentine(ref sound); wl = new WinLinux(ref chess); //random creators = new Self(ref sound); // random bb = new BB(ref sound); // random GM = new GummiBears(ref sound); NDay = new National(ref chess, ref sound); easter = new Easter(ref sound); hajk = new Hajk(ref sound); mid = new Midsummer(ref sound); vaf = new Vaffla(); wp = new Walpurgis(); crayfish = new CrayFish(); ts = new TeknatStyle(ref chess, ref sound, ref text); m = new Matrix(ref text); q = new Quiz(ref text, false, ref sound); talepsin = new Talespin(ref sound); cd = new ChipAndDale(ref sound, ref chess); nerd = new Nerdy(ref chess, ref sound); trex = new Trex(ref sound); sailormoon = new Sailormoon(ref sound,ref chess); gb = new GhostBusters(ref sound); zelda = new Zelda(ref sound, ref chess); tardis = new Tardis(ref sound); f**k = new F**k(ref sound, ref chess); silverFang = new SilverFang(ref sound); mt = new MoraT(ref sound); swine = new Swine(ref chess, ref text); tjall = new Tjall(ref chess, ref text); ronja = new Ronja(ref sound); emil = new Emil(ref sound); djungelboken = new Djungelboken(ref sound); fabbe = new Fabbe(ref sound); drink = new Drink(ref sound); frozen = new Frozen(ref sound); eventCurrent = null; // event item for events to be triggerd in clock_NewDate //randomEvent = new List<string>(new string[] { "starfield", "SuneAnimation", "TurboLogo", "Datasmurf", "WinLinux", "Scroller", "BB", "GummiBears", "TeknatStyle", "Matrix"}); randomEvent = new List<string>(new string[] { "starfield", "Nerdy", "Talespin", "Sailormoon", "GhostBusters", "Zelda", "Tardis", "F**k", "SilverFang", "MoraT" }); //new stuff List<UtilXML.EventData> ed = UtilXML.Loadeffectdata(); // TODO: Make a clean list with all events allowed to be used implement so that it is actaully usable instead of a switch at the bottom of this file. Dictionary<string, Effect> effects = new Dictionary<string, Effect>() { {"SuneAnimation", new Effect(sune, ed.Find(e => e.Name == "SuneAnimation"))}, {"Dif",new Effect(dif, ed.Find(e => e.Name == "Dif"))}, {"Fbk",new Effect(fbk, ed.Find(e => e.Name == "Fbk"))}, {"TurboLogo",new Effect(tl, ed.Find(e => e.Name == "TurboLogo"))}, {"Datasmurf", new Effect(smurf, ed.Find(e => e.Name == "Datasmurf"))}, {"RMS",new Effect(richard, ed.Find(e => e.Name == "RMS"))}, {"WinLinux",new Effect(wl, ed.Find(e => e.Name == "WinLinux"))}, {"Scroller",new Effect(scroller, ed.Find(e => e.Name == "Scroller"))}, {"Self",new Effect(creators, ed.Find(e => e.Name == "Self"))}, {"BB",new Effect(bb, ed.Find(e => e.Name == "BB"))}, {"GummiBears",new Effect(GM, ed.Find(e => e.Name == "GummiBears"))}, {"Hajk",new Effect(hajk, ed.Find(e => e.Name == "Hajk"))}, {"TeknatStyle",new Effect(ts, ed.Find(e => e.Name == "TeknatStyle"))}, {"Matrix",new Effect(m, ed.Find(e => e.Name == "Matrix"))}, {"Quiz",new Effect(q, ed.Find(e => e.Name == "Quiz"))}, {"Talespin",new Effect(talepsin, ed.Find(e => e.Name == "Talespin"))}, {"ChipDale",new Effect(cd, ed.Find(e => e.Name == "ChipDale"))}, {"Nerdy",new Effect(nerd, ed.Find(e => e.Name == "Nerdy"))}, /* {"Trex",new Effect(trex, ed.Find(e => e.Name == "Trex"))},*/ {"Sailormoon",new Effect(sailormoon, ed.Find(e => e.Name == "Sailormoon"))}, {"GhostBusters",new Effect(gb, ed.Find(e => e.Name == "GhostBusters"))}, {"Zelda",new Effect(zelda, ed.Find(e => e.Name == "Zelda"))}, {"Tardis",new Effect(tardis, ed.Find(e => e.Name == "Tardis"))}, {"F**k",new Effect(f**k, ed.Find(e => e.Name == "F**k"))}, {"SilverFang",new Effect(silverFang, ed.Find(e => e.Name == "SilverFang"))}, {"MoraT",new Effect(mt, ed.Find(e => e.Name == "MoraT"))}, {"Ronja",new Effect(ronja, ed.Find(e => e.Name == "Ronja"))}, {"Emil",new Effect(emil, ed.Find(e => e.Name == "Emil"))}, {"Djungelboken",new Effect(djungelboken, ed.Find(e => e.Name == "Djungelboken"))}, {"Fabbe",new Effect(fabbe, ed.Find(e => e.Name == "Fabbe"))}, {"Drink",new Effect(drink, ed.Find(e => e.Name == "Drink"))}, {"Frozen",new Effect(drink, ed.Find(e => e.Name == "Frozen"))} }; runEffectInMonth = new Dictionary<string, List<objdata>>(); string[] months = Util.monthlist(); int counter; foreach (KeyValuePair<string, Effect> pair in effects) { counter = 0; foreach (bool b in pair.Value.RunAllowedlist) { if (b == true) { if (!runEffectInMonth.ContainsKey(months[counter])) { runEffectInMonth.Add(months[counter], new List<objdata>()); } runEffectInMonth[months[counter]].Add(new objdata(pair.Key, pair.Value.Vetolist[counter], pair.Value.Priolist[counter], pair.Value.Runslist[counter])); } counter++; } } clock.NewDate += clock_NewDate; // Event listener if (ch.CrashDialogResult == System.Windows.Forms.DialogResult.Yes) { clock.clock = ch.CrashClock; } string name, date, type; // Event dates setup foreach (var item in XMLEvents.Descendants("event")) { name = item.Element("name").Value; date = item.Element("date").Value; type = item.Element("type").Value.ToLower(); EventItem ei = new EventItem(name, type, date); if (!events.ContainsKey(date)) { List<EventItem> list = new List<EventItem>(); // seems most bad in my eyes... events.Add(date, list); } for (int i = 0; i < events[date].Count; i++) { EventItem e = events[date][i]; if ("birthday".Equals(e.Type) && "birthday".Equals(ei.Type)) { e.Name += "\n\n" + ei.Name; events[date][i] = e; } } events[date].Add(ei); name = date = type = string.Empty; } // this needs to be fixed nicer... if (events.ContainsKey(ClockEnd.ToShortDateString())) { events[ClockEnd.ToShortDateString()].Clear(); // force this to be top.. events[ClockEnd.ToShortDateString()].Add( new EventItem("outro", "outro", ClockEnd.ToShortDateString()) ); } else { events.Add(ClockEnd.ToShortDateString(), new List<EventItem>() { new EventItem("outro", "outro", ClockEnd.ToShortDateString()) }); } // Random effects on dates with no effects and check against new list of allowed things for them... DateTime dt = ClockStart; bool star = (Util.Rnd.Next(0, 1000) < 500 ? true:false); // make this random at the start too? int num = 0; while (dt <= ClockEnd) { date = dt.ToShortDateString(); if (!events.ContainsKey(date)) { EventItem ei; if (num == 0 || num == 1) { ei = new EventItem("starfield", "random", date); } else { //ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date); string month = ""; if (dt != null) month = dt.Month.ToString(); switch (month) { case "1": month = "jan"; break; case "2": month = "feb"; break; case "3": month = "mar"; break; case "4": month = "apr"; break; case "5": month = "maj"; break; case "6": month = "jun"; break; case "7": month = "jul"; break; case "8": month = "aug"; break; case "9": month = "sep"; break; case "10": month = "okt"; break; case "11": month = "nov"; break; case "12": month = "dec"; break; }//switch if (runEffectInMonth.ContainsKey(month)) { List<objdata> mobj = runEffectInMonth[month]; List<objdata> vetolist = new List<objdata>(); List<objdata> novetolist = new List<objdata>(); foreach (objdata n in mobj) { if ("Quiz".Equals(n.Name) && eventnum == 4) { n.vetoAgain(); eventnum = 0; } if (n.Veto == true) { if (n.Runs > 0) vetolist.Add(n); } else { if (n.Runs > 0) novetolist.Add(n); } } vetolist.Sort(); novetolist.Sort(); if (vetolist.Count > 0) { ei = new EventItem(vetolist[0].Name, "random", date); vetolist[0].noMoreVeto(); } else if (novetolist.Count > 0) { ei = new EventItem(novetolist[0].Name, "random", date); novetolist[0].decRuns(); if (eventnum < 4) eventnum++; } else { ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date); } } else { ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date); } } num++; if (num == 3) { num = 0; } ei = new EventItem("Self", "random", date); // this is for debuging new events events.Add(date, new List<EventItem>()); events[date].Add(ei); } dt = dt.AddDays(1); date = string.Empty; } }
private void btnParto_Click(object sender, EventArgs e) { if ((!string.IsNullOrEmpty(txtParto.Text) || !string.IsNullOrWhiteSpace(txtParto.Text))) { Swine swine = new Swine(); Main main = new Main(); string arete = txtParto.Text; swine = main.ExisteArete(arete); if (swine != null) { Birth newBirth = new Birth(); DateTime dateParto = fechaParto.Value; int lechonesTotales = Convert.ToInt32(txtLechonesTotales.Text); int lechonesVivos = Convert.ToInt32(txtLechonesVivos.Text); int hembras = Convert.ToInt32(txtHembras.Text); int machos = Convert.ToInt32(txtMachos.Text); int lechonesMuertos = Convert.ToInt32(txtMuertos.Text); int lechonesMomias = Convert.ToInt32(txtMomias.Text); string pesos = txtPesos.Text; int totaGenero = hembras + machos; int totalDistribuido = lechonesVivos + lechonesMuertos + lechonesMomias; if (swine.partos.Count > 0) { newBirth = swine.partos.Last(); if (newBirth.getFechaFalsaPreniez().Equals("-")) { if (lechonesTotales == totaGenero && lechonesTotales == totalDistribuido) { newBirth.setFechaParto(dateParto.Date.ToString("dd-MM-yyyy")); newBirth.setTotalNacidos(lechonesTotales); newBirth.setNacidosVivos(lechonesVivos); newBirth.setNacidosMuertos(lechonesMuertos); newBirth.setNacidosMomias(lechonesMomias); newBirth.setTotalHembras(hembras); newBirth.setTotalMachos(machos); newBirth.setMovimientoLechones(Convert.ToInt32(txtMovLechones.Text)); //newBirth.setPorcentajeMortalidad(); newBirth.setGrasaDorsal(Convert.ToDouble(txtGrasaDorsal.Text)); newBirth.setCantidadTetas(Convert.ToInt32(txtCantTetas.Text)); newBirth.setTipoBaja(txtTipoBaja.Text); var items = pesos.Split(','); newBirth.pesos.Clear(); if (items.Count() == lechonesVivos) { for (int i = 0; i < items.Count(); i++) { newBirth.pesos.Add(Convert.ToInt32(items.ElementAt(i))); } swine.setTotalPartos(swine.getTotalPartos() + 1); int actualVivos = swine.getTotalLechonesVivos(); int actualMuertos = swine.getTotalLechonesMuertos(); int actualMomias = swine.getTotalLechonesMomia(); swine.setTotalLechonesVivos(actualVivos + lechonesVivos); swine.setTotalLechonesMuertos(actualMuertos + lechonesMuertos); swine.setTotalLechonesMomia(actualMomias + lechonesMomias); main.Update(swine); MessageBox.Show("El parto fue ingresado con éxito"); } else { MessageBox.Show("La cantidad de pesos ingresados no coinciden con el total de lechones"); } } else { MessageBox.Show("Los datos de hembras/machos o vivos/muertos/momias no coinciden"); } } else { MessageBox.Show("La hembra " + swine.getArete() + " no está preñada"); } } else if (swine.partos == null || swine.partos.Count == 0 || newBirth.getFechaInseminacion().Equals("-")) { MessageBox.Show("Verifique que la hembra seleccionada haya sido inseminada"); } } else { MessageBox.Show("El número de arete que ingresó no existe"); } } else { MessageBox.Show("Debe ingresar el arete de una hembra para continuar"); } }
private void btnInseminacion_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtAreteInseminacion.Text) || !string.IsNullOrWhiteSpace(txtAreteInseminacion.Text)) { Swine swine = new Swine(); Main main = new Main(); string arete = txtAreteInseminacion.Text; swine = main.ExisteArete(arete); //Validar fechas anteriores /* * * DateTime fechaFalsaPreniez = dateTimePicker2.Value; * Birth newBirth = new Birth(); * newBirth = swine.partos.Last(); * if (!newBirth.getFechaFalsaPreniez().Equals("") && !newBirth.getFechaParto().Equals("")) * { * newBirth.setFechaFalsaPreniez(fechaFalsaPreniez.Date.ToString("dd-MM-yyyy")); * } */ if (swine.getArete() != null) { if (swine.partos.Count > 0) { DateTime now = DateTime.Now; Birth birth = swine.partos.Last(); string last = birth.getFechaInseminacion(); if (last.Equals("-")) { DateTime dateInseminacion = fechaInseminacion.Value; DateTime fechaConfirmacion21 = dateInseminacion.AddDays(21); DateTime fechaConfirmacion28 = dateInseminacion.AddDays(28); //DateTime fechaPosibleParto = dateInseminacion.AddDays(114); Birth newBirth = new Birth(); txtConfirmacion21.Text = fechaConfirmacion21.Date.ToString("dd-MM-yyyy"); txtConfirmacion28.Text = fechaConfirmacion28.Date.ToString("dd-MM-yyyy"); //txtPosibleParto.Text = fechaPosibleParto.Date.ToString("dd-MM-yyyy"); string lote = txtLote.Text; if (!string.IsNullOrEmpty(txtLote.Text) || !string.IsNullOrWhiteSpace(txtLote.Text)) { newBirth.setFechaInseminacion(dateInseminacion.Date.ToString("dd-MM-yyyy")); newBirth.setLote(lote); newBirth.setFechaConfirmacion21(fechaConfirmacion21.Date.ToString("dd-MM-yyyy")); newBirth.setFechaConfirmacion28(fechaConfirmacion28.Date.ToString("dd-MM-yyyy")); //newBirth.setFechaPosibleParto(fechaPosibleParto.Date.ToString("dd-MM-yyyy")); swine.partos.Add(newBirth); main.Update(swine); MessageBox.Show("Fecha de inseminación ingresada"); } else { MessageBox.Show("Debe ingresar el lote de la hembra"); } } else { MessageBox.Show("La hembra ya está inseminada, verifique fecha de confirmación"); } } else { DateTime dateInseminacion = fechaInseminacion.Value; DateTime fechaConfirmacion21 = dateInseminacion.AddDays(21); DateTime fechaConfirmacion28 = dateInseminacion.AddDays(28); Birth newBirth = new Birth(); txtConfirmacion21.Text = fechaConfirmacion21.Date.ToString("dd-MM-yyyy"); txtConfirmacion28.Text = fechaConfirmacion28.Date.ToString("dd-MM-yyyy"); string lote = txtLote.Text; if (!string.IsNullOrEmpty(txtLote.Text) || !string.IsNullOrWhiteSpace(txtLote.Text)) { newBirth.setFechaInseminacion(dateInseminacion.Date.ToString("dd-MM-yyyy")); newBirth.setLote(lote); newBirth.setFechaConfirmacion21(fechaConfirmacion21.Date.ToString("dd-MM-yyyy")); newBirth.setFechaConfirmacion28(fechaConfirmacion28.Date.ToString("dd-MM-yyyy")); swine.partos.Add(newBirth); main.Update(swine); MessageBox.Show("Fecha de inseminación ingresada"); } else { MessageBox.Show("Debe ingresar el lote de la hembra"); } } } else { MessageBox.Show("El número de arete que ingresó no existe"); } } else { MessageBox.Show("Debe ingresar el arete de una hembra para continuar"); } }