Esempio n. 1
0
        private void InitializeCells(IFieldCellFactory cellCreator)
        {
            if (cellCreator == null)
            {
                throw new ArgumentNullException("Class table cant correctly initialize with a null reference for a cellCreator");
            }

            FieldCell[,] cells = new FieldCell[cellCreator.RowCount, cellCreator.ColCount];

            for (int i = 0; i < cellCreator.RowCount; i++)
            {
                for (int j = 0; j < cellCreator.ColCount; j++)
                {
                    cells[i, j] = cellCreator.GenerateNextCell();
                }
            }

            this.Cells = cells;
        }
Esempio n. 2
0
        public FieldCell GenerateNextCell()
        {
            ConsoleColor currentCellColor = this.currentCellIsOdd ? this.oddColor : this.evenColor;
            FieldCell    result           = new FieldCell(this.currentCol, this.currentRow, this.representationChar, currentCellColor);

            this.currentCol++;
            if (this.currentCol == this.ColCount)
            {
                this.currentCol = 0;
                this.currentRow++;
                this.currentCellIsOdd = !this.currentCellIsOdd;

                if (this.currentRow > this.RowCount)
                {
                    throw new InvalidOperationException("All cells were generated.");
                }
            }

            this.currentCellIsOdd = !this.currentCellIsOdd;

            return(result);
        }