Exemple #1
0
        // assuming that we are always either in the same row or column
        public static Direction GetDirection(Grid source, Grid destination)
        {
            if (source.Col == destination.Col && source.Row == destination.Row)
            {
                return Direction.None;
            }
            if (source.Col == destination.Col)
            {
                if (source.Row < destination.Row)
                {
                    return Direction.Down;
                }
                else
                {
                    return Direction.Up;
                }

            }
            else
            {
                if (source.Col < destination.Col)
                {
                    return Direction.Right;
                }
                else
                {
                    return Direction.Left;
                }
            }
        }
Exemple #2
0
        public static Grid GetBackOf(Grid currentGrid, Direction facingDirection)
        {
            Grid targetGrid = currentGrid;
            if (facingDirection == Direction.Up)
            {
                targetGrid.Row += 1;
            }
            else if (facingDirection == Direction.Down)
            {
                targetGrid.Row -= 1;
            }
            else if (facingDirection == Direction.Left)
            {
                targetGrid.Col += 1;
            }
            else if (facingDirection == Direction.Right)
            {
                targetGrid.Col -= 1;
            }
            else // None
            {

            }
            return targetGrid;
        }
Exemple #3
0
 public bool InRange(Grid grid)
 {
     if (grid.Row < 0 || grid.Col < 0 || grid.Row >= Tiles.GetLength(0) || grid.Col >= Tiles.GetLength(1))
     {
         return false;
     }
     return true;
 }
Exemple #4
0
 public Tile GetTile(Grid grid)
 {
     if (!InRange(grid))
     {
         return null;
     }
     return Tiles[grid.Row, grid.Col];
 }
Exemple #5
0
 public bool CanPlace(Grid g)
 {
     if (!InRange(g))
     {
         return false;
     }
     if (Tiles[g.Row, g.Col].IsExit)
     {
         return false;
     }
     foreach (Unit u in Humans)
     {
         if (u.TargetGrid == g || u.CurrentGrid == g)
         {
             return false;
         }
     }
     return true;
 }
Exemple #6
0
 public void PlaceTile(Tile NextTile, Grid g)
 {
     NextTile.CurrentGrid = g;
     Tiles[g.Row, g.Col] = NextTile;
 }
Exemple #7
0
 public void Kidnap(Unit unit)
 {
     Grid grid = new Grid(rng.Next(4,8),rng.Next(4,8));
     unit.SetGrid(grid);
     unit.ContainingMaze = this;
     Humans.Add(unit);
 }
Exemple #8
0
 public Grid PointToGrid(Point p)
 {
     Grid g = new Grid((int)p.Y / MazeMaster.TileSize, (int)p.X / MazeMaster.TileSize);
     return g;
 }
Exemple #9
0
 public void PlaceTile(Grid g)
 {
     if (CurrentMaze.CanPlace(g))
     {
         CurrentMaze.PlaceTile(NextTile, g);
         RandomNext();
     }
 }