private static void ShowGrid(CellState[,] currentState) { Console.Clear(); int x = 0; int rowLength = currentState.GetUpperBound(1) + 1; foreach (CellState state in currentState) { string output; if (state == CellState.Alive) { output = "0"; } else { output = "."; } Console.Write(output); x++; if (x >= rowLength) { x = 0; Console.WriteLine(); } } }
public TTTGame(int gridRows, int gridColumns) { // Init Rows and Colums along with the grid mRows = gridRows; mColumns = gridColumns; mGrid = new CellState[mRows, mColumns]; for (int i = 0; i <= mGrid.GetUpperBound(0); i++) { for (int j = 0; j <= mGrid.GetUpperBound(1); j++) { mGrid[i, j] = CellState.NIL; } } // Init game states mGameOver = false; mPlayerWins = false; mIsDraw = false; mWinnerSymbol = CellState.NIL; }
public SortedSet <CellState> ComputeTopEndCell() { var r = new SortedSet <CellState>(new CellStatePositionComparer()); CellState cell = _cells[0, _cells.GetUpperBound(1)]; if (cell != null) { r.Add(cell); } return(r); }
private static void ShowGrid(CellState[,] currentState) { Console.Clear(); int x = 0; int rowLength = currentState.GetUpperBound(1) + 1; foreach (var state in currentState) { var output = state == CellState.Alive ? "0" : "."; Console.Write(output); x++; if (x >= rowLength) { x = 0; Console.WriteLine(); } } }
private static void ShowGrid(CellState[,] currentState) { //clear the console of the prevous grid Console.Clear(); int x = 0; int rowLength = currentState.GetUpperBound(1) + 1; var output = new StringBuilder(); foreach (var state in currentState) { //if cell is alive it will be written as an "O" dead as "." output.Append(state == CellState.Alive ? "O" : "·"); x++; if (x >= rowLength) { x = 0; output.AppendLine(); } } Console.Write(output.ToString()); }
private static void ShowGrid(CellState[,] currentState) { int x = 0; int rowLength = currentState.GetUpperBound(1) + 1; var output = new StringBuilder(); foreach (var state in currentState) { output.Append(state == CellState.Alive ? "O" : "·"); x++; if (x >= rowLength) { x = 0; output.AppendLine(); } } Console.Clear(); Console.Write(output.ToString()); }
private static void DrawBoard(bool mock = false) { battleBoard = game.GetBattleBoard(); personalBoard = game.GetPersonalBoard(); if (personalBoard == null) { personalBoard = new ShipCell[1, 1]; } int height = battleBoard.GetUpperBound(0) + 1; int width = battleBoard.GetUpperBound(1) + 1; Console.Write(LINE_INDENT + " "); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write($" {(char)('A' + colIndex)} "); } Console.Write(LINE_INDENT + " "); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write($" {(char)('A' + colIndex)} "); } Console.WriteLine(); Console.Write(LINE_INDENT + " " + CROSS_POINT); firstCellRow = Console.CursorTop + 1; firstCellCol = Console.CursorLeft + ROW_SEP.Length / 2; for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write(ROW_SEP + CROSS_POINT); } lastCellCol = Console.CursorLeft - ROW_SEP.Length / 2 - 2; Console.Write(LINE_INDENT + " " + CROSS_POINT); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write(ROW_SEP + CROSS_POINT); } Console.WriteLine(); for (int rowIndex = 0; rowIndex < height; rowIndex++) { for (int colIndex = 0; colIndex < LINE_INDENT.Length - $"{rowIndex + 1}".Length + 1; colIndex++) { Console.Write(LINE_INDENT[0]); } Console.Write($"{rowIndex + 1}{COL_SEP}"); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write($" {(mock ? MOCK_CHAR : CellString(battleBoard[rowIndex, colIndex]))} {COL_SEP}"); } for (int colIndex = 0; colIndex < LINE_INDENT.Length - $"{rowIndex + 1}".Length + 1; colIndex++) { Console.Write(LINE_INDENT[0]); } Console.Write($"{rowIndex + 1}{COL_SEP}"); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write($" {(mock ? MOCK_CHAR : CellString(personalBoard[rowIndex, colIndex]?.State ?? new ShipCell().State))} {COL_SEP}"); } Console.WriteLine(); Console.Write(LINE_INDENT + " " + CROSS_POINT); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write(ROW_SEP + CROSS_POINT); } Console.Write(LINE_INDENT + " " + CROSS_POINT); for (int colIndex = 0; colIndex < width; colIndex++) { Console.Write(ROW_SEP + CROSS_POINT); } Console.WriteLine(); } lastCellRow = Console.CursorTop - 2; }