LETS PLAY A GAME... decent into c++ madness.

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?
Last edited on
I'm very, very confused.

1 - you can't have the user enter anything but numbers for the name since you're storying player1 and player2 as ints. use std::string

2 - youre using a scope delimiter under CheckWin( ) before your mane while loop. Are you sure you want to do that? Do you understand what it is doing?

3 - your function definitions at the bottom of the file don't make any sense to me. I think what you want to do is have CheckWin( ) cal Turn( ) and Advance( ). Is that right?

make sure you read the c++ tutorial on this site the whole way through, it is very helpful
would i put them as
1
2
3
 
char player1
char player2

then?

i want everything to be done under the CheckWin:
i want the check win function to check to see if the player has reached 100, and also go through each of the players turn.... so inside the CheckWin it will call a function (for player 1) to Roll, another function to Move, another function to check snakes and to check ladders, and a final function to print the players position
I don't think you understand what functions are. Partly because of this, half of your program (everything after line 28) doesn't make any sense.
You have to rethink your logic completely. Start from the fact that checking if a player won, picking a random number, and advancing a player, are all entirely different and unrelated operations.
Also review your material on functions and their syntax.
Last edited on
i reentered my code:

can you not call functions within other functions?
can you not call functions within other functions?

Of course you can. int main() is a function, and you call function from there, don't you?

int checkladders (int NewPos2);
void printmove (int player, int movenumber, int pos, int result, int newpos);
int checkwin (int status, int player);

int main ()
{
srand(time(NULL)); t << "A";
}

{

else if

{
i
}

else

return status;
}[/code]



i
Last edited on
would i put it under the "HEADER" function??? like....

[code]void header()

??????????
Last edited on
im getting some crazy error messages... that i dont know what they are.....
We can't help you if that's as explicit as you're going to be.
Topic archived. No new replies allowed.