diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..013007bb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.preferCSharpExtension": true +} \ No newline at end of file diff --git a/Game.cs b/Game.cs index dacdc422..5b8ec5da 100644 --- a/Game.cs +++ b/Game.cs @@ -1,25 +1,44 @@ using System; +using System.Collections.Generic; using System.Media; namespace DungeonExplorer { internal class Game - { - private Player player; - private Room currentRoom; + { + // defining all of the objects to be used in the game class + private Player player;// sets up an instance of "player" for the user + private Room currentRoom;// sets up an instance of "room" for the player to interact with + private Room nextRoom;// sets up the room to move on to + + public Game() { - // Initialize the game with one room and one player - + // setting up the argyuments for the objects + currentRoom = new Room("room 1: entrance", "a torch", 2, 2, 1); + nextRoom = new Room("room 2: passage", "a key", 5, 2, 4); + // sets up an empty list of strings for the player inventory + List playerInventory = new List(); + player = new Player("player", 100, playerInventory); } + public void Start() { - // Change the playing logic into true and populate the while loop - bool playing = false; + bool playing = true; while (playing) { - // Code your playing logic here + //gets the player to input a username + player.setPlayerName(); + //writes the description for the current room + currentRoom.WriteDescription(); + //gives the user an option to pick up an item from the room + player.PickUpItem(currentRoom.RoomItem); + //set next room to current room and run the next room description + currentRoom = nextRoom; + player.PickUpItem(currentRoom.RoomItem); + //sets playing to false to finish the game + playing = false; } } } diff --git a/Player.cs b/Player.cs index 21cc773f..f720f3fc 100644 --- a/Player.cs +++ b/Player.cs @@ -1,25 +1,112 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace DungeonExplorer { public class Player { - public string Name { get; private set; } - public int Health { get; private set; } - private List inventory = new List(); + private string playerName = "player"; // sets a default player name + private int playerHealth; //sets up integer value for health + private List playerInventory = new List(); //sets inventory as list of strings. - public Player(string name, int health) + public Player(string playerName, int playerHealth, List playerInventory) { - Name = name; - Health = health; + //takes the inputs from when the class is called to set up the variables for the class + Name = playerName; + Health = playerHealth; + Inventory = playerInventory; } - public void PickUpItem(string item) + + public string Name + { + //gets and sets player name + //sets as "player" if the value is empty + get { return playerName; } + set { playerName = string.IsNullOrWhiteSpace(value) ? "player" : value; } + } + + public int Health + { + //get and set for health + get { return playerHealth; } + set { playerHealth = value; } + } + + public List Inventory + { + // gets and sets an inventory + // returns a new list if the value is not there + get { return playerInventory; } + set { playerInventory = value ?? new List(); } + } + + + //method for setting the player name + public void setPlayerName() + { + string playerNameInput; // empty string to start + do + { + //asks user to input a name + Console.WriteLine("What name do you wish to play under: "); + playerNameInput = Console.ReadLine(); + } + //loops again if the input is null or empty + while (string.IsNullOrEmpty(playerNameInput)); + + //sets the player as their username + Name = playerNameInput; + Console.WriteLine($"Hello, {Name}! You are starting with {Health} health points"); + + //message displaying inventory (or that it is empty) + if (playerInventory.Count == 0) + { + Console.WriteLine($"Your inventory contains is empty"); + } + else + { + Console.WriteLine($"Your inventory contains: {InventoryContents()}"); + } + } + + //method to give the option to pick up an item and add it to the inventory. + public void PickUpItem(string roomItem) { + string pickUpItem; + do + { + Console.WriteLine($"There is {roomItem} in this room. Do you wish to pick it up? (Y/N): "); + pickUpItem = Console.ReadLine().ToUpper(); + } + while (pickUpItem != "Y" && pickUpItem != "N"); + if (pickUpItem == "Y") + { + //adds item to inventory + playerInventory.Add(roomItem); + //tells user what they have picked up and their current stats. + Console.WriteLine($"Item {roomItem} picked up!"); + Console.WriteLine($"{Name}, your inventory contains: {InventoryContents()}, and your hp is {Health}"); + } + else if (pickUpItem == "N") + { + Console.WriteLine($"{roomItem} not picked up"); + //message displaying inventory (or that it is empty) + if (playerInventory.Count == 0) + { + Console.WriteLine($"{Name}, your inventory contains is empty and your hp is {Health}"); + } + else + { + Console.WriteLine($"{Name}, your inventory contains: {InventoryContents()}, and your hp is {Health}"); + } + } } + + // turns the list of inventory into a string public string InventoryContents() { - return string.Join(", ", inventory); + return string.Join(", ", Inventory); } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 452cda8c..c8d389f0 100644 --- a/Program.cs +++ b/Program.cs @@ -10,11 +10,10 @@ internal class Program { static void Main(string[] args) { - Game game = new Game(); - game.Start(); - Console.WriteLine("Waiting for your Implementation"); - Console.WriteLine("Press any key to exit..."); - Console.ReadKey(); + Game game = new Game(); //calls an object of the game class (where the main program is) + game.Start(); //starts the game using start method + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); // reads key before it closes the program } } } diff --git a/Room.cs b/Room.cs index cb092efb..6829e26c 100644 --- a/Room.cs +++ b/Room.cs @@ -1,17 +1,52 @@ -namespace DungeonExplorer +using System; +using System.Dynamic; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace DungeonExplorer { public class Room { - private string description; + //sets up the parameters for the class + private string roomName; + private string roomItem; + private int roomLength; + private int roomWidth; + private int roomDoors; + + + public Room(string roomName, string roomItem, int roomLength, int roomWidth, int roomDoors) + { + //takes the inputs from when the class is called to set up the variables for the class + this.roomName = roomName; + this.roomItem = roomItem; + this.roomLength = roomLength; + this.roomWidth = roomWidth; + this.roomDoors = roomDoors; + } - public Room(string description) + public string RoomName { - this.description = description; + //gets and sets the name of the room + get { return roomName; } + set { roomName = value; } } - public string GetDescription() + public string RoomItem { - return description; + //gets and sets the name of the item in the room + get { return roomItem; } + set { roomItem = value; } } + + public void WriteDescription() + { + //writes a description of the room including all of the variables passed in + Console.WriteLine( + $"You enter {roomName}. This room goes back {roomLength} metres. \n" + + $"It is {roomWidth} metres wide. The room has {roomDoors} Doors \n"); + } + } } \ No newline at end of file