{.cpp}
#include <string>
#include <iostream>
#include "stdafx.h"
using namespace std;
int AmIWin(string strRPCInput, string strRPCCom)
{
int nWin;
if (strRPCInput == "rock")
{
if (strRPCCom == "rock")
{
return nWin = 0;
}
else if (strRPCCom == "scissor")
{
return nWin = 1;
}
else if (strRPCCom == "paper")
{
return nWin = -1;
}
else
{
return nWin = -8;
}
}
if (strRPCInput == "scissor")
{
if (strRPCCom == "rock")
{
return nWin = -1;
}
else if (strRPCCom == "scissor")
{
return nWin = 0;
}
else if (strRPCCom == "paper")
{
return nWin = 1;
}
else
{
return nWin = -8;
}
}
if (strRPCInput == "paper")
{
if (strRPCCom == "rock")
{
return nWin = 1;
}
else if (strRPCCom == "scissor")
{
return nWin = -1;
}
else if (strRPCCom == "paper")
{
return nWin = 0;
}
else
{
return nWin = -8;
}
}
}
#소스파일
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <time.h>
#include <string>
using namespace std;
int main()
{
cout << "let's play rsp game!";
int AmIWin(string strRPCInput, string strRPCCom);
//시간을 랜덤하게 sequence가 시간에 맞추어 배열
srand((unsigned int)time(0));
while (1)
{
int result;
cout << "sel rock,scissor,paper:"<<endl;
string rsp;
string pcrsp;
cin >> rsp;
int ran = rand() % 3;
if (ran == 0)
{
pcrsp = "rock";
}
else if (ran == 1)
{
pcrsp = "scissor";
}
else
{
pcrsp = "paper";
}
result = AmIWin(rsp,pcrsp);
switch(result)
{
case 1:
cout << "uwin!"<<endl << "pc is :"<< pcrsp <<endl;
break;
case -1:
cout << "ufail"<<endl<< "pc is :" << pcrsp << endl;
break;
case -8:
cout << "u are idiot"<<endl<< "pc is :" << pcrsp << endl;
}
}
return 0;
}