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
43 changes: 42 additions & 1 deletion Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ internal class Game

public Game()
{
// Initialize the game with one room and one player

player = new Player(name);
currentRoom = new Room("A dark dungeon room with a rusty key on the floor.", "Rusty Key"); // put rusty key in the room
// Initialize the game with one room and one player

}
public void Start()
Expand All @@ -20,7 +23,45 @@ public void Start()
while (playing)
{
// Code your playing logic here
Console.Write("Enter your player name: ");
string name = Console.ReadLine();

Console.WriteLine($"Welcome, {player.GetName()}! You find yourself in a dungeon.");// add message at the start of the game that says welcome player
Play();
}
}
private void Play()
{
bool playing = true;
while (playing)
{
Console.WriteLine("\nChoose an action: 1. Look around 2. Pick up item 3. Check status 4. Exit"); // Add a menu for the player
string choice = Console.ReadLine();

switch (choice)
{
case "1":
Console.WriteLine(currentRoom.GetDescription());
break;
case "2":
if (player.PickUpItem(currentRoom.GetItem()))
{
currentRoom.RemoveItem();
}
break;
case "3":
player.DisplayStatus();
break;
case "4":
playing = false;
Console.WriteLine("Thanks for playing!"); // add messsage at the end of thr game that says thanks for playing
break;
default:
Console.WriteLine("Invalid choice. Try again.");
break;
}
}

}
}
}
36 changes: 27 additions & 9 deletions Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,40 @@ 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 name;
private int health;
private string inventoryItem;

public Player(string name, int health)
public Player(string name)
{
Name = name;
Health = health;
this.name = name;
this.health = 100;
this.inventoryItem = "None";
}
public void PickUpItem(string item)

public string GetName()
{
return name;
}

public bool PickUpItem(string item)
{
if (inventoryItem == "None")
{
inventoryItem = item;
Console.WriteLine($"You picked up: {item}");// You picked up: {item} pop up message
return true;
}
else
{
Console.WriteLine("You can only carry one item!"); // You can only carry one item pop up message
return false;
}
}
public string InventoryContents()

public void DisplayStatus()
{
return string.Join(", ", inventory);
Console.WriteLine($"Player: {name}\nHealth: {health}\nInventory: {inventoryItem}");
}
}
}
3 changes: 1 addition & 2 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# DungeonExplorer
# DungeonExplorer
ID 28881128
15 changes: 13 additions & 2 deletions Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
public class Room
{
private string description;
private string item;

public Room(string description)
public Room(string description, string item)
{
this.description = description;
this.item = item;
}

public string GetDescription()
{
return description;
return description;
}
public string GetItem()
{
return item;
}

public void RemoveItem()
{
item = "None";
}
}
}
44 changes: 44 additions & 0 deletions gamemap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

// Controls the navigation between rooms
public class GameMap
{
public Room CurrentRoom { get; private set; }

// the game map with connected rooms and contents
public void Initialize()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method sets up the initial game environment
room creation
room connections (neighbors)
placing items and monsters
starting point

{
var room1 = new Room { Description = "You are in a dark cave." };
var room2 = new Room { Description = "You have entered a narrow corridor." };
var room3 = new Room { Description = "You stand in a treasure chamber." };

room1.Neighbors["east"] = room2;
room2.Neighbors["west"] = room1;
room2.Neighbors["north"] = room3;
room3.Neighbors["south"] = room2;

// Add items and monsters to rooms
room1.Items.Add(new Weapon("Rusty Sword", 10));
room3.Items.Add(new Potion("Health Potion", 20));

room2.Monsters.Add(new Monster("Goblin", 30, 5));
room3.Monsters.Add(new Monster("Dragon", 100, 25));

// Set initial room
CurrentRoom = room1;
}

// Move to the neighboring room based on direction
public void Move(string direction)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method allows the player to navigate between rooms
if the direction the player is going is valid it updates "currentroom" to the new room
if the direction the player is going isnt valid it will print a message saying "you cant go that way" as stated in code

{
if (CurrentRoom.Neighbors.ContainsKey(direction))
{
CurrentRoom = CurrentRoom.Neighbors[direction];
Console.WriteLine(CurrentRoom.Description);
}
else
{
Console.WriteLine("You can't go that way.");
}
}
}
31 changes: 31 additions & 0 deletions interface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Interface for anything that can take damage
public interface IDamageable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this interface is used for any object that can take damage - players and monsters

{
void TakeDamage(int amount);
}

// Interface for items that can be collected and used by the player
public interface ICollectible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this interface is for items that can be collected as well as used by the player - such as weapons and potions

{
void Use(Player player);
}

// File: Creature.cs

// Abstract base class for all creatures in the game
public abstract class Creature : IDamageable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base class for all living characters in the game (e.g. Player, Monster).
includes shared properties : name - the creatures name, health - their current health, IsAlive - a quick way to check if their health is above 0

{
public string Name { get; set; }
public int Health { get; set; }
public bool IsAlive => Health > 0;

// Basic implementation of taking damage
public virtual void TakeDamage(int amount)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation of how creature loses health

{
Health -= amount;
if (Health < 0) Health = 0;
}

// Abstract attack method to be implemented by subclasses
public abstract void Attack(Creature target);
}
50 changes: 50 additions & 0 deletions inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;

// Manages player's items
public class Inventory
{
private List<Item> items = new List<Item>();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stores all the Item objects the player picks up for example weapons and potions


// Add item to inventory
public void AddItem(Item item)
{
items.Add(item);
Console.WriteLine($"Added {item.Name} to inventory.");
}

// Use item by name; checks if item exists before using
public void UseItem(string name, Player player)
{
var item = items.FirstOrDefault(i => i.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (item != null)
{
item.Use(player);
items.Remove(item);
}
else
{
Console.WriteLine($"Item {name} not found in inventory.");
}
}

// Return list of all items
public IEnumerable<Item> GetItems() => items;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns all items currently in the inventory.


// Display all items in the inventory
public void DisplayItems()
{
if (!items.Any())
{
Console.WriteLine("Inventory is empty.");
return;
}

Console.WriteLine("Inventory:");
foreach (var item in items)
{
Console.WriteLine($"- {item.Name}");
}
}
}
13 changes: 13 additions & 0 deletions item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Abstract base class for all items
public abstract class Item : ICollectible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declares an abstract class, so it cannot be instantiated directly.

{
public string Name { get; set; }

protected Item(string name)
{
Name = name;
}

// Abstract use method to be implemented by specific item types
public abstract void Use(Player player);
}
21 changes: 21 additions & 0 deletions monster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

// Monster class inherits from Creature and represents enemies
public class Monster : Creature

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declares a public class named Monster.
inherits from the abstract base class Creature, meaning it must implement the Attack() method and inherits properties like "Name", "Health", and "IsAlive".

{
public int Damage { get; set; }

public Monster(string name, int health, int damage)
{
Name = name;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the constructor, used when creating a new monster. It sets the monster's name, starting health, and how much damage it deals.

Health = health;
Damage = damage;
}

// Monster attack logic
public override void Attack(Creature target)
{
Console.WriteLine($"{Name} attacks {target.Name} for {Damage} damage.");
target.TakeDamage(Damage);
}
}
43 changes: 43 additions & 0 deletions player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEngine;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADDED BY MISTAKE WAS TESTING CODE IN VS AND FORGOT TO TAKE OUT
(FOR UNITY NOT OOP)


public class DoorController : MonoBehaviour
{
public float openAngle = 90f; // The angle the door opens to
public float closeAngle = 0f; // The angle when the door is closed
public float openSpeed = 2f; // Speed of door rotation
private bool isOpen = false; // Track door state
private bool playerNearby = false; // Check if player is near

void Update()
{
// Check if player is near and presses "E"
if (playerNearby && Input.GetKeyDown(KeyCode.E))
{
isOpen = !isOpen; // Toggle door state
}

// Rotate the door smoothly
float targetAngle = isOpen ? openAngle : closeAngle;
Quaternion targetRotation = Quaternion.Euler(0, targetAngle, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * openSpeed);
}

// Detect if the player enters the interaction area
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player")) // Make sure player has the "Player" tag
{
playerNearby = true;
Debug.Log("Press 'E' to Open/Close the Door.");
}
}

// Detect if the player leaves the interaction area
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
playerNearby = false;
}
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADDED BY MISTAKE WAS TESTING CODE IN VS AND FORGOT TO TAKE OUT
(FOR UNITY NOT OOP)

17 changes: 17 additions & 0 deletions potion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Potion class inherits from Item and represents healing items
public class Potion : Item
{
public int HealAmount { get; set; }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stores how much health this potion will restore when used. This can be customised per potion for example a “Small Potion” might heal 10, while a “Greater Potion” heals 50.


public Potion(string name, int healAmount) : base(name)
{
HealAmount = healAmount;
}

// Use potion to heal player
public override void Use(Player player)
{
player.Health += HealAmount;
Console.WriteLine($"{player.Name} uses {Name} and heals for {HealAmount}. Health is now {player.Health}.");
}
}
Loading