예제 #1
0
        public void ThenPositionShouldBeEmpty(string textPosition)
        {
            var position = new SquareIdentifier(textPosition);
            var square = ChessScenario.Board[position];

            square.Piece.Should().BeNull();
            square.IsFree().Should().BeTrue();
        }
예제 #2
0
        public void ThenShouldBeAbleToMoveTo(string textColor, string textFrom, string textTo)
        {
            var color = BoardHelper.ToArmyColor(textColor);
            ChessScenario.Game.CurrentTurn.Should().Be(color);

            var from = new SquareIdentifier(textFrom);
            var to = new SquareIdentifier(textTo);
            var piece = ChessScenario.Board[from].Piece;

            piece.GetPossibleMoves()
                .Should()
                .Contain(to);
        }
예제 #3
0
        public void ThenShouldBeAbleToMoveTo(string textColor, string textFrom, Table toOptions)
        {
            var color = BoardHelper.ToArmyColor(textColor);
            ChessScenario.Game.CurrentTurn.Should().Be(color);

            var from = new SquareIdentifier(textFrom);
            var piece = ChessScenario.Board[from].Piece;

            var tos = toOptions.Rows
                .Select(row => new SquareIdentifier(row[0]))
                .ToList();

            piece.GetPossibleMoves()
                .Should()
                .BeEquivalentTo(tos);
        }
예제 #4
0
        public void ThenThereShouldBe(string textColor, string textPieceType, string textPosition)
        {
            var position = new SquareIdentifier(textPosition);
            var color = BoardHelper.ToArmyColor(textColor);
            var pieceType = BoardHelper.ToPieceType(textPieceType);

            var piece = ChessScenario.Board[position].Piece;

            piece.Should().NotBeNull(string.Format("there should be a piece at {0}", position));
            piece.Color.Should().Be(color);
            piece.CurrentSquare.Identifier.Should().Be(position);
            piece.GetType().Should().Be(pieceType);
        }
        private void RenderBoard(Board board)
        {
            foreach (var positionKey in _squares.Keys)
            {
                var position = new SquareIdentifier(positionKey);
                var square = board[position];

                var gridView = _squares[positionKey];
                var element = gridView.Items.FirstOrDefault() as PieceElement;

                if (element != null)
                {
                    if (square.IsOccupied())
                    {
                        if (element.PieceType != square.Piece.GetType()
                            || element.Color != square.Piece.Color)
                        {
                            gridView.Items.Clear();
                            var pieceElement = new PieceElement(square.Piece);
                            gridView.Items.Add(pieceElement);
                        }
                    }
                    else
                    {
                        gridView.Items.Clear();
                    }
                }
                else if (square.IsOccupied())
                {
                    var pieceElement = new PieceElement(square.Piece);
                    gridView.Items.Add(pieceElement);
                }
            }
        }
        private void OnDrop(object sender, DragEventArgs e)
        {
            try
            {
                var grid = (GridView)sender;
                var from = new SquareIdentifier(_draggedFrom.Name.ToLower());
                var to = new SquareIdentifier(grid.Name.ToLowerInvariant());
                _game.Move(from, to);

                _draggedFrom.Items.Remove(_draggedPiece);
                grid.Items.Clear();
                grid.Items.Add(new PieceElement(_game.Board[to].Piece));
                RenderBoard(_game.Board);
            }
            catch (IllegalMoveException)
            {
                // Don't make drop
            }
        }
예제 #7
0
 public override int GetHashCode()
 {
     return(IsStartForPattern.GetHashCode() ^ SquareIdentifier.GetHashCode() ^ Position.GetHashCode() ^ IsEnemy.GetHashCode());
 }