-
Notifications
You must be signed in to change notification settings - Fork 152
assignment 2 commits #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
assignment 2 commits #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| # DungeonExplorer | ||
| # DungeonExplorer | ||
| ID 28881128 |
| 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() | ||
| { | ||
| 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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method allows the player to navigate between rooms |
||
| { | ||
| if (CurrentRoom.Neighbors.ContainsKey(direction)) | ||
| { | ||
| CurrentRoom = CurrentRoom.Neighbors[direction]; | ||
| Console.WriteLine(CurrentRoom.Description); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("You can't go that way."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Interface for anything that can take damage | ||
| public interface IDamageable | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
| { | ||
| 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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| 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>(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"); | ||
| } | ||
| } | ||
| } | ||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declares a public class named Monster. |
||
| { | ||
| public int Damage { get; set; } | ||
|
|
||
| public Monster(string name, int health, int damage) | ||
| { | ||
| Name = name; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using UnityEngine; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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; | ||
| } | ||
| } | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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; } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}."); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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