Example #1
0
        public void SetPiece(int x, int y, PieceState state)
        {
            var piece = GetPiece(x, y);
            var dummy = new Piece(piece.X, piece.Y);
            dummy.SetState(state);

            // Throw an exception if the location has already been set
            if (piece.State != PieceState.Open)
                throw new ArgumentException("Location already set");

            // Throw an exception if placement is invalid
            if (!IsPlacingAllowed(dummy))
                throw new ArgumentException("The piece does not have any valid adjacent pieces");

            // Place the piece
            piece.SetState(state);

            // Turn connecting pieces
            var connectingPieces = GetValidConnectingPieces(piece);
            foreach (var p in connectingPieces)
            {
                p.SetState(state);
            }
        }