private void VerificaCelleAdiacenti(int i, int j, Tabella grid, ref int contatore) { VerificaSingolaCella(i - 1, j - 1, grid, ref contatore); VerificaSingolaCella(i - 1, j, grid, ref contatore); VerificaSingolaCella(i - 1, j + 1, grid, ref contatore); VerificaSingolaCella(i, j + 1, grid, ref contatore); VerificaSingolaCella(i + 1, j + 1, grid, ref contatore); VerificaSingolaCella(i + 1, j, grid, ref contatore); VerificaSingolaCella(i + 1, j - 1, grid, ref contatore); VerificaSingolaCella(i, j - 1, grid, ref contatore); }
private void VerificaSingolaCella(int i, int j, Tabella grid, ref int contatore) { try { if (grid.Celle[i, j]) { contatore++; } } catch (IndexOutOfRangeException) { } }
public static void ScorriEScriviCella(Tabella grid) { char cella = ' '; for (int i = 0; i < grid.Celle.GetLength(0); i++) { for (int j = 0; j < grid.Celle.GetLength(1); j++) { VerificaEScriviCella(grid.Celle[i, j]); } Console.WriteLine(); } Console.WriteLine("----------------------------------------------------------------"); }
public Tabella VerificaCelle(Tabella grid) { int contatore = 0; Tabella gridris = new Tabella(grid.Celle.GetLength(0), grid.Celle.GetLength(1)); for (int i = 0; i < grid.Celle.GetLength(0); i++) { for (int j = 0; j < grid.Celle.GetLength(1); j++) { VerificaCelleAdiacenti(i, j, grid, ref contatore); VerificaEAggiornaStatoCella(ref gridris.Celle[i, j], grid.Celle[i, j], contatore); contatore = 0; } } return gridris; }
public void TestMethodVerificaCella() { Cellula cellula = new Cellula(); Tabella grid = new Tabella(3, 3); grid = cellula.VerificaCelle(grid); bool[,] ris = new bool[3, 3]; ris[0, 0] = true; ris[0, 1] = true; ris[0, 2] = false; ris[1, 0] = true; ris[1, 1] = true; ris[1, 2] = false; ris[2, 0] = false; ris[2, 1] = false; ris[2, 2] = false; CollectionAssert.AreEqual(ris, grid.Celle, "Metodo 'VerificaCelle' non riuscito"); }
static void Main(string[] args) { int n = 3; char[,] tabellalife = new char[n, n]; Tabella grid = new Tabella(n, n); Cellula cellula = new Cellula(); Tabella gridris = grid; for (int i = 0; i < 10; i++) { ScorriEScriviCella(gridris); grid = gridris; gridris = cellula.VerificaCelle(grid); } #region Roba Vecchia //for (int i = 0; i < tabellalife.GetLength(0); i++) //{ // for (int j = 0; j < tabellalife.GetLength(1); j++) // { // if (gridris.Celle[i, j]) // tabellalife[i, j] = 'x'; // else // tabellalife[i, j] = '.'; // Console.Write(tabellalife[i, j]); // } // Console.WriteLine(); //} //Console.WriteLine("----------------------------------------------------------------"); //grid = gridris; //gridris = cellula.VerificaCelle(grid); //for (int i = 0; i < tabellalife.GetLength(0); i++) //{ // for (int j = 0; j < tabellalife.GetLength(1); j++) // { // if (gridris.Celle[i, j]) // tabellalife[i, j] = 'x'; // else // tabellalife[i, j] = '.'; // Console.Write(tabellalife[i, j]); // } // Console.WriteLine(); //} //Console.WriteLine("----------------------------------------------------------------"); //grid = gridris; //gridris = cellula.VerificaCelle(grid); //for (int i = 0; i < tabellalife.GetLength(0); i++) //{ // for (int j = 0; j < tabellalife.GetLength(1); j++) // { // if (gridris.Celle[i, j]) // tabellalife[i, j] = 'x'; // else // tabellalife[i, j] = '.'; // Console.Write(tabellalife[i, j]); // } // Console.WriteLine(); //} //Console.WriteLine("----------------------------------------------------------------"); //grid = gridris; //gridris = cellula.VerificaCelle(grid); //for (int i = 0; i < tabellalife.GetLength(0); i++) //{ // for (int j = 0; j < tabellalife.GetLength(1); j++) // { // if (gridris.Celle[i, j]) // tabellalife[i, j] = 'x'; // else // tabellalife[i, j] = '.'; // Console.Write(tabellalife[i, j]); // } // Console.WriteLine(); //} //Console.WriteLine("----------------------------------------------------------------"); //grid = gridris; //gridris = cellula.VerificaCelle(grid); //for (int i = 0; i < tabellalife.GetLength(0); i++) //{ // for (int j = 0; j < tabellalife.GetLength(1); j++) // { // if (gridris.Celle[i, j]) // tabellalife[i, j] = 'x'; // else // tabellalife[i, j] = '.'; // Console.Write(tabellalife[i, j]); // } // Console.WriteLine(); //} //Console.WriteLine("----------------------------------------------------------------"); #endregion Console.Read(); }