NewPlayerT.cpp

URL: http://147.64.242.52/~bennett/class/cmsc2040/fall2026/notes/inherit/code/preClass/NewPlayerT.cpp
 
#include <iostream>
#include "NewPlayerT.h"

using namespace std;

NewPlayerT::NewPlayerT(std::string newName){
   name = newName;
}

string NewPlayerT::Name() const{
   return name;
}

int NewPlayerT::Defense()const {
   return defense;
}

void NewPlayerT::ChangeHP(int amount){
   hp += amount;
}

int NewPlayerT::HP() const{
   return hp;
}

void NewPlayerT::SetDefense(int newDefense) {
   defense = newDefense;
}

FighterT::FighterT(std::string newName): NewPlayerT{newName + " the Fighter"} {
   SetDefense(10);
   ChangeHP(2);
}

string FighterT::Role() const {
   return "Fighter";
}

void FighterT::Fight(NewPlayerT * other){
   cout << " A " << Role() << " attacks a " << other->Role() << endl;

   int attack = rand() % 12+1;
   if (other->Defense() < attack) {
       cout << Name() << " chops " << other->Name() << endl;   
       other->ChangeHP(-3);
   } else { 
       cout << Name() << " attacks but misses " << other->Name() << endl;   
   } 
   cout << endl;
}


WizardT::WizardT(std::string newName): NewPlayerT(newName + " the Wizard"){
   SetDefense(6);
   ChangeHP(-2);
}

void WizardT::Fight(NewPlayerT * other){
   cout << " A " << Role() << " attacks a " << other->Role() << endl;
   cout << Name() << " does a zap attack on " << other->Name() << endl;   
   other->ChangeHP(-2);
   cout << endl;
}

string WizardT::Role() const {
   return "Wizard";
}

MonkT::MonkT(std::string newName): NewPlayerT(newName + " the Monk") { }

void MonkT::Fight(NewPlayerT * other) {
   cout << " A " << Role() << " attacks a " << other->Role() << endl;
   cout << Name() << " refuses to attack " << other->Name() << endl;   
   cout << endl;
}

void MonkT::ChangeHP(int amount){
    NewPlayerT::ChangeHP(amount/2);
}

string MonkT::Role() const {
   return "Monk";
}

int FighterT::Strength() const{
   return strength;
}

int WizardT::Magic() const {
   return magic;
}

int MonkT::Patience() const {
    return patience;
}