Chutes and Ladders

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

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <iomanip>
#include <ctime>

using namespace std;

void draw_box(int n, int player1, int player2);
void draw_board(int player1, int player2);
void draw_dice(int dice);
int roll();

const int MAX = 20;

int main()
{
    cout<<endl<<endl<<endl;
    srand(static_cast<unsigned int>(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;
    }
}
Topic archived. No new replies allowed.