static void Main(string[] args) { // Weapon[] myArsenal = SetupWeapons(); Weapon[] myArsenal = LoadWeapons("weapons.csv"); bool gameRunning = true; Npc punchingBag = new Npc(); Npc damsel = new Npc(); damsel.friend = true; damsel.name = "Missy"; Npc[] charactersInRoom = new Npc[2]; charactersInRoom[0] = punchingBag; charactersInRoom[1] = damsel; Prompt("Our First Text RPG Thinggy."); handedNess = Ask("Welcome adventurer, are you left or right handed (answer left or right)?\nYou have 5 seconds to answer", 5).ToLower(); Prompt($"So you are {handedNess} handed."); while (gameRunning) { //Ask player for command and convert to lowercase. string command = Ask("What would you like to do ?").ToLower(); switch (command) { case "bag": case "show inv": case "inv": case "inventory": //show inventory foreach (Weapon weap in myArsenal) { //name of weapon Prompt(weap.name); //do other stuff. //Weapon type Prompt(weap.type); //description of weapon Prompt(weap.fluff); //space between each weapon Console.WriteLine(""); } break; case "a": case "att": case "attack": //choose weapon to attack with foreach (Weapon weap in myArsenal) { string attackWith = Ask($"Do you want to attack with {weap.name} ?").ToLower(); if (attackWith[0] == 'y') { bool didAttack = false; foreach (Npc npc in charactersInRoom) { if (!npc.friend && npc.hitpoints > 0) { didAttack = true; weap.Attack(npc); break; } } if (!didAttack) { Prompt("There wasn't any bad guys left alive to attack."); } break; } } break; case "look": Prompt("You are in a room."); if (charactersInRoom.Length > 0) { foreach (Npc npc in charactersInRoom) { Prompt($"You can see that '{npc.name}' is in here with you, and they have {npc.hitpoints} health."); } } break; case "quit": gameRunning = false; break; default: break; } } Prompt($"Thank you for playing."); }
public virtual void Attack(Npc npc) { npc.hitpoints -= damage; Console.WriteLine($"You bludgeon the '{npc.name}' for {damage} point(s) of damage."); npc.HealthCheck(); }