public GameViewModel() { _currentBoard = new Board(); for (var number = 1; number <= 9; number++) { var cellViewModel = new CellViewModel(this, number); Cells[number - 1] = cellViewModel; _currentBoard[cellViewModel.Row, cellViewModel.Column] = cellViewModel; } _currentPlayer = OPlayer; }
internal void HandleClick(CellViewModel cellViewModel) { var completeResult = _currentBoard.IsComplete(); if (completeResult.IsOver) { return; } if (cellViewModel.IsSet) { return; } cellViewModel.Text = CurrentPlayer.Letter; cellViewModel.Foreground = CurrentPlayer.Color; completeResult = _currentBoard.IsComplete(); if (completeResult.IsOver) { if (completeResult.Type == CompleteType.Draw) { PrefixText = "It's a draw!"; PlayerText = ""; SufixText = ""; } else { PrefixText = "Player "; PlayerText = CurrentPlayer.Letter.ToString(); PlayerColor = CurrentPlayer.Color; SufixText = " won!"; } HighlightWinner(completeResult); } else { SetPlayerAndText(); } }