#include<iostream>
#include<conio.h>
#include<ctime>
#include<cstdlib>
#include<string>
int score=0;
using namespace std;
void display(int &score)
{
switch(score)
{
case 98:score=28;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 95:score=24;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 92:score=51;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 83:score=19;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 73:score=1;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 69:score=33;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 64:score=36;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 59:score=17;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 55:score=7;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 52:score=11;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 48:score=9;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 46:score=5;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 44:score=22;cout<<"OPPSSSSS......snaked attacked you...now you are at "<<score<<endl;break;
case 8:score=26;cout<<"Great work.........you are at "<<score<<endl;break;
case 21:score=82;cout<<"Great work.........you are at "<<score<<endl;break;
case 43:score=77;cout<<"Great work.........you are at "<<score<<endl;break;
case 50:score=91;cout<<"Great work.........you are at "<<score<<endl;break;
case 62:score=96;cout<<"Great work.........you are at "<<score<<endl;break;
case 66:score=87;cout<<"Great work.........you are at "<<score<<endl;break;
case 88:score=100;cout<<"Great work.........you are at "<<score<<endl;break;
}}
int main()
{
srand ( static_cast<unsigned int>(time(NULL)) );
int choice;
string name1,name2;
int p1=0;
int p2=0;
cout<<"enter name of PLAYER 1 \n:";
getline(cin,name1);
cout<<"Enter name of PLAYER 2 \n:";
getline(cin,name2);
while((p1<=100)&&(p2<=100))
{
//system("cls");
cout<<"----/\PLAYER1 your turn... \n " ;
getch();
int n=rand()%6+1;
p1=n+p1;
cout<<"player 1 is at "<<p1<<endl;
display(p1);
cout<<"----/\PLAYER2 your turn...press space bar \n " ;
getch();
int m=rand()%6+1;
p2=m+p2;
cout<<"player 2 is at "<<p2<<endl;
display(p2);
}
if(p1>p2)
cout<<name1<<" wins....good work";
else
cout<<name2<<" wins....good work";
system("pause");
return 0;
}
saharfatima
0
Newbie Poster
Recommended Answers
Jump to PostThis is just the machine playing with itself. What about real user input? This is a situation where a proper description of the flow of the game is required. Pseudo code is ok, or just text descriptions of how the game should flow, and how user input is interpreted to …
All 3 Replies
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
saharfatima
0
Newbie Poster
saharfatima
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.