コード例 #1
0
ファイル: GameBoard.cs プロジェクト: michaelnull/week-9-day-3
 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;
 }
コード例 #2
0
ファイル: GameBoard.cs プロジェクト: michaelnull/week-9-day-3
 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;
 }
コード例 #3
0
ファイル: GameBoard.cs プロジェクト: michaelnull/week-9-day-3
 public static bool IsPushingCrate(Location nextspace, Square[,] map)
 {
     if (map[nextspace.Y,nextspace.X].Piece == "Crate")
     {
         return true;
     }
     return false;
 }
コード例 #4
0
ファイル: GameBoard.cs プロジェクト: michaelnull/week-9-day-3
        public Square[,] LoadMap(char[,] map)
        {
            Square[,] board = new Square[map.GetLength(0), map.GetLength(1)];
            for (int i = 0; i < map.GetLength(0); i++)
            {
                for (int j = 0; j < map.GetLength(1); j++)
                {

                    Square square = new Square();
                    board[i, j] = square;
                    switch (map[i, j])
                    {

                        case '.':
                            square.Space = "Storage";
                            square.Piece = "None";
                            break;

                        case 'o':
                            square.Space = "Open";
                            square.Piece = "Crate";
                            break;

                        case '@':
                            square.Space = "Open";
                            square.Piece = "Man";
                            break;

                        case '*':
                            square.Space = "Storage";
                            square.Piece = "Crate";
                            break;

                        case '+':
                            square.Space = "Storage";
                            square.Piece = "Man";
                            break;

                        case '#':
                            square.Space = "Wall";
                            square.Piece = "None";
                            break;

                        default:
                            square.Space = "Open";
                            square.Piece = "None";
                            break;
                    }
                }

            }
            return board;
        }
コード例 #5
0
ファイル: GameBoard.cs プロジェクト: michaelnull/week-9-day-3
        public static Square[,] Move(string direction, Square[,] map)
        {
            Location currentspace = GetCurrentPlayerSpace(map);
                Location nextspace = GetNextSpace(currentspace, direction);
                if (IsValidMove(nextspace, direction, map))
                {
                    if (IsPushingCrate(nextspace, map))
                    {
                        Location nextcratespace = GetNextSpace(nextspace, direction);
                        map[nextcratespace.Y, nextcratespace.X].Piece = "Crate";
                    }
                    map[nextspace.Y, nextspace.X].Piece = "Man";
                    map[currentspace.Y, currentspace.X].Piece = "None";
                }

            return map;
        }
コード例 #6
0
 public void StoreMap(Square[,] map)
 {
     HttpContext.Session["GameBoard"] = map;
 }
コード例 #7
0
 public Square[,] GetMap()
 {
     if (HttpContext.Session["GameBoard"] == null)
     {
         GamePlay Game = new GamePlay();
         Square[,] map = new Square[Level.GetLength(0), Level.GetLength(1)];
         map = Game.LoadMap(Level);
         StoreMap(map);
         return map;
     }
     else
     {
         return (Square[,])HttpContext.Session["GameBoard"];
     }
 }