Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Chutes & Ladders (Build From Scratch) In this game of Hangman: Based on t

ID: 3778188 • Letter: I

Question

In C++

Chutes & Ladders (Build From Scratch)

In this game of Hangman:

Based on the board provided below, develop a program that mimics chutes and ladders. When a player rolls the dice they will move that number of spaces. If they land on a space at the bottom of a ladder they may climb the ladder to the corresponding space. If they land on the top of a chute, they must slide down to the corresponding space. 1. This is a two-player game. 2. The game will inform the user if they have rolled too high of a number to win the game and tell them that number. . 3. At any three point in the game there are tiles that will force the user to answer a question in order to roll their next turn. These must be C++ related questions. 4. In order to win the game the player must spin the exact number necessary to land at the end. The program should include: - Loop - Function - Array - Rand - Branching Program Format: - Directions & Player Name - Comments Each Participant should be able to: - Explain each line of code Creative Liberties: - Number of die - Location of the hidden questions - How the board is displayed visually and the indications for chutes and ladders - You can determine if you would like to show the movement of each piece through the board or you can simply display the board at the beginning of each roll

33 32 16 34 31 Chutes and Ladders 35 36 37 38 39 30 28 19 20 21 N 10 13 40 F 25

Explanation / Answer

#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void draw_line(int n,char ch);
void board();
void gamescore(char name1[],char name2[],int p1, int p2);
void play_dice(int &score);

void main()
{
int player1=0,player2=0,lastposition;
char player1name[80],player2name[80];
clrscr();
randomize();
draw_line(50,'=');
cout<<" SNAKE LADDER GAME ";
draw_line(50,'=');
cout<<" Enter Name of player 1 :";
gets(player1name);
cout<<" Enter Name of player 2 :";
gets(player2name);
while(player1<=100 && player2<=100)
{
board();
gamescore(player1name,player2name,player1,player2);
cout<<" --->" <<player1name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player1;
play_dice(player1);
if(player1<lastposition)
cout<<" Oops!! Snake found !! You are at postion "<<player1<<" ";
else if(player1>lastposition+6)
cout<<" Great!! you got a ladder !! You are at position "<<player1;
cout<<" --->"<<player2name<<" Now your Turn >> Press any key to play ";
getch();
lastposition=player2;
play_dice(player2);
if(player2<lastposition)
cout<<" Oops!! Snake found !! You are at position "<<player2<<" ";
else if(player2>lastposition+6)
cout<<" Great!! you got a ladder !! You are at position "<<player2<<" ";
getch();
}
clrscr();
cout<<" ";
draw_line(50,'+');
cout<<" RESULT ";
draw_line(50,'+');
cout<<endl;
gamescore(player1name,player2name,player1,player2);
cout<<" ";
if(player1>=player2)
cout<<player1name<<" !! You are the winner of the game ";
else
cout<<player2name<<" !! You are the winner of the game ";
draw_line(50,'+');
getch();
}

void draw_line(int n,char ch)
{
for(int i=0;i<n;i++)
cout<<ch;
}

void board()
{
clrscr();
cout<<" ";
draw_line(50,'-');
cout<<" SNAKE AT POSITION ";
draw_line(50,'-');
cout<<" From 98 to 28 From 95 to 24 From 92 to 51 From 83 to 19 From 73 to 1 From 69 to 33 From 64 to 36 From 59 to 17 From 55 to 7 From 52 to 11 From 48 to 9 From 46 to 5 From 44 to 22 ";
draw_line(50,'-');
cout<<" LADDER AT POSITION ";
draw_line(50,'-');
cout<<" From 8 to 26 From 21 to 82 From 43 to 77 From 50 to 91 From 62 to 96 From 66 to 87 From 80 to 100 ";
draw_line(50,'-');
cout<<endl;
}

void gamescore(char name1[],char name2[],int p1, int p2)
{
cout<<" ";
draw_line(50,'~');
cout<<" GAME STATUS ";
draw_line(50,'~');
cout<<" --->"<<name1<<" is at position "<<p1<<endl;
cout<<" --->"<<name2<<" is at position "<<p2<<endl;
draw_line(50,'_');
cout<<endl;
}

void play_dice(int &score)
{
int dice;
dice=random(6)+1;
cout<<" You got "<<dice<<" Point !! ";
score=score+dice;
cout<<"Now you are at position "<<score;
switch(score)
{
Case 95 :score=24; break;
Case 98 :score=28; break;
Case 92 :score=51; break;
Case 83 :score=19; break;
Case 73 :score=1; break;
Case 69 :score=33; break;
Case 64 :score=36; break;
Case 55 :score=7; break;
Case 59 :score=17; break;
Case 52 :score=11; break;
Case 48 :score=9; break;
Case 46 :score=5; break;
Case 43 :score=77; break;
Case 8 :score=26; break;
Case 21 :score=82; break;
Case 44 :score=22; break;
Case 50 :score=91; break;
Case 54 :score=93; break;
Case 62 :score=96; break;
Case 66 :score=87; break;
Case 80 :score=100;
}
}