Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Engine
- {
- public class Game
- {
- public Player player;
- public Game()
- {
- player = new Player(10, 10, 20, 0, 1);
- player.inventory.Add(World.ItemByID(World.ITEM_ID_RUSTY_SWORD));
- MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
- }
- private void moveNorth()
- {
- MoveTo(player.currentLocation.locToNorth);
- }
- private void moveSouth()
- {
- MoveTo(player.currentLocation.locToSouth);
- }
- private void moveWest()
- {
- MoveTo(player.currentLocation.locToWest);
- }
- private void moveEast()
- {
- MoveTo(player.currentLocation.locToEast);
- }
- public void MoveTo(Location newLocation)
- {
- if (newLocation.locationKey != null)
- {
- bool playerHasRequiredItem = false;
- foreach (Item item in player.inventory) //Thorws null reference unhandled
- {
- if (item.id == newLocation.locationKey.id)
- {
- playerHasRequiredItem = true;
- break;
- }
- }
- if (!playerHasRequiredItem)
- {
- Console.WriteLine("You must have {0} to enter this location", newLocation.locationKey.name);
- return;
- }
- }
- player.currentLocation = newLocation;
- GetDesc();
- GetDirections( player.currentLocation);
- }
- public void GetDesc()
- {
- Console.WriteLine(player.currentLocation.description);
- }
- public void GetDirections(Location thisLocation)
- {
- thisLocation = player.currentLocation;
- Console.WriteLine("Directions:");
- if (thisLocation.locToNorth != null)
- {
- Console.WriteLine(" N ");
- }
- if (thisLocation.locToSouth != null)
- {
- Console.WriteLine(" S ");
- }
- if (thisLocation.locToWest != null)
- {
- Console.WriteLine(" W ");
- }
- if (thisLocation.locToEast != null)
- {
- Console.WriteLine(" E ");
- }
- }
- public Dictionary<string, Func<Location>> commands = new Dictionary<string, Func<Location>>(); //trying to pretty up my old commands code which I'll post below
- public void GetCommand()
- {
- commands.Add("move", (Func<Location>)MoveTo(player.newLocation));
- }
- /* public void Commands()
- {
- List<string> command = new List<string>();
- command.AddRange(Console.ReadLine().Split(' '));
- Console.WriteLine("\n");
- if (command.Count == 0)
- {
- Console.WriteLine("Please enter a valid command");
- }
- if (command.Count >= 1)
- {
- switch (command[0])
- {
- case "move":
- if (command.Count == 1)
- {
- Console.WriteLine("Command: Move (direction)");
- }
- if (command.Count == 2)
- {
- if (command[1] == "n" && player.currentLocation.locToNorth != null)
- {
- moveNorth();
- command.Clear();
- }
- else if (command[1] == "s" && player.currentLocation.locToSouth != null)
- {
- moveSouth();
- command.Clear();
- }
- else if (command[1] == "w" && player.currentLocation.locToWest != null)
- {
- moveWest();
- command.Clear();
- }
- else if (command[1] == "e" && player.currentLocation.locToEast != null)
- {
- moveEast();
- command.Clear();
- }
- else
- {
- Console.WriteLine("Invalid direction. The valid directions are: ");
- GetDirections(player.currentLocation);
- }
- }
- break;
- case "attack":
- if (command.Count == 1)
- {
- Console.WriteLine("Invalid target");
- }
- else
- {
- Console.WriteLine("You attack.");
- }
- break;
- case "quaff":
- if (command.Count == 1)
- {
- Console.WriteLine("Which potion?");
- }
- else
- {
- Console.WriteLine("You potion.");
- }
- break;
- case "quit":
- {
- Console.WriteLine("You have quit.");
- Environment.Exit(0);
- break;
- }
- case "stats":
- Console.WriteLine("Health {0}/{1} Gold: {2} XP: {3} level: {4}", player.currentHp, player.maxHp, player.gold, player.xp, player.level);
- break;
- case "inventory":
- Console.WriteLine("Player Inventory\n****************");
- foreach (Item item in player.inventory)
- {
- Console.WriteLine(item.name + "\n");
- }
- break;
- case "quests":
- Console.WriteLine("Player Quests\n*************");
- break;
- case "givexp":
- if (command.Count == 1)
- {
- Console.WriteLine("givexp PLAYER XPVALUE");
- }
- else if (command.Count == 2)
- {
- Console.WriteLine("enter a valid xp ammount");
- }
- else
- {
- player.xp = Int32.Parse(command[2]);
- }
- break;
- }
- }
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement