Introduction

This is the challenge requirements document for the second half of the challenge called ChallengeHeroMonsterClasses. This part of the challenge will pick up right where the other one left off. You can either continue with your solution or, alternatively, you can use the starting point given in the provided challenge code folder.

Instructions

In this part of the challenge, you are to create a new Dice class that will serve as a random value for each character’s Attack() method. The Dice class will have one property, an int called Sides. This will be determined by each Character’s DamageMaximum value; if DamageMaximum is 25, then there are 25 sides.

This class will also contain a single method: Roll(). This method will return a random value to the caller, between zero and the number of sides of the die. There is a catch: You need to make sure the number is truly random each time. We’ve seen before how sometimes the Random class will non-random values, and we’ve also seen how to fix that issue. As a hint, try not to initialize your instance of the Random class within the Roll() method.

In the Default class’ Page_Load method, you’ll create a new instance of the Dice class and pass it in as the input parameter for each Character’s Attack() method. This method will set the Sides property of the die and call the Roll() method to determine the damage inflicted by the attack. This value will be returned to the caller.

Before beginning the battle loop, perform a check to determine if the hero or monster gets an AttackBonus. If this case is true, that Character gets to perform a bonus attack before the battle loop begins. This means that the Attack() method will be called for that character, and the Defend() method will be called for the other character.

Create a while() loop to represent the battle loop. This loop will only break out once one character’s health is less than zero. Inside the loop, the monster should attack the hero first and then the hero should attack the monster.

Finally, create a new helper method within the Default class called displayResults(). This method will take in two Characters: opponent1 and opponent2. Depending on their health, determine the winner and print out a winning message using both their names. If both characters have dies, print out a different message stating that.

Conclusion

This challenge requires some modification and extra thinking with the classes you’re dealing with. Make sure to refer to this and to the provided challenge code folder’s requirements if you have any questions regarding functionality. If you do get stuck, refer to the solution to see a working implementation of this challenge. As always, do your best to finish the challenge without looking at the solution. Think through it, struggle a bit, and do your best. Good luck!


Lessons in this Course