You are the Dungeon Master(DM) for a great DnD campaign. However, you've had a very busy week, and you dont have a story prepared for this weekends session. You decide to wing it with a Free for All combat, where the party decides to fight each other to see who comes out on top. To make things easier, you decide to write a program to basically let the session run itself. Please write a program that conforms to the following requirements:

1. Create a structure called Move that contains the following data members

  • name = cstring of 50 characters
  • damage - integer

2. Create a structure called Character that contains the following data members:

  • name - cstring of 50 characters
  • char_class - cstring of 50 characters
  • hitPoints - integer
  • armorClass - integer
  • isAlive - boolean
  • moveName - cstring of 50 characters

3. Open the file characters.txt. The file will be in the following format:

numMoves
move1 damage1
move2 damage2
.
.
.
moveM damageM
numChar
name1 class1 HP1 AC1 move1
name2 class2 HP2 AC2 move2
.
.
.
nameN classN HPN ACN moveN

4. The first line of the file is an integer M, representing the number of Moves. The next 'M' lines of the file will consist of 2 pieces of data - the name of the move, followed by the damage the move can do. These are separated by a tab. The next line is an integer N, representing the number of characters. The next N lines of the file will consist of 5 pieces f data - the name of the character, the character class, the hitpoints for that character, the armor class of that character and finally the signature move of that character. This data is tab separated as well.

5. Open the file session.txt. This file will be in the following format:

numAttacks
character1 move1 target1 roll1
character2 move2 target2 roll2
.
.
.
characterK moveK targetK rollK

6. The first line of the file is an integer K, representing the number of attacks. The next K lines, will each consist of the name of a character, the name of a move, the name of a second character who is being attacked, and the dice roll for the success of the attack.

7. Read in the number of Moves M from character.txt. Create a dynamic array of M Moves, and populate the structure variables with the data from the file.

8. Read the number of characters N. Create a dynamic array of N structure variables, and populate the structure variables with the data from the file. In the beginning, all the characters are alive.

9. Read in the attacks K from the file session.txt.

10. For each attack, check if the move used is the signature move of the character using the move. Also check if the roll for the attack is at least equal to the armor class of the character being attacked. If both conditions are met, subtract the move's damage from the hitpoints of the character being attacked.

11. If ever the hitpoints of the character drops BELOW 0, that character is dead.

12. Open the output file alive.txt. Print the names of the characters that are still alive and the hitpoints they have left, one per line, in the order they appear in the input file,

13. Close the files and delete the dynamic arrays

14. Make sure your program is commented properly

Sample Files

character.txt

9
Eldritch Blast 6
Strike with Longsword 7
Magic Missile 10
Shot with Crossbow 5
Unarmed Strike 4
Whip of Fire 3
Slingshot 3
Poison Dart 4
Bewitching Song 5
6
Bethryn Esvele Oracle 17 10 Bewitching Song
PatPat Barbarian 25 16 Strike with Longsword
Kold Steele Fighter 27 14 Unarmed Strike
Grendain Sorcerer 14 11 Whip of Fire
Fran Solo Rouge 18 12 Shot with Crossbow
Thruchet Druid 15 10 Poison Dart

session.txt

15
Bethryn Esvele Bewitching Song Kold Steele 16
Thruchet Flaming Strike Grendain 4
Fran Solo Shot with Crossbow Patpat 8
Patpat Strike with Longsword Thruchet 12
Kold Steele Unarmed Strike Grendain 13
Grendain Whip of Fire Bethryn Esvele 10
Fran Solo Shot with Crossbow Patpat 17
Thruchet Poison Dart Bethryn Esvele 11
Kold Steele Unarmed Strike Grendain 11
Bethryn Esvele Bewitching Song Thruchet 16
Patpat Strike with Longsword Fran Solo 12
Grendain Whip of Fire Thruchet 11
Fran Solo Shot with Crossbow Kold Steele 15
Kold Steele Unarmed Strike Patpat 18
Patpat Strike with Longsword Grendain 13

alive.txt

Bethryn Esvele 10
Patpat 16
Kold Steele 17
Fran Solo 11
Thruchet 0

Extra Credit

Write a function called sort according to the following specifications:

  • The function should take in 3 parameters - a dynamic array of Character structures, the number of elements in the array, and a character sortBy
  • If the sortBy character is 'n', sort the characters by their name, in ascending order.
  • If the sortBy character is 'h, sort by hit points, in descending order.
  • if the sortBy character is anything else, leave the array untouched.
  • Call the sort function before printing to the alive.txt file. Set sortBy to 'n'. We will change it while grading, if necessary.
  • If you chose to implement this, the output will still be the same characters in alive.txt, just arranged differently.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.