Advertisement
daixso

Room Handler

May 27th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TextRPG
  8. {
  9.     class Rooms
  10.     {
  11.         // Room ID, Name, Description, Allowed Directions
  12.         private static string[,] roomList = new string[,]
  13.         {
  14.             {"0", "Slaughtered Hog", "A warm taven full of boisterous patrons.", "N S E W"},
  15.             {"1", "Royal Castle", "A large magnificent castle with intricate statues of former kings and queens.", "W"},
  16.             {"2", "Village Farm", "A farm for the village and castle.\nIn the distance you can see animals roaming the fields.", "N"},
  17.             {"3", "Palace Park", "A huge park with fountains and statues depicting\nthe many feats of the castles knights and rulers.", "E"},
  18.             {"4", "Mages Tower", "An impossibly large tower that seems to touch the clouds.\nYou feel dizzy trying to look up to the top.", "N S E"},
  19.             {"5", "River", "A massive river that feeds the towns water supply.\nIt is also known for having large fish.", "S"},
  20.             {"6", "Mystic Garden", "A beautiful garden with plants you have never seen.\nThe mages use this garden for research and potion supplies.", "W"}
  21.         };
  22.  
  23.         //Current Room ID, Room to North, Room to South, Room to East, Room to West
  24.         private static string[,] movementList = new string[,]
  25.         {
  26.             {"0", "4", "2", "1", "3"},
  27.             {"1", null, null, null, "0"},
  28.             {"2", "0", null, null, null},
  29.             {"3", null, null, "0", null},
  30.             {"4", "5", "0", "6", null},
  31.             {"5", null, "4", null, null},
  32.             {"6", null, null, null, "4"}
  33.         };
  34.  
  35.         private static string roomId = roomList[0, 0]; //Room ID
  36.         private static string roomName = roomList[0, 1]; //Room Name
  37.         private static string roomDesc = roomList[0, 2]; //Room Description
  38.         private static string roomDirections = roomList[0, 3]; //Room allowed directions
  39.  
  40.  
  41.         //loop through rooms until you find the requested ID
  42.         public bool getRoomById(string id)
  43.         {
  44.             for(int i = 0; i < roomList.Length; i++)
  45.             {
  46.                 if(roomList[i, 0] == id)
  47.                 {
  48.                     //if room found get and set room data
  49.                     roomId = roomList[i, 0];
  50.                     roomName = roomList[i, 1];
  51.                     roomDesc = roomList[i, 2];
  52.                     roomDirections = roomList[i, 3];
  53.                     return true;
  54.                 }
  55.             }
  56.             //room not found
  57.             return false;
  58.         }
  59.  
  60.         //return the current room ID
  61.         public string getRoomId()
  62.         {
  63.             return roomId;
  64.         }
  65.  
  66.         //Return true if there is a room north of current location
  67.         private bool canGoNorth()
  68.         {
  69.             if(roomDirections.Contains("N") || roomDirections.Contains("n"))
  70.             {
  71.                 return true;
  72.             }
  73.             return false;
  74.         }
  75.  
  76.         //Return true if there is a room south of current location
  77.         private bool canGoSouth()
  78.         {
  79.             if (roomDirections.Contains("S") || roomDirections.Contains("s"))
  80.             {
  81.                 return true;
  82.             }
  83.             return false;
  84.         }
  85.  
  86.         //Return true if there is a room East of current location
  87.         private bool canGoEast()
  88.         {
  89.             if (roomDirections.Contains("E") || roomDirections.Contains("e"))
  90.             {
  91.                 return true;
  92.             }
  93.             return false;
  94.         }
  95.  
  96.         //Return true if there is a room West of current location
  97.         private bool canGoWest()
  98.         {
  99.             if (roomDirections.Contains("W") || roomDirections.Contains("w"))
  100.             {
  101.                 return true;
  102.             }
  103.             return false;
  104.         }
  105.  
  106.         //create empty string and append allowed directions to create list
  107.         public string allowedDirections()
  108.         {
  109.             string allowed = "";
  110.             if(canGoNorth())
  111.             {
  112.                 allowed += "N";
  113.             }
  114.             if(canGoSouth())
  115.             {
  116.                 allowed += "S";
  117.             }
  118.             if(canGoEast())
  119.             {
  120.                 allowed += "E";
  121.             }
  122.             if(canGoWest())
  123.             {
  124.                 allowed += "W";
  125.             }
  126.             return allowed;
  127.         }
  128.  
  129.         //Verify and handle room changes
  130.         public void movement(string dir)
  131.         {
  132.  
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement