/// <summary> /// Method called when a play is made in-game /// </summary> /// <param name="rowNo">Row number of the selected square</param> /// <param name="colNo">Column number of the selected square</param> /// <param name="squareOwner">Owner of the square (human, computer, open, error)</param> public void PlaySquare(int rowNo, int colNo, CellOwners squareOwner) { var targetSquare = _ticTacToeCells .FirstOrDefault(ttts => ttts.rowID == rowNo && ttts.colID == colNo); // there may be bad input, accounts for unknown unknowns and is safe programming practice if (targetSquare != null) { targetSquare.XorY = squareOwner; // new event argument with a row, column, and XorY property var eventArgs = new CellAssignmentArgs(targetSquare.rowID, targetSquare.colID, targetSquare.XorY); // assigns the new arguments to the selected square, if the cell selected isnt null if (this.CellAssignment != null) { CellAssignment(this, eventArgs); } } }
public void TicTacToeLogic_CellAssignmentChanged(object sender, CellAssignmentArgs e) { foreach (var item in tableLayoutPanel1.Controls) { var uc = item as GameCellControl; if (uc != null) { if ((uc.GameCellRow == e.RowId) && (uc.GameCellCol == e.ColId)) { switch (e.SquareOwner) { case TicTacToeEnums.CellOwners.Computer: uc.Value = "O"; break; case TicTacToeEnums.CellOwners.Error: uc.Value = "*"; break; case TicTacToeEnums.CellOwners.Human: uc.Value = "X"; break; case TicTacToeEnums.CellOwners.Open: uc.Value = "?"; break; default: uc.Value = "*"; break; } uc.Enabled = false; } } } }