Example #1
0
        public void RefreshBoard()
        {
            for (int i = 0; i < 3; i++)
            {
                for (int k = 0; k < 3; k++)
                {
                    theGrid[i][k] = Marker.Blank;
                }
            }

            _marker   = Marker.Cross;
            _numMoves = 0;
            _refreshBoard?.Invoke(null);
        }
Example #2
0
        public void PlaceMarker(int x, int y)
        {
            if ((x < 3) && (y < 3) && (theGrid[y][x] == Marker.Blank))
            {
                theGrid[y][x] = _marker;
                _marker       = (_marker == Marker.Cross) ? Marker.Nought : Marker.Cross;
                _numMoves    += 1;

                if (this.IsWinningMove(x, y))
                {
                    //If it is trigger the win drawing event
                    var winningLine = GetWinningLine(x, y);
                    _winAction?.Invoke(winningLine);
                }
                else if (_numMoves == 9) //The board is full
                {
                    _drawTrue?.Invoke(null);
                }
            }
            //We don't want this to trigger an error cause the user might have just clicked here.
        }