From 22451706ba4fbc8e7dd7efadc3adfe8163c69929 Mon Sep 17 00:00:00 2001 From: Amelia Williams-Bond Date: Mon, 10 Mar 2025 19:39:53 +0000 Subject: [PATCH 1/3] Adding core functionality to the game --- Game.cs | 43 ++++++++++++++++++++++++++++++++++++++++++- Player.cs | 36 +++++++++++++++++++++++++++--------- Program.cs | 3 +-- Room.cs | 15 +++++++++++++-- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Game.cs b/Game.cs index dacdc422..c47d4052 100644 --- a/Game.cs +++ b/Game.cs @@ -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() @@ -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; + } + } + + } } } \ No newline at end of file diff --git a/Player.cs b/Player.cs index 21cc773f..e77a5c4c 100644 --- a/Player.cs +++ b/Player.cs @@ -4,22 +4,40 @@ namespace DungeonExplorer { public class Player { - public string Name { get; private set; } - public int Health { get; private set; } - private List inventory = new List(); + 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}"); } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 452cda8c..8e501b37 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/Room.cs b/Room.cs index cb092efb..65e0fab8 100644 --- a/Room.cs +++ b/Room.cs @@ -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"; } } } \ No newline at end of file From 7b08088079353d6de245c0d9540a5082bb68c305 Mon Sep 17 00:00:00 2001 From: Amelia Williams-Bond Date: Tue, 11 Mar 2025 17:51:12 +0000 Subject: [PATCH 2/3] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc0e0a4d..a8287592 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# DungeonExplorer \ No newline at end of file +# DungeonExplorer +ID 28881128 From ae25aedea0fc1938dfb0163d15fca7699501cc5d Mon Sep 17 00:00:00 2001 From: Amelia Williams-Bond Date: Tue, 29 Apr 2025 22:44:17 +0100 Subject: [PATCH 3/3] Add files via upload --- gamemap.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ interface.cs | 31 +++++++++++++++++++++++++++++++ inventory.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ item.cs | 13 +++++++++++++ monster.cs | 21 +++++++++++++++++++++ player.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ potion.cs | 17 +++++++++++++++++ room.cs | 17 +++++++++++++++++ weapon.cs | 16 ++++++++++++++++ 9 files changed, 252 insertions(+) create mode 100644 gamemap.cs create mode 100644 interface.cs create mode 100644 inventory.cs create mode 100644 item.cs create mode 100644 monster.cs create mode 100644 player.cs create mode 100644 potion.cs create mode 100644 room.cs create mode 100644 weapon.cs diff --git a/gamemap.cs b/gamemap.cs new file mode 100644 index 00000000..8b8db1f6 --- /dev/null +++ b/gamemap.cs @@ -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() + { + 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) + { + if (CurrentRoom.Neighbors.ContainsKey(direction)) + { + CurrentRoom = CurrentRoom.Neighbors[direction]; + Console.WriteLine(CurrentRoom.Description); + } + else + { + Console.WriteLine("You can't go that way."); + } + } +} \ No newline at end of file diff --git a/interface.cs b/interface.cs new file mode 100644 index 00000000..7ff23caf --- /dev/null +++ b/interface.cs @@ -0,0 +1,31 @@ +// Interface for anything that can take damage +public interface IDamageable +{ + void TakeDamage(int amount); +} + +// Interface for items that can be collected and used by the player +public interface ICollectible +{ + void Use(Player player); +} + +// File: Creature.cs + +// Abstract base class for all creatures in the game +public abstract class Creature : IDamageable +{ + 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) + { + Health -= amount; + if (Health < 0) Health = 0; + } + + // Abstract attack method to be implemented by subclasses + public abstract void Attack(Creature target); +} diff --git a/inventory.cs b/inventory.cs new file mode 100644 index 00000000..c7829a66 --- /dev/null +++ b/inventory.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +// Manages player's items +public class Inventory +{ + private List items = new List(); + + // 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 GetItems() => items; + + // 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}"); + } + } +} \ No newline at end of file diff --git a/item.cs b/item.cs new file mode 100644 index 00000000..62a6edad --- /dev/null +++ b/item.cs @@ -0,0 +1,13 @@ +// Abstract base class for all items +public abstract class Item : ICollectible +{ + 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); +} \ No newline at end of file diff --git a/monster.cs b/monster.cs new file mode 100644 index 00000000..5d9f4927 --- /dev/null +++ b/monster.cs @@ -0,0 +1,21 @@ +using System; + +// Monster class inherits from Creature and represents enemies +public class Monster : Creature +{ + public int Damage { get; set; } + + public Monster(string name, int health, int damage) + { + Name = name; + 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); + } +} \ No newline at end of file diff --git a/player.cs b/player.cs new file mode 100644 index 00000000..05f1c97a --- /dev/null +++ b/player.cs @@ -0,0 +1,43 @@ +using UnityEngine; + +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; + } + } +} diff --git a/potion.cs b/potion.cs new file mode 100644 index 00000000..de3bc3e0 --- /dev/null +++ b/potion.cs @@ -0,0 +1,17 @@ +// Potion class inherits from Item and represents healing items +public class Potion : Item +{ + public int HealAmount { get; set; } + + 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}."); + } +} \ No newline at end of file diff --git a/room.cs b/room.cs new file mode 100644 index 00000000..c9e1fad1 --- /dev/null +++ b/room.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq; + +// Represents a room with items, monsters, and neighboring rooms +public class Room +{ + public string Description { get; set; } + public List Items { get; set; } = new List(); + public List Monsters { get; set; } = new List(); + public Dictionary Neighbors { get; set; } = new Dictionary(); + + // Returns the monster with the highest health + public Monster GetStrongestMonster() + { + return Monsters.OrderByDescending(m => m.Health).FirstOrDefault(); + } +} \ No newline at end of file diff --git a/weapon.cs b/weapon.cs new file mode 100644 index 00000000..c918df74 --- /dev/null +++ b/weapon.cs @@ -0,0 +1,16 @@ +// Weapon class inherits from Item and represents damage-dealing items +public class Weapon : Item +{ + public int Damage { get; set; } + + public Weapon(string name, int damage) : base(name) + { + Damage = damage; + } + + // Equip logic when weapon is used + public override void Use(Player player) + { + Console.WriteLine($"{player.Name} equips {Name}."); + } +} \ No newline at end of file