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
}
87 changes: 87 additions & 0 deletions Battle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;

namespace DungeonExplorer
{
public static class Battle // When enounter is called he battle is initiated
{
private static Random rng = new Random();

public static void Start(Player player, Orc orc)
{
Console.WriteLine($"\nA wild {orc.Name} appears! Prepare for battle!\n");

while (player.Health > 0 && orc.Health > 0)
{
Console.WriteLine("Your Turn:");
Console.WriteLine("1. Attack");
Console.WriteLine("2. Block");
Console.Write("Choose your action: ");
string input = Console.ReadLine();
int playerDamage = player.GetAttackDamage();

bool playerBlocked = false;

switch (input)
{
case "1":
if (rng.NextDouble() < 0.1) // Creates a potential for YOU to miss an attack
{
Console.WriteLine("You missed your attack!");
}
else
{
if (rng.NextDouble() < 0.2) // Creates a potential that the orc blocks your attack
{
Console.WriteLine($"{orc.Name} blocked your attack!");
}
else
{
orc.Health -= playerDamage; // Player Deals Damage to Orc
Console.WriteLine($"You hit the {orc.Name} for {playerDamage} damage.\n");
}
}
break;
case "2":
playerBlocked = true;
Console.WriteLine("You brace yourself and prepare to block the next attack.\n");
break;
default:
Console.WriteLine("Invalid input. You lost your turn.");
break;
}

if (orc.Health <= 0) break;

Console.WriteLine("Enemy Turn:");
if (rng.NextDouble() < 0.1) // Creates A Potential For The Orc To Miss An Attack
{
Console.WriteLine($"{orc.Name} missed their attack!\n");
}
else
{
int damage = orc.Damage;
if (playerBlocked)
{
damage /= 2;
Console.WriteLine($"You partially blocked the attack! You receive {damage} damage.");
}
else
{
Console.WriteLine($"{orc.Name} hits you for {damage} damage.");
}
player.Health -= damage;
}

Console.WriteLine($"\nPlayer Health: {player.Health}");
Console.WriteLine($"{orc.Name} Health: {orc.Health}\n");
}

if (player.Health > 0)
Console.WriteLine($"You defeated the {orc.Name}!");
else
Console.WriteLine("You were defeated. Game Over.");

Console.WriteLine();
}
}
}
Binary file added CMP1903M_2425_A01_Report (1).docx
Binary file not shown.
10 changes: 9 additions & 1 deletion DungeonExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Battle.cs" />
<Compile Include="Game.cs" />
<Compile Include="Orcs.cs" />
<Compile Include="Player.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Room.cs" />
<Compile Include="RoomBase.cs" />
<Compile Include="RoomOne.cs" />
<Compile Include="Location.cs" />
<Compile Include="RoomFour.cs" />
<Compile Include="RoomFive.cs" />
<Compile Include="RoomThree.cs" />
<Compile Include="RoomTwo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
79 changes: 70 additions & 9 deletions Game.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,86 @@
using System;
using System.Media;
using System.Runtime.InteropServices;

namespace DungeonExplorer
{
internal class Game
public class Game
{
private Player player;
private Room currentRoom;
private RoomOne roomOne;
private RoomTwo roomTwo;
private RoomThree roomThree;
private RoomFour roomFour;
private RoomFive roomFive;

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

Console.Write("Enter your name: ");
string playerName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(playerName))
{
Console.WriteLine("Name cannot be empty. Using default name 'Steve'.");
playerName = "Steve";
}
player = new Player(playerName, 100);
roomOne = new RoomOne("\n You Slowly Push The Dungeon Doors Open Stumbling Down The Rocky Cavern, The Torch Lit Halls Flicker With Light\n "
+ " You Reach A Wooden Door Which Swings Open To The Orcs Armoury - Bloodstained Weapons Are Hung on the wall but they still flicker with light \n"
+ "You peer around the corner two old armour stands are idle in the room the armour looking new and polished untouched by war \n" +
"... You delve into the room to see whats around ..."); ;
roomTwo = new RoomTwo("\n You Pull Open A Door Handle, Its Rusted Iron Handle Chips In Your Hand It Opens Revealing A Cafeteria With An Orc Finishing Off His Meal \n");
roomThree = new RoomThree("\n You Hear Metal Clanging Through The Door You Rush Through Clutching Your Sword To See What Thw Noise Is -"
+"\n An Orc Drops His Tools And Grabs The Strong Sword He Has Just Finished Tempering \n");
roomFour = new RoomFour("The Blacksmiths Go Silent As The Flames Burn Out, A Chime Comes From A Door With A Cross On\n"+
"You Tap The Door With Your New Sword As It Swings Open Revealing the Orcs Church");
roomFive = new RoomFive("The Guard Topples Over Making A Horriffic Screach - You Hear A Massive Pound Come From The Double Doors Off to the Side \n"+
"You Jam The Key You Found In the Armoury Into The Lock And With A Hard Twist The Doors Swing Open Revealing The King And His Throne");
}

public void Start()
{
// Change the playing logic into true and populate the while loop
bool playing = false;
while (playing)
Console.WriteLine("\n--- Room One: The Armory ---\n");
Console.WriteLine(roomOne.GetDescription() + "\n");

while (roomOne.HasRemainingItems())
{
Console.WriteLine("Choose a location to search:");
roomOne.ShowLocations();
int choice = GetUserChoice(1, roomOne.Locations.Count);
var item = roomOne.PickUpItemFromLocation(choice - 1);
if (item != null)
{
player.PickUpItem(item);
}
Console.WriteLine("\n" + player.GetStatus() + "\n");
}
Console.WriteLine("You collected all items in Room One.\n");

Console.WriteLine("\n--- Room Two: Cafeteria ---\n");
roomTwo.Enter(player);
if (player.Health <= 0) return;

Console.WriteLine("\n--- Room Three: Blacksmith's Forge ---\n");
roomThree.Enter(player);
if (player.Health <= 0) return;

Console.WriteLine("\n--- Room Four: The Church ---\n");
roomFour.Enter(player);
if (player.Health <= 0) return;

Console.WriteLine("\n--- Room Five: Throne Room ---\n");
roomFive.Enter(player);
}

private int GetUserChoice(int min, int max)
{
while (true)
{
// Code your playing logic here
Console.Write("Option: ");
string input = Console.ReadLine();
if (int.TryParse(input, out int opt) && opt >= min && opt <= max)
{
return opt;
}
Console.WriteLine($"Please enter a number between {min} and {max}.");
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions Location.cs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of OOP to further abstract the location of the rooms

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace DungeonExplorer
{
public class Location
{
public string Name { get; private set; }
public string Description { get; private set; }
public string Item { get; private set; }

public Location(string name, string description, string item) //Class For Creating POIs in Rooms
{
Name = name;
Description = description;
Item = item;
}

public string PickUpItem() // Allows the player to pick up items
{
string foundItem = Item;
Item = null;
return foundItem;
}
}
}

43 changes: 43 additions & 0 deletions Orcs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using DungeonExplorer;

namespace DungeonExplorer
{
public class Orc // Enemy Class
{
public string Name { get; private set; }
public int Health { get; set; }
public int Damage { get; private set; }

public Orc(string name, int health, int damage)
{
Name = name;
Health = health;
Damage = damage;
}



// Specifying Which Orcs Can Spawn In
public class OrcGrunt : Orc
{
public OrcGrunt() : base("Orc Grunt", 20, 5) { }
}

public class OrcSoldier : Orc
{
public OrcSoldier() : base("Orc Soldier", 70, 15) { }
}

public class OrcWarlord : Orc
{
public OrcWarlord() : base("Orc Warlord", 100, 20) { }
}

public class OrcKing : Orc
{
public OrcKing() : base("Orc King", 150, 25) { }
}
}
}

62 changes: 52 additions & 10 deletions Player.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,67 @@
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 name;
private int health;
private List<string> inventory;
Comment on lines 6 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great use of encapsulation here to get and set the values of the player.

Comment on lines 6 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your naming conventions here are a little inconsistent in some of your classes, maybe try PascalCase for public members, and lowercase for private.


public Player(string name, int health)
public Player(string name, int health)
{
Name = name;
Health = health;
this.name = name;
this.Health = health;
inventory = new List<string>();
}

public string Name { get { return name; } }

public int Health
{
get { return health; }
set { health = value < 0 ? 0 : value; }
}

public void PickUpItem(string item)
{
inventory.Add(item);
Console.WriteLine($"{name} picked up {item}.");

// Picking up armour increases health
if (item == "Helmet")
{
Health += 25;
Console.WriteLine("The Orc's Helmet Fits Your Head Perfectly - Your Health Increased by 25!");
}
if (item == "Chestplate")
{
Health += 50;
Console.WriteLine("Its A Squeeze To Get Into However ... It fits - Your Health Increased by 50");

}

if (item == "Health Potion")
{
int healAmount = 75; // Heal amount for health potion
Health += healAmount;
Console.WriteLine($"You Gulp Down The Healing Potion - It Tastes Horrible But Your Wounds Heal - Your health restored by 75");
}
}
public string InventoryContents()

public string GetStatus()
{
string invStatus = (inventory.Count > 0) ? string.Join(", ", inventory) : "No items";
return $"Player: {name}\nHealth: {health}\nInventory: {invStatus}";
}

public int GetAttackDamage()
{
return string.Join(", ", inventory);
int damage = 10; // Default damage
if (inventory.Contains("Strong Sword"))
damage += 15; // Additional damage from Strong Sword
return damage;
}
}
}
}
17 changes: 0 additions & 17 deletions Room.cs

This file was deleted.

Loading