newPlayerTest.cpp

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

using namespace std;

const int PLAYERS{3};

void TellAboutPlayer(NewPlayerT *  player);

int main() {
    NewPlayerT *  players[PLAYERS];

    players[0] = new FighterT("Fred");
    players[1] = new WizardT("Walt");
    players[2] = new MonkT("Marty");

    for(int i = 0; i < PLAYERS; ++i) {
       TellAboutPlayer(players[i]);
    }

    cout << endl << endl;
    cout << "A few Battles " << endl;
    for(int i = 0; i < PLAYERS; ++i) {
       for(int j = 0; j < PLAYERS; ++j)  {
          if (i != j) {
             players[i]->Fight(players[j]);
          }
       }
    }

    for(int i = 0; i < PLAYERS; ++i) {
        delete players[i];
    }

    return 0;
}

void TellAboutPlayer(NewPlayerT *  player){
    cout << player->Name() << " the " << player->Role() << endl;
    cout << "\tHas a defense of " << player->Defense() << endl;
    cout << "\tHas  " << player->HP() << " hit points."  << endl;
}