示例#1
0
 private void FillSqrBottom(Board board, Square sqr)
 {
     for (int i = 0; i < Length; i++)
     {
         Squares.Add(board.Squares[sqr.X, sqr.Y - i]);
         board.Squares[sqr.X, sqr.Y - i].Ship = this;
     }
 }
示例#2
0
 private void FillSqrRight(Board board, Square sqr)
 {
     for (int i = 0; i < Length; i++)
     {
         Squares.Add(board.Squares[sqr.X + i, sqr.Y]);
         board.Squares[sqr.X + i, sqr.Y].Ship = this;
     }
 }
示例#3
0
        private void DrawSquares(Graphics g)
        {
            Squares.Clear();
            for (var r = Rank._1; r <= Rank._8; r++)
            {
                for (var f = File.A; f <= File.H; f++)
                {
                    var x           = Flipped ? Left + (Side - ((int)f + 1) * SquareSide) : Left + (int)f * SquareSide;
                    var y           = Flipped ? Top + ((int)r * SquareSide) : Top + Side - ((int)r + 1) * SquareSide;
                    var chessSquare = Game.Board.Square(f, r);
                    var brush       = chessSquare.Color == Chess.Color.Black ? DarkBrush : LightBrush;

                    var rect = new RectangleF(x, y, SquareSide, SquareSide);
                    g.FillRectangle(brush, rect);
                    var circleRect = rect;
                    circleRect.Inflate(-SquareSide * 0.75f, -SquareSide * 0.75f);
                    if (HiLights.Contains(chessSquare))
                    {
                        g.FillEllipse(_hiLightBrush, circleRect);
                    }

                    var lastMove = Game.OtherPlayer.Moves.FirstOrDefault();
                    if (lastMove != null)
                    {
                        if (lastMove.FromSquare == chessSquare || lastMove.ToSquare == chessSquare)
                        {
                            g.FillRectangle(LastMoveBrush, rect);
                        }
                    }

                    Squares.Add(chessSquare, rect);
                    if (chessSquare.Piece != null && MouseDownSquare != chessSquare)
                    {
                        if (_animationOffset == null || chessSquare.Piece != _animationOffset.Item1)
                        {
                            DrawPiece(chessSquare, rect, g);
                        }
                    }

                    //g.DrawString(chessSquare.ToString(), new Font(FontFamily.GenericSansSerif, 12), Brushes.Red, x + SquareSide / 16,
                    //        y + SquareSide / 4);
                }
                if (MouseDownSquare?.Piece != null)
                {
                    var x    = MouseX - SquareSide / 2;
                    var y    = MouseY - SquareSide / 2;
                    var rect = new RectangleF(x, y, SquareSide, SquareSide);
                    DrawPiece(MouseDownSquare, rect, g);
                }


                if (_animationOffset != null && _animationOffset.Item1 != null)
                {
                    var rect = new RectangleF(_animationOffset.Item2.X, _animationOffset.Item2.Y, SquareSide, SquareSide);
                    DrawPiece(_animationOffset.Item1.Square, rect, g);
                }
            }
        }
 private void ExtendSquares()
 {
     /* Called when the Size property or SquareSideLength property is changed,
      * and the resulting change is a higher window size,
      * or a larger amount of squares.
      *
      * Extends (or initializes) the squares list. */
     if (Squares == null)
     {
         // First-time initialization of the entire grid.
         var topList = new List <List <Square> >();
         for (int y = 0; y < this.Height; y += SquareSideLength)
         {
             var sublist = new List <Square>();
             for (int x = 0; x < this.Width; x += SquareSideLength)
             {
                 /* We create a new Square object with this GridBox as its parent,
                  * and x and y as its location and rectangle parameters.
                  * The actual location and rectangle are created and set
                  * in the square's constructor. */
                 Square squareObj = new Square(this, x, y);
                 sublist.Add(squareObj);
             }
             topList.Add(sublist);
         }
         /* Set the Squares list of lists to the newly populated top list. */
         this.Squares = topList;
     }
     else
     {
         // Modify the existing squares list
         // First extend the existing sublists.
         for (int y = 0; y < Squares.Count; y++)
         {
             // y is an index value
             for (int x = Squares[y].Count * SquareSideLength; x < this.Width; x += SquareSideLength)
             {
                 Square squareObj = new Square(this, x, y * SquareSideLength);
                 Squares[y].Add(squareObj);
             }
         }
         // Now add the potentially new lists
         for (int y = Squares.Count * SquareSideLength; y < this.Height; y += SquareSideLength)
         {
             // y is a pixel point
             List <Square> sublist = new List <Square>();
             for (int x = 0; x < this.Width; x += SquareSideLength)
             {
                 Square squareObj = new Square(this, x, y);
                 sublist.Add(squareObj);
             }
             Squares.Add(sublist);
         }
     }
     // Redraw the grid.
     this.Invalidate();
 }
示例#5
0
        private void Init()
        {
            var board = generator.Generate();

            foreach (var item in board)
            {
                Squares.Add(item);
            }
        }
示例#6
0
        private void BoardView_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (var square in BoardGrid.Children.Where(x => x.GetType() == typeof(SquareView)))
            {
                Squares.Add(square as SquareView);
            }

            foreach (var piece in BoardGrid.Children.Where(x => x.GetType() == typeof(PieceView)))
            {
                Pieces.Add(piece as PieceView);
            }
        }
示例#7
0
        private void SetupBoard()
        {
            RowNumberArray = GenerateNumbers();
            ColNumberArray = GenerateNumbers();
            var squareNumber = 1;

            for (var row = 0; row < RowNumberArray.Length; row++)
            {
                for (var col = 0; col < ColNumberArray.Length; col++)
                {
                    var square = new Square(squareNumber++, RowNumberArray[row], ColNumberArray[col]);
                    Squares.Add(square);
                }
            }
        }
 private void CreateItems()
 {
     Squares.Clear();
     Route.Clear();
     for (int i = 0; i < Size; i++)
     {
         for (int j = 0; j < Size; j++)
         {
             Squares.Add(new GridItem()
             {
                 Row = i, Column = j
             });
         }
     }
 }
示例#9
0
        /// <summary>
        /// The move squares.
        /// </summary>
        /// <param name="squares">
        /// The squares.
        /// </param>
        private void MoveSquares(ref Squares squares)
        {
            Square square;

            square = Board.GetSquare(this.Base.Square.Ordinal - 1);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal + 15);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal + 16);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal + 17);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal + 1);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal - 15);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal - 16);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }

            square = Board.GetSquare(this.Base.Square.Ordinal - 17);
            if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
            {
                squares.Add(square);
            }
        }
示例#10
0
 private void addC(object obj)
 {
     Squares.Add(new Square());
     setNumbers();
 }