// 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; } } }
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; }
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; }
public Tile GetTile(Grid grid) { if (!InRange(grid)) { return null; } return Tiles[grid.Row, grid.Col]; }
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; }
public void PlaceTile(Tile NextTile, Grid g) { NextTile.CurrentGrid = g; Tiles[g.Row, g.Col] = NextTile; }
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); }
public Grid PointToGrid(Point p) { Grid g = new Grid((int)p.Y / MazeMaster.TileSize, (int)p.X / MazeMaster.TileSize); return g; }
public void PlaceTile(Grid g) { if (CurrentMaze.CanPlace(g)) { CurrentMaze.PlaceTile(NextTile, g); RandomNext(); } }