hey folks, im new to C++ and im trying to write a simple little "call to function" program for the game snakes and ladders.. simple.. yet killing me.. on the inside. my brain hurts. (this is normal right?)
ill have my code at the end of what i have so far.. and help is much appreciated.. insight or whatever to get me kickin.
here are my steps i want in my program..
1. enter names of both players
2. run a loop to control the program, call a "Check" function to check if the player has reached 100. using a bool data type where the while statement is.
3. inside that loop have a function for each player
- for player 1 =
"turn" function (for the dice roll (1 - 6))
"advance" function (to move ahead) and
INSIDE the
"advance" function call on the function
"snakes" and another function
"chutes" (to see if they climb up or fall down)
"print" function (to see current status of player)
- REPEAT for player 2!
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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int CheckWin (int RollDie, int Move, void CheckChutes, void CheckLadders );
int main()
{
srand(time(NULL));
char player1;
char player2;
cout << "==========================CHUTES AND LADDERS=========================" << endl << endl;
cout << "What are your names?" << endl;
cout << "Enter name of Player 1: ";
cin >> player1;
cout << endl;
cout << "Enter name of Player 2: ";
cin >> player2;
cout << endl;
cout << "TIME TO PLAY!" << endl << endl;
cout << "player move number current position die new position";
cout << "*************************************************************************";
CheckWin();
cout << player1 << //OUTPUTS WILL GO
cout << player2 << //HERE
return 0;
}
int CheckWin (int RollDie, int Move, void CheckChutes, void CheckLadders )
{
int RollDie (int dice)
{
return rand() % 6 + 1;
Move();
}
int Move (int dice)
{
P1pos = 1;
NewPos = P1pos + RollDie;
CheckChutes();
CheckLadders();
}
void CheckChutes ()
{
if (NewPos == 11)
NewPos = 4;
else if (NewPos == 15)
NewPos = 7;
else if (NewPos == 30)
NewPos = 21;
else if (NewPos == 44)
NewPos = 31;
else if (NewPos == 58)
NewPos = 43;
else if (NewPos == 64)
NewPos = 55;
else
NewPos = NewPos;
}
void CheckLadders ()
{
if (NewPos == 8)
NewPos = 16;
else if (NewPos == 12)
NewPos = 27;
else if (NewPos == 28)
NewPos = 39;
else if (NewPos == 33)
NewPos = 46;
else if (NewPos == 48)
NewPos = 55;
else if (NewPos == 59)
NewPos = 75;
else
NewPos = NewPos;
}
//working..
{
|
just what i have so far.. its real scattered looking..
idk if im going in the write direction or not.
NOTES: how will i keep the current position of each player at the beginning of each turn and move from that position?