#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class Player{
private :
string name[2];
int idx;
public :
Player(){name[0]="옥돌이"; name[1]="돌딸기"; idx=-1;}
string getName(){
idx++;
if(idx==2){
idx=0;
return name[idx];
}
else{
return name[idx];
}
}
};
class UpAndDownGame{
private:
static int result;
static int low;
static int high;
public:
UpAndDownGame() {srand((unsigned) time (0));}
static void Game();
};
int UpAndDownGame :: high = 90;
int UpAndDownGame :: low = 0;
int UpAndDownGame :: result = 0;
void UpAndDownGame :: Game() {
int number ;
Player p;
cout << "Up & down 게임을 시작합니다. " << endl;
result= rand() %100;
while (1){
string name= p.getName();
cout << "답은 " << low<< "와 " << high << "사이에 있습니다." ;
cout << name << ">> ";
cin >> number;
if(number > result) {
high=number;
}
else if (number <result) {
low=number;
}
else{
cout << name <<"이(가) 이겼습니다 !! " << endl;
break;
}
}
}
int main(){
UpAndDownGame gg;
gg.Game();
return 0;
}