//Produced by Ashish Khulbey
#include"iostream.h"
#include"conio.h"
#include"string.h"
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
#include"dos.h"
void user()
{
clrscr();
int uw=0,a=0,us=0,cw=0,cs=0;
do
{
delay(1000);
clrscr();
srand(time(NULL));
short no=rand()%9+1;
gotoxy(26,2);
textcolor(4);
cprintf("You are batting");
gotoxy(45,5);
cout<<"Score="<<us;
gotoxy(45,8);
cout<<"Wicket="<<uw;
gotoxy(20,5);
cout<<"Enter your no:";
cin>>a;
gotoxy(20,8);
cout<<"Computers no:"<<no;
delay(500);
if((a!=no)&&(uw!=2))
{
us=us+a;
}
else if(a==no)
{
uw++;
}
if(uw==2)
{
gotoxy(1,9);
cout<<"\nYou are out";
delay(1000);
break;
}
} while(uw!=2);
delay(1500);
clrscr();
gotoxy(25,10);
delay(1000);
textcolor(4);
cprintf("Now its computers turn to play");
do
{
delay(1000);
clrscr();
srand(time(NULL));
short no=rand()%9+1;
gotoxy(26,2);
textcolor(4);
cprintf("Computer is batting");
gotoxy(45,5);
cout<<"Score="<<cs;
gotoxy(45,8);
cout<<"Wicket="<<cw;
gotoxy(20,5);
cout<<"Enter your no:";
cin>>a;
gotoxy(20,8);
cout<<"Computers no:"<<no;
delay(500);
if((a!=no)&&(cw!=2))
{
cs=cs+no;
}
else if(a==no)
{
cw++;
}
if(cw==2)
{
gotoxy(1,9);
cout<<"\nComputer is out";
delay(1000);
break;
}
if(cs > us)
{
break;
}
}while(cw !=2);
if(us > cs)
{
delay(1000);
clrscr();
gotoxy(32,10);
textcolor(4);
cprintf("You have Won");
}
if(cs > us)
{
delay(1000);
clrscr();
gotoxy(30,10);
textcolor(4);
cprintf("Computer has Won");
}
}
void cpu()
{
delay(1500);
clrscr();
int cw=0,a=0,cs=0,us=0,uw=0;
do
{
delay(1000);
clrscr();
srand(time(NULL));
short no=rand()%9+1;
gotoxy(26,2);
textcolor(4);
cprintf("Computer is batting");
gotoxy(45,5);
cout<<"Score="<<cs;
gotoxy(45,8);
cout<<"Wicket="<<cw;
gotoxy(20,5);
cout<<"Enter your no:";
cin>>a;
gotoxy(20,8);
cout<<"Computers no:"<<no;
delay(500);
if((a!=no)&&(cw!=2))
{
cs=cs+no;
}
else if(a==no)
{
cw++;
}
if(cw==2)
{
gotoxy(1,9);
cout<<"\nComputer is out";
delay(1000);
break;
}
}while(cw !=2);
delay(1500);
clrscr();
gotoxy(25,10);
textcolor(4);
cprintf("Now its your turn to play");
delay(1500);
do
{
delay(1000);
clrscr();
srand(time(NULL));
short no=rand()%9+1;
gotoxy(26,2);
textcolor(4);
cprintf("You are batting");
gotoxy(45,5);
cout<<"Score="<<us;
gotoxy(45,8);
cout<<"Wicket="<<uw;
gotoxy(20,5);
cout<<"Enter your no:";
cin>>a;
gotoxy(20,8);
cout<<"Computers no:"<<no;
delay(500);
if((a!=no)&&(uw!=2))
{
us=us+a;
}
else if(a==no)
{
uw++;
}
if(uw==2)
{
gotoxy(1,9);
cout<<"\nYou are out";
delay(1000);
break;
}
if(us > cs)
{
break;
}
} while(uw!=2);
if(us > cs)
{
delay(1000);
clrscr();
gotoxy(32,10);
textcolor(4);
cprintf("You have Won");
}
if(cs > us)
{
delay(1000);
clrscr();
gotoxy(30,10);
textcolor(4);
cprintf("Computer has Won");
}
}
void main()
{
clrscr();
int ch=0,q=0;
do
{
gotoxy(23,7);
textcolor(4);
cprintf("The winner of the toss will bat first");
gotoxy(24,9);
textcolor(4);
cprintf("Enter your choice for toss (1/2): ");
cin>>ch;
delay(800);
srand(time(NULL));
short toss=rand()%2+1;
if (toss==ch)
{
gotoxy(27,10);
textcolor(4);
cprintf("You have won the toss");
delay(1500);
user();
}
else
{
gotoxy(27,10);
textcolor(4);
cprintf("Computer has won the toss");
delay(1500);
cpu();
}
delay(1000);
clrscr();
gotoxy(30,5);
textcolor(4);
cprintf("Want to play again??:");
} while(q=='y'||q=='Y');
getch();
}