Note that there are some explanatory texts on larger screens.

plurals
  1. POGame Program is skipping
    text
    copied!<p>Am trying to run a game I've made of 5 classes, but the most important part isn't running. keep in mind that am still a beginner in c#. All the 5 classes are separate but I only typed the namespaces in the first class here as to avoid confusion, they are there in each class. The program runs but when it reaches the Battle class it skips the BattleLoop completely and asks if i want to play again...Please help me.</p> <p>First class (my entry point):</p> <pre><code>class Program { static void Main(string[] args) { MainGame maingame = new MainGame(); } } </code></pre> <p>Second Class:</p> <pre><code>class MainGame { Hero myhero; Battle battle; string answer; public MainGame() { myhero = new Hero(); Hero.Initialize(myhero); BasicGameLoop(); } void BasicGameLoop() { do { Monster monster = new Monster(); battle = new Battle(myhero, monster); Console.WriteLine("Do you want to Play again??"); answer= Console.ReadLine(); } while(answer == "Y" || answer == "y"); } } </code></pre> <p>Third class:</p> <pre><code>class Battle { string choice; Random rand; int healing, fleechance, hitchance; public Battle(Hero hero, Monster monster) { Console.WriteLine("{0} is facing a {1}.", hero.Identifier, monster.Identifier); } public void BattleLoop(Hero hero, Monster monster) { do { rand = new Random(); DisplayChoices(); choice = Console.ReadLine(); hitchance = rand.Next(0, 100); switch (choice) { case "a": case "A"://this way a or A work hitchance = rand.Next(0, 100); if (hitchance &gt; 30) { hero.AttackDamage = GetHeroDamage(hero); Console.WriteLine("{0} Attacks!", hero.Identifier); hero.AttackDamage -= monster.Defense; Console.WriteLine("The Monster Loses {0}hp", hero.AttackDamage); } else { Console.WriteLine("{0} Missed!", hero.Identifier); } break; case "d": case "D": Console.WriteLine("{0} Defends", hero.Identifier); break; case "h": case "H": healing = 400; hero.CurrentHealth += healing; Console.WriteLine("{0} uses a Potion!", hero.Identifier); Console.WriteLine("{0} heals himself for {1} Points",hero.Identifier,healing); break; case "f": case "F": fleechance = rand.Next(0, 100); if (fleechance &gt; 40) { Console.WriteLine("{0} fled!",hero.Identifier); Console.ReadLine(); Environment.Exit(0); } else { Console.WriteLine("Fleeing Failed"); Console.ReadLine(); } break; default: Console.WriteLine("Sorry that choice was invalid and the monster took a cheap shot!"); break; } Console.WriteLine(); if (monster.isAlive == true) { hitchance = rand.Next(0, 100); if (hitchance &gt; 30) { monster.Strength = GetMonsterDamage(monster); Console.WriteLine("The Monster Attacks!"); if (choice == "d" || choice == "D") { monster.Strength /= 2; } monster.Strength -= hero.Defense; Console.WriteLine("The Hero loses {0}hp", monster.Strength); } else { Console.WriteLine("The Monster Missed!"); } Console.WriteLine("Press Enter to Continue"); Console.ReadLine(); Console.Clear(); } } while (hero.isAlive == true &amp;&amp; monster.isAlive == true); if (hero.CurrentHealth &gt; 0) { Console.WriteLine("{0} emerged Victorious!", hero.Identifier); } else { Console.WriteLine("{0} has been defeated :(", hero.Identifier); } Console.ReadLine(); } public void PrintStatus(Hero hero, Monster monster) { Console.Write(@" ******************************** HP/MaxHP MP/MaxMP {0}: {1}/{2}hp {3}/{4}mp {5}: {6}/{7}hp {8}/{9}mp ******************************** ", hero.Identifier, hero.CurrentHealth, hero.MaxHealth, hero.CurrentMagic, hero.MaxMagic, monster.Identifier, monster.CurrentHealth, monster.MaxHealth, monster.CurrentMagic, monster.MaxMagic); } string DisplayChoices() { string choice; Console.Write(@" __________________________ Please Choose an action: (A)ttack (D)efend (H)eal (F)lee __________________________"); Console.WriteLine(); choice = Console.ReadLine(); return choice; } public int GetHeroDamage(Hero hero)// 2nd Method to calculate the hero's Damage during battle. { int attackdamage; attackdamage = hero.AttackDamage; return attackdamage; } int GetMonsterDamage(Monster monster) // 3rd Method to calculate the monster's damage during the battle. { int attackdamage; attackdamage = monster.Strength; return attackdamage; } } </code></pre> <p>Fourth class"</p> <pre><code>class Hero { public int CurrentHealth, MaxHealth, CurrentMagic; public int MaxMagic, Strength, Defense, Agility; public int Experience, Gold, AttackDamage; public string Identifier; public bool isAlive; public Hero() { } public static void Initialize(Hero hero) { hero.CurrentHealth = 18; hero.MaxHealth = 18; hero.CurrentMagic = 8; hero.MaxMagic = 8; hero.Strength = 10; hero.Defense = 3; hero.Agility = 6; hero.Experience = 0; hero.Gold = 0; Console.WriteLine("What is your Hero's name?"); hero.Identifier = Console.ReadLine(); hero.isAlive = true; hero.AttackDamage = hero.Strength; } } </code></pre> <p>Fifth class:</p> <pre><code>class Monster { public int CurrentHealth, MaxHealth, CurrentMagic; public int MaxMagic, Strength, Defense, Agility; public int Experience, Gold, AttackDamage; public string Identifier; public bool isAlive; public Monster() { CurrentHealth = 8; MaxHealth = 8; CurrentMagic = 0; MaxMagic = 0; Strength = 5; Defense = 3; Agility = 4; Experience = 5; Gold = 2; Identifier = "Monster"; isAlive = true; AttackDamage = Strength; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload