Objectives
The goal of this assignment is to learn the following:
- How to use inheritance
- How to create class actions and use derived actions
- How to use the audio library to record and play sounds
Overview
In this assignment you will create an interactive battle simulator. Users will be given the chance to record their own sound effects. They will be given a description of three different types of champions, and will get to choose their champion and their opponent. Then, the two will fight to the death, with the user's own sound effects detailing each hit and miss in this epic battle.
Requirements
You will need six classes: Equipment, Sounds, Stats, Warrior, Wizard, and Ranger. Class Stats will be your base class, and will contain actions and blueprint actions to be used in each class that inherits from Stats.
To do : You have to put your own record (.wav) in the good files. And only after, you can run this project. When it's implemented, each of the records should last no more than 2 seconds.
Class Equipment
In this class, you will implement a getter and a setter a class variable of type text called name:
- action SetEquipment(text equipment): Setter for name.
- action GetEquipment returns text: Getter for name.
Class Stats
This class will need the following library: use Libraries.Containers.Array. As you did in Lab 6.2, you will need to create an array of type Equipment. Name this array inventory. Class Stats will use the following actions:
- action AddEquipment(Equipment item): This action adds the input parameter to the array inventory.
- action SayInventory: This action should iterate through inventory until it reaches the end and say to the user each item held in it.
- blueprint action BuildCharacter: This is a blueprint that will be later implemented in classes Warrior, Wizard, and Ranger.
Class Sounds
This class will contain several actions to record your own sound effects to be used in the simulator. Implement the following actions:
- action RecordHit: Records for 2 seconds a "hit" sound. To be used when your champion or your enemy successfully makes a hit.
- action RecordMiss: Records for 2 seconds a "miss" sound. To be used when your champion or your enemy misses a hit.
- action RecordOuch: Records for 2 seconds an "ouch" sound. To be used when you champion or your enemy gets hit.
- action RecordTaunt:Records for 2 seconds a taunting sound. To be used when you champion misses the enemy, or the enemy misses your champion.
- action RecordVictory: Records for 2 seconds a victory song. To be used if your champion deafeats the enemy.
- action RecordDefeat: Records for 2 seconds a "defeat" sound. To be used if your enemy defeats your champion.
Class Ranger
Class Ranger will inherit from class Stats. It will have one action: action BuildCharacter. Similar to Lab 6.2, BuildCharacter will describe the Ranger in terms of his equipment and weapons. Using the inherited actions from class Stats, add at least 5 items to describe the Ranger. Example:
action BuildCharacter
Equipment bow
bow:SetEquipment("uses a two hand bow with steel arrows")
parent:Stats:AddEquipment(bow)
end
Class Warrior
Class Warrior will inherit from class Stats. It will have one action: action BuildCharacter. BuildCharacter will do the same in class Warrior as it did in class Ranger.
Class Wizard
Class Wizard will inherit from class Stats. It will have one action: action BuildCharacter. BuildCharacter will do the same in class Wizard as it did in class Warrior.
Class Main
Class Main will have two actions:
- action Damage(integer HP) returns integer Damage will use a random number generator (named value to generate integers no larger than 50). It will then follow this format:
if value is between 0 and 10, decrement HP by 10.
if value is between 10 and 20, decrement HP by 20.
//Continue this up until 50, then return HP.
if value is between 0 and 10, decrement HP by 10. if value is between 10 and 20, decrement HP by 20. //Continue this up until 50, then return HP.
- action Main: Mainshould call all the actions to describe the three champions. It should also call all of the actions so the user can record their own sound effects. After this, the user should be prompted to choose a champion. If the user selects the warrior, tell them they selected the warrior, and using the audio files that came with this project, play "Warrior.wav". Do the same if the user selects the Ranger or the Wizard, playing the appropriate files for each.
Next, prompt the user to choose an opponent. Do the same for the opponent selection as you did for the champion selection: telling the user which opponent they selected, and playing the appropriate sound. Now you will simulate a battle between the champion and the opponent. Create a random number generator (named decider) that will generate integers between 0 and 3. Repeat the following until either the champion or the opponent has less than or equal to 0 hp:
if decider = 0
Play "Hit.wav". Decrement the opponent's hp. Play "Ouch.wav". Tell the user
their champion made a successful hit, and tell them the enemies current hp.
if decider = 1
Tell the user their champion missed the enemy. Play "Miss.wav". Play "Taunt.wav".
if decider = 2
Play "Hit.wav". Decrement the champion's hp. Play "Ouch.wav". Tell the user
their champion was successfully hit by their opponent, and tell them the champions current hp.
if decider = 3
Tell the user the opponent missed their attack on the champion. Play "Miss.wav". Play "Taunt.wav"
Lastly, check to see if either the champion or the opponent has died. If the champion died, play "Defeat.wav" and tell the user the opponent was the victor. If the opponent died, play "Victory.wav" and tell the user the champion was the victor.
Sample Output
When run, the program should describe the three champions to the user. Then, the user will select a champion and an opponent. The battle will ensue, and the user will be told who the victor was in the end. The following is an example of when the program is run after the champions are described:
Choose a Champion: Enter 1 for the Warrior, 2 for the Ranger, or 3 for the Wizard
1
You have chosen the Warrior as your champion.
*Play Warrior.wav*
Choose an opponent: Enter 1 for the Warrior, 2 for the Ranger, or 3 for the Wizard
2
You have chosen the Ranger as your opponent
*Play Ranger.wav*
*Play Hit.wav*
*Play Ouch.wav*
Successfully hit the enemy! His HP is 50
Your opponent missed their attack on you.
*Play Miss.wav*
*Play Taunt.wav*
*Play Hit.wav*
*Play Ouch.wav*
Successfully hit the enemy! His HP is 0
Your champion is the victor!!!
*Play Victory.wav*