public void FightABattle(Gladiator playersGladiator) { Gladiator opposingGladiator = new Gladiator(); //create a new gladiator playersGladiator.SlainOpponents.Add(opposingGladiator.GladiatorName); //store the name of opposing gladiator so a message can be printed of eventual wins or losses. Round round = new Round(); do { round.FightARound(playersGladiator, opposingGladiator); if (playersGladiator.CurrentWounds <= 0) //if the players gladiator dies you get a message of the lost fight { Console.WriteLine($"Oh No!! You lost to {opposingGladiator.GladiatorName}!!"); playersGladiator.IsPlayerGladdiatorDead = "y"; Console.ReadLine(); } else if (opposingGladiator.CurrentWounds <= 0) //if the generated gladiator dies you get a message of your win { Console.WriteLine($"You won against {opposingGladiator.GladiatorName}!! Congratulations!!"); playersGladiator.NumberOfVictories++; playersGladiator.CurrentWounds = playersGladiator.StartingWounds;//the players hitpoints is restored opposingGladiator.IsPlayerGladdiatorDead = "y"; Console.ReadLine(); } } while (playersGladiator.IsPlayerGladdiatorDead == "n" && opposingGladiator.IsPlayerGladdiatorDead == "n"); }
public void FightARound(Gladiator playersGladiator, Gladiator opposingGladiator) { do { //print to console the characteristics of the two fighters Console.WriteLine($"\nBattle {playersGladiator.BattleNumber} Battleturn {RoundNumber}:"); Console.WriteLine($"Your gladiator {playersGladiator.GladiatorName} \nweaponskill of {playersGladiator.Weaponskill}\nstrenght of {playersGladiator.Strenght}\ntoughness of {playersGladiator.Toughness}\nwounds equal to {playersGladiator.CurrentWounds}\nNumber of victories {playersGladiator.NumberOfVictories} victories."); Console.WriteLine($"\nOpposing gladiator is {opposingGladiator.GladiatorName}\nweaponskill of {opposingGladiator.Weaponskill}\nstrenght of {opposingGladiator.Strenght}\ntoughness of {opposingGladiator.Toughness}\nwounds equal to {opposingGladiator.CurrentWounds}.\n"); opposingGladiator.CurrentWounds = CombatResult(playersGladiator, opposingGladiator); playersGladiator.CurrentWounds = CombatResult(opposingGladiator, playersGladiator); RoundNumber++; Console.ReadKey(); } while ((playersGladiator.CurrentWounds > 0) && (opposingGladiator.CurrentWounds > 0)); }
/// <summary> /// Function that resolves a round of combat. /// </summary> /// <param name="aggressor is the fighter who tries to strike"></param> /// <param name="defender is the fighter that recives eventual damage"></param> /// <returns>The returning value is number of wounds the defender recives.</returns> private int CombatResult(Gladiator aggressor, Gladiator defender) { int hitRoll = RollADie(); // a random number is generated if (hitRoll <= aggressor.Weaponskill) //if generated number is less or equal to the agressors weaponskill damage is dealt { int causedWoundsToDefender = 0, damageToDefender; Console.WriteLine($"{aggressor.GladiatorName} strikes {defender.GladiatorName} as {hitRoll} is less or equal to {aggressor.GladiatorName}s weaponskill of {aggressor.Weaponskill}."); damageToDefender = aggressor.Strenght + RollADie(); //agressors damage is determined Console.WriteLine($"{aggressor.GladiatorName} does {damageToDefender} damage to {defender.GladiatorName}"); if ((causedWoundsToDefender = damageToDefender - defender.Toughness) < 0) //if aggressors damage is not enough to go throu defenders toughness no damage is done. { Console.WriteLine($"{aggressor.GladiatorName} did not do enough damage as {defender.GladiatorName} toughness of {defender.Toughness} was greater than the inflicted damage."); return(defender.CurrentWounds); } else //if Aggressors damage is greater than defenders toughness damage is done. { Console.WriteLine($"{defender.GladiatorName} have {defender.Toughness} in toughness and reduce number of wounds taken to {causedWoundsToDefender}."); if ((defender.CurrentWounds <= causedWoundsToDefender) && defender.CurrentWounds == 1) //if defender have 1 remaining wound in which case a "s" will not be added to Wound in the message to player. { Console.WriteLine($"As {defender.GladiatorName} currently have {defender.CurrentWounds} wound and recives {causedWoundsToDefender} damage, {defender.GladiatorName} will perish"); defender.CurrentWounds = defender.CurrentWounds - causedWoundsToDefender; return(defender.CurrentWounds); } else if ((defender.CurrentWounds <= causedWoundsToDefender) && defender.CurrentWounds > 1)//If defender have more than 1 wound remaining a "s" will be added to wound in the message to the player. { Console.WriteLine($"As {defender.GladiatorName} currently have {defender.CurrentWounds} wounds and recives {causedWoundsToDefender} damage, {defender.GladiatorName} will perish"); defender.CurrentWounds = defender.CurrentWounds - causedWoundsToDefender; return(defender.CurrentWounds); } else if ((defender.CurrentWounds - causedWoundsToDefender) == 1)//if defender after damage is dealt have 1 remaining wound a "s" will not be added to Wound in the message to player. { Console.WriteLine($"As {defender.GladiatorName} currently have {defender.CurrentWounds} wounds and recives {causedWoundsToDefender} damage, {defender.GladiatorName} have {defender.CurrentWounds = defender.CurrentWounds - causedWoundsToDefender} wound remaining."); return(defender.CurrentWounds); } else if ((defender.CurrentWounds - causedWoundsToDefender) > 1) //if defender after damage is dealt have more than 1 remaining wound a "s" will be added to Wound in the message to player. { Console.WriteLine($"As {defender.GladiatorName} currently have {defender.CurrentWounds} wounds and recives {causedWoundsToDefender} damage, {defender.GladiatorName} have {defender.CurrentWounds = defender.CurrentWounds - causedWoundsToDefender} wounds remaining."); return(defender.CurrentWounds); } } return(defender.CurrentWounds); } else //if aggressors hitroll was more than aggressors weaponskill. { Console.WriteLine($"{aggressor.GladiatorName} did not manage to hit {defender.GladiatorName} and no damage was caused."); return(defender.CurrentWounds); } }
static void Main(string[] args) { //Variable initiations string chosenGladiatorName = "", illegalMenuChoise = "n"; int menuOption = 0; //Print out welcome message and rules for the Arena Console.WriteLine("Welcome to the ARENA!"); Console.WriteLine("In this game you get a generated gladiator that will fight other gladiators to the death. After a fight you will "); Console.WriteLine("be asked if you would like to retire your gladiator. If you retire your gladiator or if your gladiator"); Console.WriteLine("perishes in the arena the game ends, and you get a score based on how many fights your gladiator survived."); Console.WriteLine("Good Luck!"); do {//Here the player is to choose a name that contains letters or numbers. Console.Write("\nWhat would you like to name your Gladiator: "); chosenGladiatorName = Console.ReadLine(); if (chosenGladiatorName == "") { Console.WriteLine("You must type in a name."); } } while (chosenGladiatorName == ""); //Create the players gladiator and assign the name choosen Gladiator playersGladiator = new Gladiator(chosenGladiatorName); do {//here is the ingame menu Console.Clear(); Console.WriteLine("What would you like to do?"); Console.WriteLine("1. Fight in the arena."); Console.WriteLine("2. Retire your Gladiator"); Console.WriteLine("3. Check your Gladiators stats"); Console.WriteLine("You have {0} wins so far", playersGladiator.NumberOfVictories); menuOption = 0; //if text is given as answear a message is given that a number is required try { menuOption = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { illegalMenuChoise = "y"; Console.WriteLine("Indecision will have you killed in the Arena. Please type a number."); Console.ReadLine(); } switch (menuOption) //here starts which option should be run based on which choise in the menu. { case 1: //Here starts a battle between the player and a to be generated gladiator Console.Clear(); Console.WriteLine("BATTLE!!!!!"); Battle playerBattle = new Battle(); Console.WriteLine($"Battle {playersGladiator.BattleNumber}"); playerBattle.FightABattle(playersGladiator); playersGladiator.BattleNumber++; break; case 2: //this choise is if the player wish to retire the gladiator playersGladiator.RetirePlayerGladiator = "y"; break; case 3: //this choise shows the stats of the gladiator Console.WriteLine("Your gladiator {0} have a weaponskill of {1},strenght of {2}, toughness of {3}, wounds equal to {4} and {5} victories.", playersGladiator.GladiatorName, playersGladiator.Weaponskill, playersGladiator.Strenght, playersGladiator.Toughness, playersGladiator.StartingWounds, playersGladiator.NumberOfVictories); Console.ReadLine(); break; case 4: case 5: case 6: case 7: case 8: case 9: case 0: if (illegalMenuChoise == "y") // this is to prevent dubble messages that the menuchoise is not a number { break; } else { Console.WriteLine("This choise will get you killed in the Arena. Make another choise."); Console.ReadLine(); break; } default: break; } } while (playersGladiator.RetirePlayerGladiator != "y" && playersGladiator.IsPlayerGladdiatorDead != "y"); //end if the players gladiator is retired or if the gladiator is dead if (playersGladiator.NumberOfVictories == 0 && playersGladiator.IsPlayerGladdiatorDead == "y") //if the gladiator didnt manage to win any battlerounds and died { Console.WriteLine("You did not manage to win any battles at the Arena, better luck next time!\nYour score is: 0."); } else if (playersGladiator.NumberOfVictories >= 1 && playersGladiator.IsPlayerGladdiatorDead == "y")//if the player gladiator won atleast one round but have died { Console.WriteLine($"Your gladiator {playersGladiator.GladiatorName} has won {playersGladiator.NumberOfVictories} matches over the following gladiators:"); playersGladiator.PrintSlainOpponents(playersGladiator.SlainOpponents); Console.ReadLine(); } else if (playersGladiator.RetirePlayerGladiator == "y" && playersGladiator.IsPlayerGladdiatorDead == "n")//if the players gladiator is alive and retired { Console.WriteLine($"Your gladiator {playersGladiator.GladiatorName} has retired and won {playersGladiator.NumberOfVictories} matches over the following gladiators:"); playersGladiator.PrintSlainOpponents(playersGladiator.SlainOpponents); } Console.ReadLine(); }