Question: Load Player Contents Check ( 0 / 4 ) Rogue Class Creation ( 1 / 1 ) Rogue Class Display ( 0 / 1 )

Load Player Contents Check (0/4)
Rogue Class Creation (1/1)
Rogue Class Display (0/1)
Save Player Contents Check (4/4)
Sort NPC List not Full (2/2)
Sort NPC List Full (3/3)
Update Level Check (0/2)
Warrior Class Creation (1/1)
Warrior Class Display (0/1)
Wizard Class Creation (1/1)
Wizard Class Display (0/1)
Add More Than One Player (0/2.5)
Add Player Empty List (0/2.5)
Failed Tests
Add More Than One Player (0/2.5)
Add Player Empty List (0/2.5)
Load Player Contents Check (0/4)
Rogue Class Display (0/1)
Update Level Check (0/2)
Warrior Class Display (0/1)
Wizard Class Display (0/1)
Note: It will tell you something like "Test Failed: b"..."!= b"..."" where the left hand side is my output and the right hand side is the expected output.
this is my code:
// Q7-b: Define Friend Function updateLevel()(1.5 points)
// Define the function updateLevel()that is declared in player.h file.
// This function sets the new 'level' of the player. The player object and new level is to be passed as function arguments.
// Use 'd' display option after using 'c' option to verify.
// You will need to implement addPlayer() and displayList() before you test this function.
// Updating a player's level will update their stats. This scaling matches the same scaling as the constructor in player.cpp.
void updateLevel(Player* player, int newLevel){
player->level = newLevel;
// Update stats based on player type
if (player->getPlayerType()== warrior){
player->health = newLevel *200;
player->mana = newLevel *10;
player->armor = newLevel *50;
player->magicResist = newLevel *25;
player->attack = newLevel *50;
player->magicAttack = newLevel *10;
}
else if (player->getPlayerType()== wizard){
player->health = newLevel *25;
player->mana = newLevel *100;
player->armor = newLevel *10;
player->magicResist = newLevel *50;
player->attack = newLevel *10;
player->magicAttack = newLevel *100;
}
else if (player->getPlayerType()== rogue){
player->health = newLevel *50;
player->mana = newLevel *25;
player->armor = newLevel *25;
player->magicResist = newLevel *10;
player->attack = newLevel *100;
player->magicAttack = newLevel *50;
}
}
// Q8- addPlayer (5 points)
// This function is used to add a new player to the global linked list 'list'. Add the new player to tail of the list.
// playerType 'type' can be warrior, wizard, or rogue. You will need to use the function argument type to determine which constructor to use to create new player node.
// For example, if the user enters type as 'rogue', then you need to use the Rogue class and constructor to create new player node and add it to the list.
// NOTE: In executeAction(), searchPlayer() is called before this function. Therefore no need to check here if the player exists in the list.
// See how this fucntion is called in case 'a' of executeAction()
void addPlayer(string nameInput, int levelInput, playerType archetypeInput)
{
Player* newPlayer = nullptr;
// Create the correct subclass based on the archetype
switch (archetypeInput){
case warrior:
newPlayer = new Warrior(nameInput, levelInput, archetypeInput);
break;
case wizard:
newPlayer = new Wizard(nameInput, levelInput, archetypeInput);
break;
case rogue:
newPlayer = new Rogue(nameInput, levelInput, archetypeInput);
break;
default:
std::cerr "Error: Invalid player type." std::endl;
return; // Exit if archetype is invalid
}
Load Player Contents Check ( 0 / 4 ) Rogue Class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!