This is my unfinished code for Chutes an Ladders. How would I get draw_board and draw_box to print in rows and columns? Any help is appreciated. Thanks
#include <iostream>
#include <iomanip>
#include <ctime>
usingnamespace std;
void draw_box(int n, int player1, int player2);
void draw_board(int player1, int player2);
void draw_dice(int dice);
int roll();
constint MAX = 20;
int main()
{
cout<<endl<<endl<<endl;
srand(static_cast<unsignedint>(time(nullptr)));
int p1 = 0;
int p2 = 0;
int p1_dice = 0;
int p2_dice = 0;
int turn = 1;
int answer = 0;
bool done = false;
do{
//P1 Position
draw_board(p1, p2);
draw_dice(p1_dice);
p1_dice = roll();
cout<<"Player 1 dice is: "<<p1_dice<<endl;
p1 = p1 + p1_dice;
cout<<"Player 1 is now in box: "<<p1<<endl;
cin.get();
//P2 Position
p2_dice = roll();
draw_dice(p2_dice);
cout<<"Player 2 dice is: "<<p2_dice<<endl;
p2= p2 + p2_dice;
cout<<"Player 2 is now in box: "<<p2<<endl;
cin.get();
//Player Turn
if (turn >0){
cout<<"Player 1 Turn"<<endl;
}
else{
cout<<"Player 2 Turn"<<endl;
}
turn = turn * -1;
cin>>answer;
if (answer =='x')
done =true;
}while (!done);
return 0;
}
//Dice Roll
int roll(){
return (rand()%(6-1+1)+1);
}
//Draw Board
void draw_board(int player1, int player2){
for (int i = 0; i<MAX; i++){
draw_box(i, player1, player2);
}
cout<<endl<<endl;
}
void draw_box(int n, int player1, int player2){
cout<<"["<<setw(2)<<n;
if (player1 == n)
cout<<" $ ";
else
cout<<" ";
if (player2 == n)
cout<<"@ ";
else
cout<<" ";
cout<<"]"<<setw(2);
}
//Dice Faces
void draw_dice(int dice){
switch (dice){
case 1:
cout<<"+-------+"<<endl;
cout<<"| |"<<endl;
cout<<"| o |"<<endl;
cout<<"| |"<<endl;
cout<<"+-------+"<<endl;;
break;
case 2:
cout<<"+-------+"<<endl;
cout<<"| o |"<<endl;
cout<<"| |"<<endl;
cout<<"| o |"<<endl;
cout<<"+-------+"<<endl;;
break;
case 3:
cout<<"+-------+"<<endl;
cout<<"| o |"<<endl;
cout<<"| o |"<<endl;
cout<<"| o |"<<endl;
cout<<"+-------+"<<endl;;
break;
case 4:
cout<<"+-------+"<<endl;
cout<<"| o o |"<<endl;
cout<<"| |"<<endl;
cout<<"| o o |"<<endl;
cout<<"+-------+"<<endl;;
break;
case 5:
cout<<"+-------+"<<endl;
cout<<"| o o |"<<endl;
cout<<"| o |"<<endl;
cout<<"| o o |"<<endl;
cout<<"+-------+"<<endl;;
break;
case 6:
cout<<"+-------+"<<endl;
cout<<"| o o |"<<endl;
cout<<"| o o |"<<endl;
cout<<"| o o |"<<endl;
cout<<"+-------+"<<endl;;
break;
}
}