public bool DoRound(Character player, Character opponent) { //Random Rand = new Random(); int playerRoundStrength = player.Strength + Rand.Next(1, 6) - 4; // lowering strength by 4 to deal less damage and getting more rounds. int opponentRoundStrength = opponent.Strength + Rand.Next(1, 6) - 4; string actionString = ""; if (playerRoundStrength > opponentRoundStrength) { opponent.RoundHealth -= playerRoundStrength / 2; // Player does damage to opponent actionString = "You attack " + opponent.Name + " dealing " + playerRoundStrength / 2 + " damage lowering his health to " + ((opponent.RoundHealth >= 0) ? opponent.RoundHealth : 0) + "."; } else if (playerRoundStrength < opponentRoundStrength) { player.RoundHealth -= opponentRoundStrength / 2; // opponent does damage to player actionString = opponent.Name + " attacks you dealing " + opponentRoundStrength / 2 + " damage lowering your health to " + ((player.RoundHealth >= 0) ? player.RoundHealth : 0) + "."; } else // stand off. no damage done by either { actionString = "No attack was made. Unpleasant insults were made instead."; } player.AppendLogAndPrint(actionString); if (player.RoundHealth > 0 && opponent.RoundHealth > 0) { return(true); // both still alive and kicking? then return true and continue fighting } else { return(false); // someone died and fight is over. return false to stop. } }
public bool DoBattle(Character c) { string input = ""; Console.WriteLine("Press enter to start a new battle or x to exit: "); input = Console.ReadLine(); if (input.ToLower().Equals("x")) { c.AppendLogAndPrint("Player is feeling old and grumpy. Retirement it is! "); return(false); } Character o = new Character(); o.generateOpponent(); c.RoundHealth = c.Health; o.RoundHealth = o.Health; Console.WriteLine(c.Name + " vs " + o.Name + ". You who are about to die, we salute you!\nPress enter to fight!"); Console.ReadLine(); while (BattleContinues) { Round r = new Round(); RoundCounter++; Console.WriteLine("Round " + RoundCounter + ": "); BattleContinues = r.DoRound(c, o); } if (c.RoundHealth > 0) { return(true); // if player survived the battle he can contionue playing } else { c.AppendLogAndPrint("Oh no! You were killed by " + o.Name + "!"); return(false); // return false if player is dead } }