Check out Yahtzee

Hi all. I had the source code up a few days ago, but took it down when I decided to improve the looks of the game. Hopefully, some of you will D/L the code, compile it and let me know where improvements can be made, or errors you find.

Thanks for any feedback..

NOTE.. Removed from dropbox
https://www.dropbox.com/s/rjy7x313gia4x1z/yahtzee.cpp?dl=0
Last edited on
Your code doesn't compile. Did you forget some parts. ?
VS 2017 CE
Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0725	name must be a namespace name	Yaahtzee	main.cpp	40
Error (active)	E0276	name followed by '::' must be a class or namespace name	Yaahtzee		104
Error	C2871	'System': a namespace with this name does not exist	Yaahtzee		40
Error	C2653	'Console': is not a class or namespace name	Yaahtzee		104
Error	C3861	'SetWindowSize': identifier not found	Yaahtzee		104

Warning	C4456	declaration of 'High_Scores' hides previous local declaration	Yaahtzee		789
Warning	C4244	'argument': conversion from 'int' to 'WORD', possible loss of data	Yaahtzee		1097
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1102
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1103
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1109
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1110
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1117
Warning	C4244	'=': conversion from 'int' to 'SHORT', possible loss of data	Yaahtzee		1118
Warning	C4459	declaration of 'console' hides global declaration	Yaahtzee		1282
You have to change some settings on Visual Studio for the code to compile. I ran the code uploaded before this one, but I didn't comment since I don't know how to play Yahtzee.
I haven't tried to compile it because I don't use VS, but here are some comments based on reading the code.

General:
- You frequently pass the Players, names, die, and titles around as parameters. Consider storing these in a Yahtzee class and making some (all?) of the functions methods of the class.
- It's probably not worth changing here, but for future projects, consider separating the code that plays the game from the code that implements the user interface. So you'd have a Yahtzee class that just plays the game and records the results, and a separate UI class that displays the state of the game, gets user input, and calls the appropriate Yahtzee members to move the game alone.
- More comments! For example, most of the code is drawing the game. You might add some comments saying which part you're drawing.

- Lines 114-117. Call Load_Scores() before the loop and remove starting.
- Line 260: The code for Up/Down and Left/Right are nearly identical. Can you pull those out into a function and where the differences are the parameters?
- Liens 961, 1002, 1020: Make Style static so it doesn't get created each time the function is called. The three Style arrays appear to be the same, which is another to have a Yahtzee and/or UI class: you can make it a static member of the class and have just one copy.
@dhayden

Lines 114-117. Call Load_Scores() before the loop and remove starting.


Moved line and removed bool starting

Lines 961, 1002, 1020: Make Style static


Sounds good. Thanks

More comments! For example, most of the code is drawing the game. You might add some comments saying which part you're drawing.


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
void Yahtzee_Screen(string titles[13])
{
	string Yahtzee="YAHTZEE", Totals[4] = {"     Left Side","Bonus (over 62)","    Right Side","   Grand Total"};
	int len = Yahtzee.length();
	for(int x=0;x<len;x++) // cout the game title one letter at a time, spaced apart
	{
		gotoXY(33+(x*2),2);
		cout <<Yahtzee[x];
		Sleep(400);
	}

	Box(1, 6, 3, 12,  3, black on light_cyan, 1 , dark_gray); // Box to place player's name
	Box(1, 6, 5, 60, 28, black on light_cyan, 1 , dark_gray); // Box to place left & right score boxes
	gotoXY( 9, 4,"Player");
	gotoXY(6,5,"\xC3"); // Join top two boxes
	gotoXY(17,5,"\xC1");//     ""
	Box(1,10,6,25,13,black,light_yellow, 1 , dark_cyan); // Box for left scores - 1 thru 6 die values
	BoxLineDown(1,28,6,13); // Divide word labels from scores
	for( int x=0; x<6;x++)
	{		
		gotoXY(11, 7+(x*2), titles[x]);
		if(x<5)
		{
			BoxLineAcross(1,10,8+(x*2),25);
			gotoXY(28,8+(x*2),"\xC5");
		}
	}
	Box(1,37,6,25,15,black,light_yellow, 1 , dark_cyan); //Box for right scores - 3of a kind, four of a kind, etc.
	BoxLineDown(1,55,6,15);  // Divide word labels from scores
	for( int x=0; x<7;x++)
	{
		gotoXY(38, 7+(x*2), titles[x+6]);
		if(x<6)
		{
			BoxLineAcross(1,37,8+(x*2),25);
			gotoXY(55,8+(x*2),"\xC5");
		}
	}
	Box(1,10,20, 8,3,black,light_yellow, 1 , dark_cyan); // Box to place 'Total' for scorese
	Box(1,10,22,25,9,black,light_yellow, 1 , dark_cyan); // Box for left, right scores and gran total
	gotoXY(10,22,"\xC3"); // Join top two boxes
	gotoXY(17,22,"\xC1"); //         "
	gotoXY(11,21,"Totals");
	BoxLineDown(1,28,22,9); // Divide word labels from scores
	for( int x=0; x<4;x++)
	{
		gotoXY(12, 23+(x*2), Totals[x]);
		if(x<3)
		{
			BoxLineAcross(1,10,24+(x*2),25);
			gotoXY(28,24+(x*2),"\xC5");
		}
	}
}


making some (all?) of the functions methods of the class.


Not sure how to do this, as I've never attempted it.
Not sure how to do this, as I've never attempted it.

http://www.cplusplus.com/doc/tutorial/classes/
Hi all. I was hoping to be informed if there were improvements to the way the game actually played, or ?? Was a bit disappointed in only getting responses for changes to the coding which really didn't change the way it played or looked. I'll call this solved though it wasn't in reality.
Topic archived. No new replies allowed.