Exemplo n.º 1
0
        private GameSquare UpLeftNeighbor(GameSquare square)
        {
            Point location = square.Location;

            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point upLeftNeighbor = new Point(location.X, location.Y);

            upLeftNeighbor.Y -= 1;

            // For even rows, down-left is the same; for odd rows, it's -1
            if (location.Y % 2 == 1)
            {
                upLeftNeighbor.X -= 1;
            }

            if ((upLeftNeighbor.X < 0) || (upLeftNeighbor.Y < 0))
            {
                return(null);
            }
            else
            {
                return(board[upLeftNeighbor.X, upLeftNeighbor.Y]);
            }
        }
Exemplo n.º 2
0
        private GameSquare DownRightNeighbor(GameSquare square)
        {
            Point location = square.Location;

            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point downRightNeighbor = new Point(location.X, location.Y);

            downRightNeighbor.Y += 1;

            // For even rows, up-right is +1; for odd rows, it's the same
            if (location.Y % 2 == 0)
            {
                downRightNeighbor.X += 1;
            }

            if ((downRightNeighbor.X >= ColumnCount) || (downRightNeighbor.Y >= RowCount))
            {
                return(null);
            }
            else
            {
                return(board[downRightNeighbor.X, downRightNeighbor.Y]);
            }
        }
Exemplo n.º 3
0
        public GameSquare GetNeighbor(GameSquare square, Direction direction)
        {
            switch (direction)
            {
            case Direction.Left:
                return(LeftNeighbor(square));

            case Direction.UpLeft:
                return(UpLeftNeighbor(square));

            case Direction.UpRight:
                return(UpRightNeighbor(square));

            case Direction.Right:
                return(RightNeighbor(square));

            case Direction.DownRight:
                return(DownRightNeighbor(square));

            case Direction.DownLeft:
                return(DownLeftNeighbor(square));

            default:
                throw new ArgumentException("Unknown direction");
            }
        }
Exemplo n.º 4
0
        protected void DrawSquareBackground(Graphics g, GameSquare square, float x, float y)
        {
            // Find the outline of the hexagon
            PointF[] hexagon = { new PointF(x,                 y + HEX_ADJUST),
                                 new PointF(x + HEX_WIDTH / 2, y - HEX_ADJUST),
                                 new PointF(x + HEX_WIDTH,     y + HEX_ADJUST),
                                 new PointF(x + HEX_WIDTH,     y + HEX_HEIGHT - HEX_ADJUST),
                                 new PointF(x + HEX_WIDTH / 2, y + HEX_HEIGHT + HEX_ADJUST),
                                 new PointF(x,                 y + HEX_HEIGHT - HEX_ADJUST) };

            // Draw the outline
            g.DrawPolygon(Pens.White, hexagon);

            // If the square isn't safe, highlight it
            if (!square.IsSafe)
            {
                g.FillPolygon(unsafeBrush, hexagon);
            }

            // Put in the coordinates (for debugging only)
            // g.DrawString(square.Column + "," + square.Row, coordFont, Brushes.White, x + 23, y - 3);

            // Mark start and finish
            if (square.IsWinningLoc)
            {
                g.DrawString("Finish", finishFont, Brushes.White, x + 20, y - 2);
            }

            // Add tag for special squares
            string squareTag = "";
            Brush  tagBrush;

            if (square is SafeSquare)
            {
                squareTag = "A";
                tagBrush  = Brushes.Green;
            }
            else if (square is HostileSquare)
            {
                squareTag = "H";
                tagBrush  = Brushes.Red;
            }
            else if (square is WarpSquare)
            {
                squareTag = "W";
                tagBrush  = ((WarpSquare)square).WarpColor;
            }
            else
            {
                return;
            }

            g.DrawString(squareTag, objectFont, tagBrush, x + 30, y + 20);
        }
Exemplo n.º 5
0
        public override void MarkUnsafeSquares()
        {
            Location.IsSafe = false;

            foreach (Direction dir in scans)
            {
                GameSquare square = board.GetNeighbor(Location, dir);
                if (square != null)
                {
                    square.IsSafe = false;
                }
            }
        }
Exemplo n.º 6
0
        public override void MarkUnsafeSquares()
        {
            Location.IsSafe = false;

            GameSquare leftNeighbor = board.GetNeighbor(Location, Direction.Left);

            if (leftNeighbor != null)
            {
                leftNeighbor.IsSafe = false;
            }

            GameSquare upLeftNeighbor = board.GetNeighbor(Location, Direction.UpLeft);

            if (upLeftNeighbor != null)
            {
                upLeftNeighbor.IsSafe = false;
            }

            GameSquare upRightNeighbor = board.GetNeighbor(Location, Direction.UpRight);

            if (upRightNeighbor != null)
            {
                upRightNeighbor.IsSafe = false;
            }

            GameSquare rightNeighbor = board.GetNeighbor(Location, Direction.Right);

            if (rightNeighbor != null)
            {
                rightNeighbor.IsSafe = false;
            }

            GameSquare downRightNeighbor = board.GetNeighbor(Location, Direction.DownRight);

            if (downRightNeighbor != null)
            {
                downRightNeighbor.IsSafe = false;
            }

            GameSquare downLeftNeighbor = board.GetNeighbor(Location, Direction.DownLeft);

            if (downLeftNeighbor != null)
            {
                downLeftNeighbor.IsSafe = false;
            }
        }
Exemplo n.º 7
0
        protected void DrawGameSquare(GameSquare square,
            Graphics g)
        {
            // (x,y) is the upper-left corner of the rectangle that
            // approximates the hexagon
            float x = 10 + square.Column * HEX_WIDTH;
            float y = 20 + square.Row * HEX_HEIGHT;

            // Offset even rows by 1/2 of width
            if (square.Row % 2 == 0)
            {
                x += HEX_WIDTH / 2;
            }

            DrawSquareBackground(g, square, x, y);
            DrawOccupant(g, square.Occupant, x, y);
        }
Exemplo n.º 8
0
        protected void DrawGameSquare(GameSquare square,
                                      Graphics g)
        {
            // (x,y) is the upper-left corner of the rectangle that
            // approximates the hexagon
            float x = 10 + square.Column * HEX_WIDTH;
            float y = 20 + square.Row * HEX_HEIGHT;

            // Offset even rows by 1/2 of width
            if (square.Row % 2 == 0)
            {
                x += HEX_WIDTH / 2;
            }

            DrawSquareBackground(g, square, x, y);
            DrawOccupant(g, square.Occupant, x, y);
        }
Exemplo n.º 9
0
        public bool Move(Direction dir)
        {
            GameSquare target = board.GetNeighbor(Location, dir);

            if (target == null)
            {
                return(false);
            }

            if (target is WarpSquare)
            {
                Location = ((WarpSquare)target).TargetSquare;
            }
            else
            {
                Location = target;
            }
            return(true);
        }
Exemplo n.º 10
0
        private GameSquare RightNeighbor(GameSquare square)
        {
            Point location = square.Location;

            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point rightNeighbor = new Point(location.X, location.Y);

            rightNeighbor.X += 1;

            if (rightNeighbor.X >= ColumnCount)
            {
                return(null);
            }
            else
            {
                return(board[rightNeighbor.X, rightNeighbor.Y]);
            }
        }
Exemplo n.º 11
0
 public GameObject(GameBoard board)
 {
     this.board = board;
     location   = null;
 }
Exemplo n.º 12
0
        private GameSquare UpRightNeighbor(GameSquare square)
        {
            Point location = square.Location;
            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point upRightNeighbor = new Point(location.X, location.Y);
            upRightNeighbor.Y -= 1;

            // For even rows, down-right is +1; for odd rows, it's the same
            if (location.Y % 2 == 0)
            {
                upRightNeighbor.X += 1;
            }

            if ((upRightNeighbor.X >= ColumnCount) || (upRightNeighbor.Y < 0))
            {
                return null;
            }
            else
            {
                return board[upRightNeighbor.X, upRightNeighbor.Y];
            }
        }
Exemplo n.º 13
0
        private GameSquare RightNeighbor(GameSquare square)
        {
            Point location = square.Location;
            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point rightNeighbor = new Point(location.X, location.Y);
            rightNeighbor.X += 1;

            if (rightNeighbor.X >= ColumnCount)
            {
                return null;
            }
            else
            {
                return board[rightNeighbor.X, rightNeighbor.Y];
            }
        }
Exemplo n.º 14
0
 public GameSquare GetNeighbor(GameSquare square, Direction direction)
 {
     switch (direction)
     {
         case Direction.Left:
             return LeftNeighbor(square);
         case Direction.UpLeft:
             return UpLeftNeighbor(square);
         case Direction.UpRight:
             return UpRightNeighbor(square);
         case Direction.Right:
             return RightNeighbor(square);
         case Direction.DownRight:
             return DownRightNeighbor(square);
         case Direction.DownLeft:
             return DownLeftNeighbor(square);
         default:
             throw new ArgumentException("Unknown direction");
     }
 }
Exemplo n.º 15
0
 public GameObject(GameBoard board)
 {
     this.board = board;
     location = null;
 }
Exemplo n.º 16
0
        private GameSquare DownLeftNeighbor(GameSquare square)
        {
            Point location = square.Location;
            if ((location.X < 0) || (location.X >= ColumnCount) ||
                (location.Y < 0) || (location.Y >= RowCount))
            {
                throw new IndexOutOfRangeException();
            }

            Point downLeftNeighbor = new Point(location.X, location.Y);
            downLeftNeighbor.Y += 1;

            // For even rows, up-left is the same column index; for odd rows, it's -1
            if (location.Y % 2 == 1)
            {
                downLeftNeighbor.X -= 1;
            }

            if ((downLeftNeighbor.X < 0) || (downLeftNeighbor.Y >= RowCount))
            {
                return null;
            }
            else
            {
                return board[downLeftNeighbor.X, downLeftNeighbor.Y];
            }
        }
Exemplo n.º 17
0
 public PatrolObject(GameBoard board, GameSquare[] path)
     : base(board)
 {
     this.path = path;
 }
Exemplo n.º 18
0
        protected void DrawSquareBackground(Graphics g, GameSquare square, float x, float y)
        {
            // Find the outline of the hexagon
            PointF[] hexagon = {new PointF(x, y + HEX_ADJUST),
                                new PointF(x + HEX_WIDTH / 2, y - HEX_ADJUST),
                                new PointF(x + HEX_WIDTH, y + HEX_ADJUST),
                                new PointF(x + HEX_WIDTH, y + HEX_HEIGHT - HEX_ADJUST),
                                new PointF(x + HEX_WIDTH / 2, y + HEX_HEIGHT + HEX_ADJUST),
                                new PointF(x, y + HEX_HEIGHT - HEX_ADJUST)};

            // Draw the outline
            g.DrawPolygon(Pens.White, hexagon);

            // If the square isn't safe, highlight it
            if (!square.IsSafe)
            {
                g.FillPolygon(unsafeBrush, hexagon);
            }

            // Put in the coordinates (for debugging only)
            // g.DrawString(square.Column + "," + square.Row, coordFont, Brushes.White, x + 23, y - 3);

            // Mark start and finish
            if (square.IsWinningLoc)
            {
                g.DrawString("Finish", finishFont, Brushes.White, x + 20, y - 2);
            }

            // Add tag for special squares
            string squareTag = "";
            Brush tagBrush;
            if (square is SafeSquare)
            {
                squareTag = "A";
                tagBrush = Brushes.Green;
            }
            else if (square is HostileSquare)
            {
                squareTag = "H";
                tagBrush = Brushes.Red;
            }
            else if (square is WarpSquare)
            {
                squareTag = "W";
                tagBrush = ((WarpSquare)square).WarpColor;
            }
            else
            {
                return;
            }

            g.DrawString(squareTag, objectFont, tagBrush, x + 30, y + 20);
        }