-
Notifications
You must be signed in to change notification settings - Fork 152
Development #116
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?
Development #116
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "dotnet.preferCSharpExtension": true | ||
| } |
| 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(); | ||
| } | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } | ||
| } | ||
|
|
| 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) { } | ||
| } | ||
| } | ||
| } | ||
|
|
| 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
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. Great use of encapsulation here to get and set the values of the player.
Comment on lines
6
to
+10
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. 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; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
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.
Good use of OOP to further abstract the location of the rooms