PHP Code:
class player {
public:
int attack(){return strength;}
int receive(int damage){
if (resistance < damage) {
health -= (damage - resistance);
}
if (health <= 0){
dead = true;
return 0;
} else {
return health;
}
}
int getHealth(){return health;}
int getResistance(){return resistance;}
int getStrength(){return strength;}
int getAccuracy(){return accuracy;}
bool isDead(){return dead;}
void getInfo();
void setName(){
//cin.get();
printf("\nWhat is your name? ");
cin >> name;
}
char* getName(){return name;}
void initialize(int h, int r, int s, int a, char* type){
health = h;
resistance = r;
strength = s;
accuracy = a;
species = type;
dead = false;
initialized = true;
}
private:
int health;
int resistance;
int strength;
int accuracy;
bool dead;
bool initialized;
char name[41];
char *species;
}human, wizard, ghost, character;
void player::getInfo(){
system("cls");
cout << "Character Profile:\n"
<< "Name: " << name << " the "
<< species << "\n"
<< "Health: " << health << "\n"
<< "Strength: " << strength << "\n"
<< "Accuracy: " << accuracy << "%\n"
<< "Resistance: " << resistance << "\n";
getche();
}
void initPlayers(){
human.initialize(20, 5, 8, 80, "Warrior");
wizard.initialize(30, 8, 5, 70, "Wizard");
ghost.initialize(50, 0, 15, 60, "Specter");
// Get player type choice from the user
system("cls");
printf("Choose which character to assume:\n");
printf("1) Warrior\n");
printf("2) Wizard\n");
printf("Choice: ");
switch (getche()){
case '1':
character = human;
break;
case '2':
character = wizard;
break;
default:
character = ghost;
break;
}
character.setName();
}