Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
34Activity
0 of .
Results for:
No results containing your search query
P. 1
Snakes Ladders program in C++

Snakes Ladders program in C++

Ratings:

1.0

(1)
|Views: 7,426|Likes:
Published by afiz
This is snakes and ladders program which is written in C++ programming language.
This is snakes and ladders program which is written in C++ programming language.

More info:

Categories:Types, School Work
Published by: afiz on Apr 18, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

01/11/2013

pdf

text

original

 
/*sankes_ladder.cpp:This is sankes_ladder Game program. This program will displaysankes and ladder Board.It will take two player names. Gives you winner of the Game byusing Random function.Date : 18/04/2009.Author: Afiz *******/#include<iostream> // including header files.using namespace std;class player // player class{public: // class members declaration.char name[50];player(); // constructor declaration.int currentposition;int previousposition;int Rollingdie(); // Rollingdie function.};player :: player() // constructor implementation.{currentposition=1; // initialization of variables.previousposition=1;}int player :: Rollingdie() // Rollingdie function.{return (rand()%(6)+1); // using Random function.}class board // board class.{int Board[10][10]; // board arraypublic:board(); // board constructor.int nextposition(int, int) ; // declaration of nextpostion function.void display(); // display function.};board:: board() // creating board{int k=1;for(int i=0;i<10;i++)for(int j=0;j<10;j++)Board[i][j]=k++; // assiging values to board}int board :: nextposition(int a, int b) // implemenation of nextposition function.{switch(a+b){ // creting ladders.case 8://cout << "Great You Got Ladder\n";return 31;break;
 
case 15:return 97;break;case 42:return 81;break;case 66:return 87; break;// creating snakescase 24:return 1;/* cout << "Wow.. You Got Snake\n";*/break;case 55:return 13;break;case 71:return 29; break;case 88:return 54; break;case 99:return 6; break;default:return (a+b); break;}}void board :: display() // definition of display function.{for(int i=9;i>=0;i--){cout <<endl;if(i%2!=0){ // Add line Display Codefor(int j=9;j>=0;j--){if( Board[i][j]==1 || Board[i][j]==24) // this is all about creating sankesand laddercout << Board[i][j]<<"S1\t" ;else if( Board[i][j]==13 || Board[i][j]==55)cout << Board[i][j]<<"S2\t" ;else if( Board[i][j]==29 || Board[i][j]==71)cout << Board[i][j]<<"S3\t" ;else if( Board[i][j]==54 || Board[i][j]==88)cout << Board[i][j]<<"S4\t" ;else if( Board[i][j]==6|| Board[i][j]==99)cout << Board[i][j]<<"S5\t" ;else if(Board[i][j]==8 || Board[i][j]==31)cout << Board[i][j]<<"L1\t" ;else if(Board[i][j]==15 || Board[i][j]==97)cout << Board[i][j]<<"L2\t" ;else if(Board[i][j]==42 || Board[i][j]==81)cout << Board[i][j]<<"L3\t" ;else if(Board[i][j]==66 || Board[i][j]==87)cout << Board[i][j]<<"L4\t" ;elsecout << Board[i][j] << "\t";}}else{for(int j=0;j<10;j++)if( Board[i][j]==1 || Board[i][j]==24) // Even Line display code
 
cout << Board[i][j]<<"S1\t" ;else if( Board[i][j]==13 || Board[i][j]==55) // this is all aboutcreating sankes and laddercout << Board[i][j]<<"S2\t" ;else if( Board[i][j]==29 || Board[i][j]==71)cout << Board[i][j]<<"S3\t" ;else if( Board[i][j]==54 || Board[i][j]==88)cout << Board[i][j]<<"S4\t" ;else if( Board[i][j]==6|| Board[i][j]==99)cout << Board[i][j]<<"S5\t" ;else if(Board[i][j]==8 || Board[i][j]==31)cout << Board[i][j]<<"L1\t" ;else if(Board[i][j]==15 || Board[i][j]==97)cout << Board[i][j]<<"L2\t" ;else if(Board[i][j]==42 || Board[i][j]==81)cout << Board[i][j]<<"L3\t" ;else if(Board[i][j]==66 || Board[i][j]==87)cout << Board[i][j]<<"L4\t" ;elsecout << Board[i][j] << "\t";}}}int main() // main class{srand(time(0)); // it is random function.board b; // creation object in board class.cout <<"\n****************************************************************************\n";cout << "\t\tSnakes and Ladder Board";cout <<"\n****************************************************************************\n";b.display(); // calling display function.cout <<"\n****************************************************************************\n";player player1,player2; // creationg objects in player class.cout << "Enter First player Name\n";cin >> player1.name;cout << "Enter second player Name\n";cin >> player2.name;cout << endl;cout <<"***********************\n##### Main Game####\n***********************\n";int score;while(true){// player One logic part.player1.previousposition = player1.currentposition;score=player1.Rollingdie(); // calling Rollingdie function.player1.currentposition =b.nextposition(score,player1.previousposition);if(player1.currentposition > 100)player1.currentposition=player1.previousposition;cout << player1.name<<"\t"<< player1.currentposition <<"\t"<<score<<endl;if(player1.currentposition == 100)

Activity (34)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Rajesh Singh liked this
Esther Yp liked this
Rizki Pratama liked this
Musa Ghauri liked this
KalyaneeMuniandy liked this
mewborna liked this
KalyaneeMuniandy liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->