예제 #1
0
파일: Cellula.cs 프로젝트: DanielBurca/Life
 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);
 }
예제 #2
0
파일: Cellula.cs 프로젝트: DanielBurca/Life
 private void VerificaSingolaCella(int i, int j, Tabella grid, ref int contatore)
 {
     try
     {
         if (grid.Celle[i, j])
         {
             contatore++;
         }
     }
     catch (IndexOutOfRangeException)
     {
     }
 }
예제 #3
0
파일: Program.cs 프로젝트: DanielBurca/Life
 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("----------------------------------------------------------------");
 }
예제 #4
0
파일: Cellula.cs 프로젝트: DanielBurca/Life
 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;
 }
예제 #5
0
 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");
 }
예제 #6
0
파일: Program.cs 프로젝트: DanielBurca/Life
        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();
        }