Exemplo n.º 1
0
        public Grid(GridListener gridListener = null, Grid copy = null)
        {
            if (gridListener != null)
            {
                this.ActionOnGrid = gridListener;
            }
            else
            {
                this.ActionOnGrid = new GridListener((x, y, value) => { });
            }

            Cells = new Cell[NB_COLUMNS][];

            for (int i = 0; i < NB_COLUMNS; i++)
            {
                this.Cells[i] = new Cell[NB_ROWS];
                for (int j = 0; j < NB_ROWS; j++)
                {
                    this.Cells[i][j] = new Cell(new System.Drawing.Point(i + 1, j + 1), (copy == null ? (byte)0 : copy[i, j].Value), new CellListener(
                                                    (value) => { ActionOnGrid.ActionOnGridChange(i, j, value); },
                                                    (draft) => { }
                                                    ));
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Put a 0 value for every cell in the grid.
 /// <param name="resetDraft">Empty the draft of every cell if true. Default value is false</param>
 /// </summary>
 public void reset(bool resetDraft = false)
 {
     for (int i = 0; i < NB_ROWS; i++)
     {
         for (int j = 0; j < NB_COLUMNS; j++)
         {
             // if the cell (i, j) is null, the program creates it (regardless of the value of `resetDraft`)
             if (this.Cells[i][j] == null)
             {
                 this.Cells[i][j] = new Cell(new System.Drawing.Point(i + 1, j + 1), 0, new CellListener(
                                                 (value) => { ActionOnGrid.ActionOnGridChange(i - 1, j - 1, value); },
                                                 (draft) => { })
                                             );
             }
             // Otherwise, the programe change the value to 0 and reset the draft list if `resetDraft` is equal to 0
             else
             {
                 this.Cells[i][j].Value = 0;
                 if (resetDraft)
                 {
                     this.Cells[i][j].Draft.Clear();
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 // Indexer (see https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/index)
 public Cell this[int i, int j]
 {
     get
     {
         return(Cells[i][j]);
     }
     set
     {
         Cells[i][j] = value;
         ActionOnGrid.ActionOnGridChange(i, j, value.Value);
     }
 }