Beispiel #1
0
        public static Location GetNextSpace(Location currentspace, string direction)
        {
            Location nextspace = new Location();
            switch (direction)
            {
                case "up":
                    nextspace.X = currentspace.X;
                    nextspace.Y = currentspace.Y - 1;
                    break;

                case "down":
                    nextspace.X = currentspace.X;
                    nextspace.Y = currentspace.Y + 1;
                    break;

                case "left":
                    nextspace.X = currentspace.X - 1;
                    nextspace.Y = currentspace.Y;
                    break;

                case "right":
                    nextspace.X = currentspace.X + 1;
                    nextspace.Y = currentspace.Y;
                    break;

                default:
                    nextspace.X = 1;
                    nextspace.Y = 1;
                    break;
            }
            return nextspace;
        }
Beispiel #2
0
 public static Location GetCurrentPlayerSpace(Square[,] map)
 {
     Location space = new Location();
     for (int i = 0; i< map.GetLength(0); i++)
     {
         for (int j = 0; j < map.GetLength(1); j++)
         {
             if (map[i,j].Piece == "Man")
             {
                 space.X = j;
                 space.Y = i;
                 break;
             }
         }
     }
     return space;
 }
Beispiel #3
0
 public static bool IsValidMove(Location nextspace, string direction, Square[,] map)
 {
     //check out of bounds
     if (nextspace.X < 0 || nextspace.Y < 0 || nextspace.X > map.GetLength(1) || nextspace.Y > map.GetLength(0))
     {
         return false;
     }
     //check if hitting wall
     if (map[nextspace.Y,nextspace.X].Space == "Wall")
     {
         return false;
     }
     //check if pushing crate against a wall
     if (IsPushingCrate(nextspace, map))
     {
         var nextcratespace = GetNextSpace(nextspace, direction);
         if (map[nextcratespace.Y,nextcratespace.X].Space == "Wall" || IsPushingCrate(nextcratespace, map))
         {
             return false;
         }
     }
     return true;
 }
Beispiel #4
0
 public static bool IsPushingCrate(Location nextspace, Square[,] map)
 {
     if (map[nextspace.Y,nextspace.X].Piece == "Crate")
     {
         return true;
     }
     return false;
 }