//I've made this indexer only for easier _gameBoard access inside the class private Xo this[Cell cell] { get { return _gameBoard[cell.X, cell.Y]; } set { _gameBoard[cell.X, cell.Y] = value; } }
public string DisplayBoard() { var borad = new StringBuilder().Append(Environment.NewLine); for (var i = 0; i < 3; i++) { for (var j = 0; j < 3; j++) { var cell = new Cell(i,j); var xo = (this[cell]) == 0 ? "?" : this[cell].ToString(); borad.AppendFormat("{0,2}", xo); } borad.Append(Environment.NewLine); } return borad.ToString(); }
public bool Move(Cell cell) { if (IsMoveIlegal(cell)) return false; this[cell] = CurrentTurn; _countMoves++; _lastMove = cell; ChangeTurn(); return true; }
private bool IsMoveIlegal(Cell cell) { if (!cell.IsValidCell()) return true; return this[cell] != 0; }