Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TextRPG
- {
- class Rooms
- {
- // Room ID, Name, Description, Allowed Directions
- private static string[,] roomList = new string[,]
- {
- {"0", "Slaughtered Hog", "A warm taven full of boisterous patrons.", "N S E W"},
- {"1", "Royal Castle", "A large magnificent castle with intricate statues of former kings and queens.", "W"},
- {"2", "Village Farm", "A farm for the village and castle.\nIn the distance you can see animals roaming the fields.", "N"},
- {"3", "Palace Park", "A huge park with fountains and statues depicting\nthe many feats of the castles knights and rulers.", "E"},
- {"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"},
- {"5", "River", "A massive river that feeds the towns water supply.\nIt is also known for having large fish.", "S"},
- {"6", "Mystic Garden", "A beautiful garden with plants you have never seen.\nThe mages use this garden for research and potion supplies.", "W"}
- };
- //Current Room ID, Room to North, Room to South, Room to East, Room to West
- private static string[,] movementList = new string[,]
- {
- {"0", "4", "2", "1", "3"},
- {"1", null, null, null, "0"},
- {"2", "0", null, null, null},
- {"3", null, null, "0", null},
- {"4", "5", "0", "6", null},
- {"5", null, "4", null, null},
- {"6", null, null, null, "4"}
- };
- private static string roomId = roomList[0, 0]; //Room ID
- private static string roomName = roomList[0, 1]; //Room Name
- private static string roomDesc = roomList[0, 2]; //Room Description
- private static string roomDirections = roomList[0, 3]; //Room allowed directions
- //loop through rooms until you find the requested ID
- public bool GetRoomById(string id)
- {
- for(int i = 0; i < roomList.Length; i++)
- {
- if(roomList[i, 0] == id)
- {
- //if room found get and set room data
- roomId = roomList[i, 0];
- roomName = roomList[i, 1];
- roomDesc = roomList[i, 2];
- roomDirections = roomList[i, 3];
- return true;
- }
- }
- //room not found
- return false;
- }
- //return the current room ID
- public string GetRoomId()
- {
- return roomId;
- }
- //Return true if there is a room north of current location
- private bool CanGoNorth()
- {
- if(roomDirections.Contains("N") || roomDirections.Contains("n"))
- {
- return true;
- }
- return false;
- }
- //Return true if there is a room south of current location
- private bool CanGoSouth()
- {
- if (roomDirections.Contains("S") || roomDirections.Contains("s"))
- {
- return true;
- }
- return false;
- }
- //Return true if there is a room East of current location
- private bool CanGoEast()
- {
- if (roomDirections.Contains("E") || roomDirections.Contains("e"))
- {
- return true;
- }
- return false;
- }
- //Return true if there is a room West of current location
- private bool CanGoWest()
- {
- if (roomDirections.Contains("W") || roomDirections.Contains("w"))
- {
- return true;
- }
- return false;
- }
- //create empty string and append allowed directions to create list
- public string AllowedDirections()
- {
- string allowed = "";
- if(CanGoNorth())
- {
- allowed += "N";
- }
- if(CanGoSouth())
- {
- allowed += "S";
- }
- if(CanGoEast())
- {
- allowed += "E";
- }
- if(CanGoWest())
- {
- allowed += "W";
- }
- return allowed;
- }
- //Verify and handle room changes
- public void Movement(string dir)
- {
- for(int i = 0; i < movementList.Length - 1; i++)
- {
- if (movementList[i, 0] == roomId)
- {
- foreach(string movement in movementList)
- {
- if(movement == dir)
- {
- switch(dir)
- {
- case "N":
- GetRoomById(movementList[i, 1]);
- break;
- case "S":
- GetRoomById(movementList[i, 2]);
- break;
- case "E":
- GetRoomById(movementList[i, 3]);
- break;
- case "W":
- GetRoomById(movementList[i, 4]);
- break;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement