예제 #1
0
        public void DrawCurrentState(int picNum)
        {
            for (int y = 0; y < Squares.GetLength(0); y++)
            {
                for (int x = 0; x < Squares.GetLength(1); x++)
                {
                    Squares[x, y].Render(Bitmap, Color.White);
                }
            }

            foreach (Square square in ClosedSet)
            {
                square.Render(Bitmap, Color.Red);
            }

            foreach (Square square in OpenSet)
            {
                square.Render(Bitmap, Color.Green);
            }

            foreach (Square square in Path)
            {
                square.Render(Bitmap, Color.Blue);
            }

            End.Render(Bitmap, Color.Black);
            Start.Render(Bitmap, Color.Black);

            string picName = $"{picNum}.bmp";

            Bitmap.Save(picName);
            Console.WriteLine($"Drawn next state at: {Directory.GetCurrentDirectory()}\\{picName}");
        }
예제 #2
0
 /// <summary>
 /// Ends the game by disabling all squares
 /// </summary>
 public void EndGame()
 {
     for (int i = 0; i < Squares.GetLength(0); i++)
     {
         for (int j = 0; j < Squares.GetLength(1); j++)
         {
             Squares[i, j].CanBePlaced = false;
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Forces every square to check its bounds
 /// </summary>
 public static void CheckSquares()
 {
     for (int i = 0; i < Squares.GetLength(0); i++)
     {
         for (int j = 0; j < Squares.GetLength(1); j++)
         {
             Squares[i, j].CheckSquare();
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Sets up the GridPanel. Creates all 9x12 squares and places them on the board
        /// </summary>
        public GridPanel()
        {
            InitializeComponent();

            // The range of letters used to label the squares
            const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            // Create and place all 9x12 squares
            for (int i = 0; i < Squares.GetLength(0); i++)
            {
                for (int j = 0; j < Squares.GetLength(1); j++)
                {
                    // Create a new square with the right letter and number
                    Squares[i, j] = new Square(alphabet[i] + (j + 1).ToString())
                    {
                        // 2 pixel gap on all sides + width of 40 and height of 37
                        Location = new Point(GetSquareLocationFromSize(WIDTH, i), GetSquareLocationFromSize(HEIGHT, j))
                    };

                    // Add the new square to the panel
                    Controls.Add(Squares[i, j]);

                    // Add each square to the bag
                    if (!SquareBag.Contains(Squares[i, j]))
                    {
                        SquareBag.Add(Squares[i, j]);
                    }
                }
            }

            // For each square
            for (int i = 0; i < Squares.GetLength(0); i++)
            {
                for (int j = 0; j < Squares.GetLength(1); j++)
                {
                    // Find the squares to the left
                    Square left = i != 0 ? Squares[i - 1, j] : null;

                    // Right
                    Square right = i != 8 ? Squares[i + 1, j] : null;

                    // Top
                    Square top = j != 0 ? Squares[i, j - 1] : null;

                    // And bottom
                    Square bottom = j != 11 ? Squares[i, j + 1] : null;

                    // And set them as the current square's bounds
                    Squares[i, j].SetBounds(left, right, top, bottom);
                }
            }

            // Shuffles the bag
            ShuffleBag();
        }
예제 #5
0
 /// <param name="position">This function checks whether <paramref name="position"/> is within the bounds of the chess board</param>
 ///
 /// <return>true if position exists on the board, false otherwise</return>
 public virtual bool IsInsideBounds(Vec2 <int> position)
 {
     if ((position.X >= 0) && (position.X < Squares.GetLength(0)))
     {
         return((position.Y >= 0) && (position.Y < Squares.GetLength(1)));
     }
     else
     {
         return(false);
     }
 }
예제 #6
0
        public List <Square> GetNeighbors(Square square)
        {
            List <Square> neighbors = new List <Square>();

            /*
             * // get left
             * if (square.X > 0)
             *  neighbors.Add(Squares[square.X - 1, square.Y]);
             * // get right
             * if (square.X < Squares.GetLength(1) - 1)
             *  neighbors.Add(Squares[square.X + 1, square.Y]);
             * // get top
             * if (square.Y > 0)
             *  neighbors.Add(Squares[square.X, square.Y - 1]);
             * // get bottom
             * if (square.Y < Squares.GetLength(0) - 1)
             *  neighbors.Add(Squares[square.X, square.Y + 1]);
             * // top right
             * if (square.X + 1 < Squares.GetLength(1) && square.Y - 1 > 0)
             *  neighbors.Add(Squares[square.X + 1, square.Y - 1]);
             * // bottom right
             * if (square.X + 1 < Squares.GetLength(1) && square.Y + 1 < Squares.GetLength(0))
             *  neighbors.Add(Squares[square.X + 1, square.Y + 1]);
             * // bottom left
             * if (square.X - 1 > 0 && square.Y + 1 < Squares.GetLength(0))
             *  neighbors.Add(Squares[square.X - 1, square.Y + 1]);
             * // top left
             * if (square.X - 1 > 0 && square.Y - 1 > 0)
             *  neighbors.Add(Squares[square.X - 1, square.Y - 1]);
             * return neighbors;
             */
            // better alternative

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (x == 0 && y == 0)
                    {
                        continue;
                    }
                    int checkX = square.X + x;
                    int checkY = square.Y + y;

                    if (checkX >= 0 && checkX < Squares.GetLength(1) && checkY >= 0 && checkY < Squares.GetLength(0))
                    {
                        neighbors.Add(Squares[checkX, checkY]);
                    }
                }
            }
            return(neighbors);
        }
예제 #7
0
        public void Rotate()
        {
            int squaresWidth  = Squares.GetLength(0);
            int squaresHeight = Squares.GetLength(1);

            Square[,] rotated = new Square[squaresHeight, squaresWidth];

            for (int x = 0; x < squaresHeight; x++)
            {
                for (int y = 0; y < squaresWidth; y++)
                {
                    rotated[x, y] = Squares[y, squaresHeight - 1 - x];
                }
            }

            Squares = rotated;
        }
예제 #8
0
        /// <summary>
        /// Updates the display to show which squares a player has and can place
        /// </summary>
        ///
        /// <param name="player">The player whose placeable squares are going to be displayed</param>
        public void UpdateHeldSquares(IPlayer player)
        {
            // Update the hand panel too
            Game.SetHand(player.Squares);

            // Go through each square
            for (int i = 0; i < Squares.GetLength(0); i++)
            {
                for (int j = 0; j < Squares.GetLength(1); j++)
                {
                    // Determine whether this player has this square
                    bool hasSquare = player.Squares.Contains(Squares[i, j]);
                    // Change the border on it
                    Squares[i, j].BorderStyle = hasSquare ? BorderStyle.Fixed3D : BorderStyle.None;
                    // If it is placeable, change it's state
                    if (Squares[i, j].CanBePlaced)
                    {
                        Squares[i, j].SetState(hasSquare ? SquareState.Placeable : SquareState.Open);
                    }
                }
            }
        }
예제 #9
0
            public void Initialize2DCoordinates(Vec2 <uint> coordinates)
            {
                this.OriginCoordinates = coordinates;

                Vec2 <uint> squareOrigin = OriginCoordinates;

                for (uint i = 0; i < Squares.GetLength(0); i++)
                {
                    Square square = null;
                    for (uint j = 0; j < Squares.GetLength(1); j++)
                    {
                        square = (Square)Squares[i, j];

                        square.Initialize2DCoordinates(squareOrigin);

                        squareOrigin.Y += square.Size.Height;
                    }

                    // ReSharper disable once PossibleNullReferenceException
                    squareOrigin.X += square.Size.Width;
                    squareOrigin.Y  = OriginCoordinates.Y;
                }
            }