Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.preferCSharpExtension": true
}
35 changes: 27 additions & 8 deletions Game.cs
Original file line number Diff line number Diff line change
@@ -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<string> playerInventory = new List<string>();
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;
}
}
}
Expand Down
105 changes: 96 additions & 9 deletions Player.cs
Original file line number Diff line number Diff line change
@@ -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<string> inventory = new List<string>();
private string playerName = "player"; // sets a default player name
private int playerHealth; //sets up integer value for health
private List<string> playerInventory = new List<string>(); //sets inventory as list of strings.

public Player(string name, int health)
public Player(string playerName, int playerHealth, List<string> 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<string> Inventory
{
// gets and sets an inventory
// returns a new list if the value is not there
get { return playerInventory; }
set { playerInventory = value ?? new List<string>(); }
}


//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);
}
}
}
9 changes: 4 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
47 changes: 41 additions & 6 deletions Room.cs
Original file line number Diff line number Diff line change
@@ -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");
}

}
}