1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int main()
{
srand(time(NULL));
int choice,n=0,player1=-1,player2=-1,winner=0,dice,j=0,k=0;
char mark1='X',mark2='O';
string square[100]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","23","24","25","26","27","28","29","30",
"31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58",
"59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","78","79","80","81","82","83","84","85",
"86","87","88","89","90","91","92","93","94","95","96","97","98","99","100"};
cout<<" Snake and Ladder "<<endl;
getch();
system("CLS");
do {
cout<<"| | | | | | | | | | | Type 1 to Roll the Dice"<<endl;
cout<<"|"<<square[99]<<"|"<<square[98]<<" |"<<square[97]<<" |"<<square[96]<<" |"<<square[95]<<" |"<<square[94]<<" |"<<square[93]<<" |"<<square[92]<<" |"<<square[91]<<" |"<<square[90]<<" |"<<endl;
cout<<"---------------------------------------- Ladder: 1-38,4-14,9-31,21-42"<<endl;
cout<<"| | | | | | | | | | | 28-84,51-67,71-91,80-100"<<endl;
cout<<"|"<<square[80]<<" |"<<square[81]<<" |"<<square[82]<<" |"<<square[83]<<" |"<<square[84]<<" |"<<square[85]<<" |"<<square[86]<<" |"<<square[87]<<" |"<<square[88]<<" |"<<square[89]<<" |"<<endl;
cout<<"---------------------------------------- Snake: 17-6,54-34,62-19,64-60"<<endl;
cout<<"| | | | | | | | | | | 87-24,93-73,95-75,98-79"<<endl;
cout<<"|"<<square[79]<<" |"<<square[78]<<" |"<<square[77]<<" |"<<square[76]<<" |"<<square[75]<<" |"<<square[74]<<" |"<<square[73]<<" |"<<square[72]<<" |"<<square[71]<<" |"<<square[70]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[60]<<" |"<<square[61]<<" |"<<square[62]<<" |"<<square[63]<<" |"<<square[64]<<" |"<<square[65]<<" |"<<square[66]<<" |"<<square[67]<<" |"<<square[68]<<" |"<<square[69]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[59]<<" |"<<square[58]<<" |"<<square[57]<<" |"<<square[56]<<" |"<<square[55]<<" |"<<square[54]<<" |"<<square[53]<<" |"<<square[52]<<" |"<<square[51]<<" |"<<square[50]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[40]<<" |"<<square[41]<<" |"<<square[42]<<" |"<<square[43]<<" |"<<square[44]<<" |"<<square[45]<<" |"<<square[46]<<" |"<<square[47]<<" |"<<square[48]<<" |"<<square[49]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[39]<<" |"<<square[38]<<" |"<<square[37]<<" |"<<square[36]<<" |"<<square[35]<<" |"<<square[34]<<" |"<<square[33]<<" |"<<square[32]<<" |"<<square[31]<<" |"<<square[30]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[20]<<" |"<<square[21]<<" |"<<square[22]<<" |"<<square[23]<<" |"<<square[24]<<" |"<<square[25]<<" |"<<square[26]<<" |"<<square[27]<<" |"<<square[28]<<" |"<<square[29]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[19]<<" |"<<square[18]<<" |"<<square[17]<<" |"<<square[16]<<" |"<<square[15]<<" |"<<square[14]<<" |"<<square[13]<<" |"<<square[12]<<" |"<<square[11]<<" |"<<square[10]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"| | | | | | | | | | |"<<endl;
cout<<"|"<<square[0]<<" |"<<square[1]<<" |"<<square[2]<<" |"<<square[3]<<" |"<<square[4]<<" |"<<square[5]<<" |"<<square[6]<<" |"<<square[7]<<" |"<<square[8]<<" |"<<square[9]<<" |"<<endl;
cout<<"----------------------------------------"<<endl;
n=(n%2)+1;
cout<<"\nPlayer "<<n<<", It's Your Turn: ";
cin>>choice;
if(choice==1){
dice=rand()%6+1;
cout<<"You rolled "<<dice<<endl;
if(n==1) {
player1=player1+dice;
j=(j+player1);
square[j]=mark1;
}
}
else if(n==2) {
player2=player2+dice;
k=(k+player2);
square[k]=mark2;
}
}
else {
cout<<"Press 1 to roll the dice!"<<endl;
}
getch();
if(player1==99) {
winner=1;
}
else if(player2==99) {
winner=2;
}
system("CLS");
}
while(winner==0);
getch();
return 0;
}
|