[C#] Help declaring enemy object and keeping proper tack of it’s enemyObject.HP without it resetting every time we restart the game loop.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RPG { class Program { static void Main(string[] args) { bool pTurn = true; bool eTurn = false; bool tutorial = true; while (tutorial == true) { Console.WriteLine("Welcome to the tutorial. You will face a basic enemy named Kobold in this room."); Player myPlayer = new Player(); setUpCharacters(); Player kobold = new Player("Kobold", 500, 100); PTURN: while (pTurn) { string choice = ""; string options = "\nFight - Run\n"; Console.WriteLine(options); choice = Console.ReadLine(); if (choice == "Fight") { kobold.HP = kobold.HP - myPlayer.Attack; displayCharacter(kobold); } pTurn = false; eTurn = true; //goto ETURN; } ETURN: while (eTurn) { pTurn = true; eTurn = false; goto PTURN; } } } static string createCharacter() { string classChoice; Console.WriteLine("Do you walk the Path of The Mage (1), or the Path of The Warrior (2)?\n"); classChoice = Console.ReadLine(); if (classChoice == "1") return classChoice; else return "1"; }//SELECTING CHARACTER CLASS (MAGE OR WARRIOR) static void displayCharacter(Player player) { Console.WriteLine("\n{0} - {1} - {2}", player.Name, player.HP, player.Attack); }//TESTING CLASS TO CHECK FOR CORRECT INPUTS static void setUpCharacters() { Console.WriteLine("To create a character, press Enter"); Console.ReadLine(); if (createCharacter() == "1") //NEW PLAYER OBJECT BASED ON createClass() RETURN { string playerName = ""; Console.WriteLine("\nWhat is your name?\n"); playerName = Console.ReadLine(); Player myPlayer = new Player(playerName, 100, 500); displayCharacter(myPlayer); } }//CREATE ENEMY CHARACTER OBJECTS static void generateEnemy() { Player kobold = new Player(); } //END OF METHODS } //CREATING A BASIC CHARACTER CLASS class Player { public string Name { get; set; } public int HP { get; set; } public int Attack { get; set; } public Player(string name, int hp, int attack) { Name = name; HP = hp; Attack = attack; } public Player() { } } 

}

This code is SUPER unfinished. It will let you create a Chacter (Mage only right now), but when we enter tthe game loop and attack the kobold, his health always resets to 500 when we displayCharacter().

If you need any clarification on the code, just ask!

Thanks so much!

by Risen_from_ash via /r/csharp

Leave a Reply