help with this project please!

look under the options function and try to turn off the random colors... that is where the porblems are. i want to be able to turn off random colors within the game. here is the code, keep in mind, this is an annuedited, rough draft version, and not all parts have been implemented yet

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include"dos.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "windows.h"
#include<string>
using namespace std;

HANDLE hCon;
string menu_choice;
void options();// declare these up here so i can declare them in menu method and menu in these methods without any confusion...
void tutorial ();
void get_strings();
//anagram solvers from http://homepage.ntlworld.com/adam.bozon/anagramsolver.htm


char words[7];//character array for allo possible words. array used for counting points for indivisdual letters


string word_set;
int randnum; 
int difficulty = 1;//for difficulty 1-3
char rand_color_dis = 'n';//used in options, converts to bool though for easier computing... set to no for default
bool rand_color_disable;//to disable random color in case it gets annoying... which it porbably well... disable in options menu of game
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };

void SetColor(Color c){
        if(hCon == NULL)
                hCon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hCon, c);
}


void disable_color(bool rand_color_disable){
	if(rand_color_disable = false){
	SetColor(GRAY);

	}
	if (rand_color_disable = true){
	}
}

void load(){
	cout<<"Loading";
for(int i = 0;i <=2;i++){ //waits 3 seconds, just for cool loading effect....
	cout<<".";	
Sleep(1000);
}
system("cls");//clears screen after loading
}

void rand_color(){ // will set color to random color.... only in actual game, not menu screen, we need some consistency!!
	int rand_color = rand() % 14 + 1;//makes randum numbe from 1-15
	
	switch(rand_color){
	case 1:
		SetColor(DARKBLUE);
	break;
	case 2:
		SetColor(DARKGREEN);
	break;
	case 3:
		SetColor(DARKTEAL);
	break;
	case 4:
		SetColor(DARKRED);
	break;
	case 5:
		SetColor(DARKPINK);
	break;
	case 6:
		SetColor(DARKYELLOW);
	break;
	case 7:
		SetColor(GRAY);
	break;
	case 8:
		SetColor(DARKGRAY);
	break;
	case 9:
		SetColor(BLUE);
	break;
	case 10:
		SetColor(GREEN);
		case 11:
		SetColor(TEAL);
	break;
	case 12:
		SetColor(RED);
	break;
	case 13:
		SetColor(PINK);
	break;
	case 14:
		SetColor(YELLOW);
		break;
		case 15:
		SetColor(WHITE);
	break;
	}
	disable_color(rand_color_disable);
	
}

void menu(){
	 SetColor(GREEN);
cout<<"            TEXT TWIST"<<endl;
cout<<"\n \n  \n";
    SetColor(RED);
cout<<"            Play"<<endl;
cout<<endl;

    SetColor(YELLOW);
cout<<"            Options"<<endl;
cout<<endl;
        SetColor(TEAL);
cout<<"            Help"<<endl; //show tutorial here!!! with example and typing in using sleep
//in opstions allow difficulty to change, add more difficult sets as it increases!

cin>>menu_choice;
system("cls");

if(menu_choice =="Help" || menu_choice =="help"){


tutorial();


menu();
}
if(menu_choice =="Options" || menu_choice =="options"){
options();
}
}

void ready_load(){
	int i = 5;
	
	while(i>0){
cout<<"Ready in: "<<i;
i--;
Sleep(1000);
system("cls");

	}
}

void options(){
		
	int choice;

system("cls");
rand_color();
disable_color(rand_color_disable);

cout<<"1. RANDOM COLOR DISABLED:		"<<rand_color_dis<<endl;
cout<<endl;
cout<<"2. difficulty:		"<<difficulty<<" (1-3, 1- easiest, 3- hardest)"<<endl;
cout<<endl;
cout<<"3. Back"<<endl;
cout<<endl;
cout<<endl;

cout<<"Which would you like to change? ";
cin>> choice;



if (choice == 1){
	char rand_color_dis = 'y';//used in options, converts to bool though for easier computing... set to no for default
bool rand_color_disable =false;

system("cls");
options();

}

if(choice == 2){
	cout<<"Different levels of diifficulty are still being added... "<<endl;
}

if(choice == 3){
	system("cls");
	menu();

}

else{
	system("cls");
	options();
}






		}



void tutorial(){

    char answer[7] = {'m','a','i','l'};

	rand_color();//makes random color! This should be fun...
	disable_color(rand_color_disable);

system("cls");
cout<<"Welcome to the tutorial! This will show you how to play the game \n it will simulate a real game, please keep in mind \"//\" are \n instrucionts used only in the tutorial, not in the actual game!"<<endl;
	system("pause");//i know this is not supposed to be used but it is the only way. cin.get does not work when system("cls") is used right after
system("cls");

cout<<"Here are your first set of words: fmalie"<<endl;
Sleep(1000);
cout<<endl;
cout<<"//You Must type in all possible words! Like this:"<<endl;

Sleep(3000);
for(int i = 0;i <=7;i++){

Sleep(400);
cout<<answer[i];
}
cout<<"Correct! 400 points!"<<endl;
Sleep(1400);

system("cls");

cout<<"Here are your first set of words: fmalie"<<endl;
cout<<endl;
cout<<"//Here is another example:"<<endl;
Sleep(3000);
 char answer_1[7] = {'m','e'};
for(int j = 0;j <=7;j++){

Sleep(400);
cout<<answer_1[j];
}
cout<<"Correct! 200 points"<<endl;
Sleep(1400);
system("cls");

cout<<"Here are your first set of words: fmalie"<<endl;
cout<<endl;
cout<<"//Make sure you dont type in anything incorrect \n It will subtract from your points!"<<endl;
Sleep(3500);
char answer_2[7] = {'l','e','m','e'};
for(int c = 0;c <=7;c++){

Sleep(400);
cout<<answer_2[c];
}
cout<<"Incorrect, you have lost 50 points!"<<endl;
Sleep(3500);
system("cls");
rand_color();
cout<<"\n \n That is the end of the tutorial!\n \n The point system char: \n \n Letters		Points \n 2			200 \n 3		300 \n 4			400 \n 5			500 \n 6			600 \n 7			700 \n \n press enter to continue!";
	system("pause");//i know this is not supposed to be used but it is the only way. cin.get does not work when system("cls") is used right after
system("cls");


}







void intro(){
	char intro[90] = {'W','e','l','c','o','m','e',' ','T','o',' ','T','e','x','t',' ','T','w','i','s','t',' ','B','y',' ','*','*','*','*','*','*',' ','*','*','*','*','*'};

	for(int i = 0;i<=65;i++){

	
		if(i == 7 || i == 10 || i == 21) {
		cout<<"\n  \n";
		}
rand_color();
	cout<<intro[i];
	Sleep(75);
	}
	system("cls");
		load();
	}


void get_string(){

	
		
		randnum= rand() % 14 + 1;//fifteen possible numbers

		switch(randnum){
		case 1:
			word_set = "detraly";
			break;
			
			case 2:
			word_set = "zolefya";
			break;
			case 3:
			word_set = "yamilrw";
			break;
			case 4:
			word_set = "prtadg";
			break;
			case 5:
			word_set = "nemofoi";
			break;
			case 6:
			word_set = "tcvodil";
			break;
			case 7:
			word_set = "xoktre";
			break;
			
			case 8:
			word_set = "pyhltwi";
			break;
			case 9:
			word_set = "qutrilb";
			break;
			case 10:
			word_set = "zefihld";
			break;
			case 11:
			word_set = "eicldfm";
			break;
			case 12:
			word_set = "pilogva";
			break;
			case 13:
			word_set = "itghojs";
			break;
			case 14:
			word_set = "viofslb";
			break;
			case 15:
			word_set = "jouygln";
			break;
		}
		//EASY USE ARRAYS FOR EACH SET OF LETTERS FOR ALL POSSIBLE WORDS AND USE FOR LOOP TO SORT THROUGH
}


void begin_words(){
	rand_color();
	disable_color(rand_color_disable);
	cout<<"Here is your first set:";
get_string();
cout<<word_set<<endl;



}



char char_to_point(char *letter){//need to have defined array above because this methods serves to purposes:
return 0;
}



int main() {
	srand( time(0));//to make random num in get_string. if this is in the fuctino then it will return same num each time
rand_color_disable = true;


	intro();
menu();
system("cls");
ready_load();
begin_words();
system("pause");//pauses program, prevents from closing
return 0;
}
Last edited on
if you try to turn off the random colors, you will notice that it simply switches to a new random color... instead of gray like it is supposed to.
Line 39 and line 43. == is used for comparisons.

Turning your compiler's warning level up would probably be helpful, since most compiler's will warn for this if you let them.
ok thank you for replying, however that does not fix the random color problem i am currently having
It does bring your attention to those lines though. Your problem is the logic inside the same function.

Is color disabled when the parameter is true or false?




Last edited on
@ramus313

The fix I came up with, is
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
void options()
{
	int choice = 0, game_difficulty = 0;
	bool rand_color_disable = true;
	char rand_color_dis[2] = {'N','Y'};
	SetColor(RED); // Change to whatever color you wanted option menu, to be.
	disable_color(rand_color_disable);
	do
	{
		system("cls");
		cout << "1. RANDOM COLOR DISABLED: [" << rand_color_dis[rand_color_disable] << "]" <<endl << endl;
		cout << "2. difficulty:  [" << difficulty << "]" << endl <<endl; 
		cout << "3. Back  " << endl << endl <<endl;

		cout << "Which would you like to change? ";
		cin >> choice;

		if (choice == 1)
		{
			rand_color_disable = !rand_color_disable;
		}
		if(choice == 2)
		{
			cout << "Different levels of diifficulty are still being added... " << endl;
			cout << "Just for testing purposes, what difficulty do you wish?" << endl << endl;
			do
			{
			cout <<  "(1-3, 1- easiest, 3- hardest)" << endl;
			cin >> game_difficulty;
			if ( game_difficulty < 1 || game_difficulty> 3)
				cout << "That choice is NOT listed as a game option." << endl << endl;
			} while (game_difficulty <1 || game_difficulty > 3);
			difficulty = game_difficulty;

			Sleep(1500);
		}
		if(choice == 3)
		{
			system("cls");
			menu();
		}
	}while (choice!=3);
}


I was wondering about the same thing as cire was.
Last edited on
See, I didn't even see the options code. His problem there was simply masking the global rand_color_disable variable with a local one.

I don't really know why he bothered with a parameter in the definition of disable_color, since just accessing the global rand_color_disable variable would be more in-line with the overall style.

One of the problems with the option code is that a local variable named rand_color_disable is declared that masks the global rand_color_table that the rest of the program uses. Unfortunately, your fix makes the same mistake.

Last edited on
im sorry in my original code i dont see where i made the mistake of creating a local var with the same as the global one. which method is it under?

The Color is disabled when the disable color is false:

1
2
3
4
5
6
7
8
9
void disable_color(){
	if(rand_color_disable = false){
	SetColor(GRAY);

	}
	if (rand_color_disable = true){
	}
}



even added this to one of the times i called the random_color function:

1
2
3
4
5
if(rand_color_disable = true)
	rand_color();
	if(rand_color_disable = false)
	disable_color();


and it still didnt work!!!
Last edited on
Line 175. Find is your friend.

In this code:

1
2
3
4
5
6
7
8
void disable_color(){
	if(rand_color_disable = false){
	SetColor(GRAY);

	}
	if (rand_color_disable = true){
	}
}


rand_color_disable is set to false, then the body of the first if is skipped, because the result of evaluating rand_color_disable being set to false is always false. Then, rand_color_disable is set to true.

You really, really need to turn up your compiler's warning level.

1
2
3
4
5
6
7
void disable_color(){
	if(rand_color_disable == false){
	     SetColor(GRAY);
	}else {
	     // do other stuff here.
	}
}


The other code snippet you posted has the same problem. use == for equality comparison.
Last edited on
Topic archived. No new replies allowed.