public void checkRatones() { for (int i = animales.Count - 1; i >= 0; i--) { if (animales[i] is Raton) { Raton rat1 = (Raton)animales[i]; for (int j = animales.Count - 1; j >= 0; j--) { if (animales[j] is Raton) { Raton rat2 = (Raton)animales[j]; if (rat1.posX == rat2.posX && rat1.posY == rat2.posY && i != j && rat1.genero != rat2.genero && rat1.seReprodujo == false && rat2.seReprodujo == false) { rat1.seReprodujo = true; rat2.seReprodujo = true; int ratasNuevas = r.Next(2, 7); for (int k = 0; k < ratasNuevas; k++) { animales.Add(new Raton(r.Next(W), r.Next(H))); } for (int k = 0; k < ratasNuevas / 2; k++) { Queso q = new Queso(r.Next(W), r.Next(H)); for (int h = 0; h < quesos.Count; h++) { if (q.posX == ((Queso)quesos[h]).posX && q.posY == ((Queso)quesos[h]).posY) { ((Queso)quesos[h]).AddQueso(2); } } quesos.Add(q); } Queso queso; if (ratasNuevas % 2 == 1) { queso = new Queso(r.Next(W), r.Next(H), 1); for (int h = 0; h < quesos.Count; h++) { if (queso.posX == ((Queso)quesos[h]).posX && queso.posY == ((Queso)quesos[h]).posY) { ((Queso)quesos[h]).AddQueso(1); } } quesos.Add(queso); } } //if (rat1.posX == rat2.posX && rat1.posY == rat2.posY) } //if2 } //for2 } //if raton } //for }
public void Actualizar() { grilla.Rows.Clear(); grilla.ColumnCount = mimanager.W; grilla.RowCount = mimanager.H; for (int i = 0; i < x; i++) { grilla.Columns[i].Width = width / x; } for (int i = 0; i < y; i++) { grilla.Rows[i].Height = height / y; } for (int i = 0; i < mimanager.animales.Count; i++) { Animal animal = (Animal)mimanager.animales[i]; if (animal is Raton) { grilla.Rows[animal.posY].Cells[animal.posX].Value += "R"; } else { grilla.Rows[animal.posY].Cells[animal.posX].Value += "G "; } } for (int i = 0; i < mimanager.quesos.Count; i++) { Queso queso = (Queso)mimanager.quesos[i]; grilla.Rows[queso.posY].Cells[queso.posX].Value += "Q "; } int gvivos = 0, rvivos = 0; for (int i = 0; i < mimanager.animales.Count; i++) { if (mimanager.animales[i] is Gato) { gvivos++; } else { rvivos++; } } tbgvivos.Text = Convert.ToString(gvivos); tbrvivos.Text = Convert.ToString(rvivos); lbdias.Text = Convert.ToString(pasos / 10); if (rvivos == 0) { MessageBox.Show("Ya no hay ratones en mi bota"); groupBox1.Enabled = true; btgenerar.Enabled = true; button1.Enabled = true; tbancho.Clear(); tblargo.Clear(); craton.Clear(); cgato.Text = "0"; lbdias.Text = "--"; tbgvivos.Text = "--"; tbrvivos.Text = "--"; info.Items.Clear(); grilla.Rows.Clear(); grilla.Columns.Clear(); pasos = 0; } rvivos = 0; gvivos = 0; }