Exercise 1 Simple text based game


The Duel

NOTE: This exercise is intended for an object oriented programming language such as C# or Java. PHP or python should work fine as well, without to many adjustments.

Your task is to create a simple text based game where two characters fight each other to death. You can either let the fight progress automatically or hit a key for each round. The project will be divided into subtasks with prerequisits for each task. Make sure each piece works before you move on to the next one. You must be able to run the program before you move on.



At the end, you’ll have four character classes with one unique skill each as well as some skills they all have in common. Each character class must have some way to attack as well as some defence attributes. I won’t bother with class balancing for this challenge. If you want to do that yourself, feel free to go ahead. Some of the classes will have a weapon. We’ll only create two weapons for this exercise, but you, again, can create more if you like. The result of the fight will be randomly generated each time you run the program. The program flow will look like this.

  1. The program starts
  2. The player enters a name for his/her character.
  3. The player picks a class for his/her character.
  4. The player picks a weapon for the character.
  5. The computer selects an opponent with a random class and weapon.
  6. Opponent information is shown to the player.
  7. The player is prompted to press a key or click a button to start the fight.
  8. At the start of each round, the first character to make a move is selected randomly.
  9. The first character to make a move picks a skill to use.
  10. The second character gets a chance to counter the skill.
  11. The second character makes his move.
  12. The first character gets a chance to counter the move.
  13. This continues until one of the characters is out of hitpoints.
  14. The result is displayed to the player.
  15. Program ends.

This might seem overwhelming at first, but we’re going to use basic concepts to complete all these tasks.

Good luck!







Step 8: A few more things

We need to fix a few things before we start implementing our fighting logic.

Our weapon can swing and parry, but our character can’t havea weapon yet. We also need to do some work in the attack and defend methods.

Let’s make the following changes:

  1. Open our character class
  2. Add a field called weapon of type Weapon.
  3. Add a weapon parameter to the constructor and set the weapon field.
  4. Add a field called hitChance with a value between 1 and 100.
  5. Add this new field as well to the constructor and set it.
  6. Change the attack() method to return an integer.
  7. Change the defend method to return a bool.
  8. In the attack method, generate a random number between 1 and 100 and compare it to the hitChance lit we did in the parray method for the weapon. Return true if we hit, otherwise return false.
  9. In the defend method, call the weapon parray method and just return the result.
  10. Change yooour main program to at least be able to run it and do some testing.

If everything works correctly, go on to the next step, where we’ll do some fighting.






This entry was posted in Projects. Bookmark the permalink.