#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include <string>
usingnamespace std;
class human;
class AI;
class Ref;
class game {
public:
newGame();
void setHchoice(string Hchoice);
void setCchoice(string Cchoice);
string getHchoice ();
string getCchoice ();
void setNchoice(int n);
int getNchoice();
protected: //game is used as a storage of data from the AI and human
staticint nchoice; //number of RPS game human played
static string hchoice; //human choice
static string cchoice; //computer choice
private:
};
#endif // GAME_H_INCLUDED
#include "game.h"
#include "human.h"
#include <string>
usingnamespace std;
human::human() {
choice="";
setHchoice("");
setNchoice(0);
}
human::human(string Choice) {
int i;
int nchoice=0;
choice=Choice;
setHchoice(Choice);
for (i=0;i<=Choice.length();i++) { //counting the number of game the human made
if (Choice[i]==32) {
nchoice++;
}
}
if (nchoice!=0) {
nchoice++;
}
if (nchoice==0 && Choice[0]!=0) {
nchoice=1;
}
setNchoice(nchoice);
//cout<<"n in human: "<<getNchoice()<<endl;
}
void human::setchoice(string Choice) {
int i;
int nchoice=0;
choice=Choice;
setHchoice(Choice);
for (i=0;i<Choice.length();i++) {
if (Choice[i]==32) {
nchoice++;
}
}
if (nchoice!=0) {
nchoice++;
}
setNchoice(nchoice);
}
human.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef HUMAN_H_INCLUDED
#define HUMAN_H_INCLUDED
#include "game.h"
#include <string>
usingnamespace std;
class human : public game {
public:
human();
human(string choice);
void setchoice(string Choice);
private:
string choice;
int nchoice;
};
#endif // HUMAN_H_INCLUDED