Experimental Wire Like Game

A very simple console game that places and removes wires.
Not finished(organizing needed)!!

Controls:
Q W E
A S D
Move:ASDW
Place Wire:E
Remove Wire:Q

Bugs(Please Help):
-Wires that are connecting left-Bottom-Right/left-Top-Right stay fixed

Code(copy and paste):
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
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int wwh; //height
int www; //width
int posx;
int posy;
int w[1000][1000];//world data
int type[12];//types
int tedit;//mode
int optposy[1];

void drawworld();
void setup();
void optdrawtype();
void updatewires();

int main(int argc, char* argv[])
{
	setup();
	int k;
	drawworld();
loop:

	k=getch();
	cout << k;
	if(tedit==1)
	{
		if(k==100)
			posx=posx+1;

		if(k==97)
			if(posx>0)
			posx=posx-1;
		if(k==115)
			posy=posy+1;

		if(k==119)
			if(posy>0)
				posy=posy-1;
		if(k==101)
		{
				w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=250;
				updatewires();
		}
		if(k==113)
		{
			w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=0;
			updatewires();
		}
		if(k==102)
			updatewires();
		drawworld();
	}

	goto loop;
	return 0;
}
void drawworld()
{
	COORD T={0,0};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE ),T);
	int curr;
	int curr1;
	int cn;
	char c;
    for(curr=posy; curr<(wwh+posy); curr++)
	{
		for(curr1=posx; curr1<(www+posx); curr1++)
		{
			c=w[curr1][curr];
			if(curr1==((www+posx)-(www/2)-1))
				if(curr==((wwh+posy)-(wwh/2)))
					c=16;
			if(curr1==((www+posx)-(www/2)+1))
				if(curr==((wwh+posy)-(wwh/2)))
					c=17;
			cout << c;
			

		}
		cn=178;
		c=cn;
		cout << c;
		if(curr==posy) cout << "Type : " << type;
		if(curr==posy+1) cout << "C : Controlls";
		
		cout << endl;
	}
	return;
}

void setup()
{
	int curr;
	int curr1;
	cout << "Loading . . ." << endl;
	optposy[1]=0;
	cout << "Setting Up Types . . ." << endl;
	type[0]=179;
	type[1]=180;
	type[2]=191;
	type[3]=192;
	type[4]=193;
	type[5]=194;
	type[6]=195;
	type[7]=196;
	type[8]=197;
	type[9]=217;
	type[10]=218;
	type[11]=169;
	type[12]=170;
	cout << "Other . . ." << endl;

	tedit=1;
	posx=0;
	posy=0;
	www=60;
	wwh=24;
	for(curr=posy; curr<(wwh+posy); curr++)
		for(curr1=posx; curr1<(www+posx); curr1++)
			w[curr1][curr]=0;
	cout << "Done";
	return;
}

void updatewires()
{
	int curr;
	int curr1;
	    for(curr=posy; curr<(wwh+posy); curr++)
		{
			for(curr1=posx; curr1<(www+posx); curr1++)
			{
				if(w[curr1][curr]>0)
				{
				//none
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=250;
							}
				//bottom
				//bottom
				if(w[curr1][(curr+1)]>0)
					//top
					if(w[curr1][(curr-1)]==0)
						//right
						if(w[(curr1+1)][curr]==0)
							//left
							if(w[(curr1-1)][(curr)]==0)
							{
								w[curr1][curr]=type[0];
							}
				//top
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[0];
							}
				//bottom/top
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[0];
							}
				//right
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[7];
							}
				//right/bottom
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[10];
							}
				//right/top
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[3];
							}
				//right/bottom/top
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]==0)
							{
								w[curr1][curr]=type[6];
							}
				//left
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[7];
							}
				//left/bottom
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[2];
							}
				//left/top
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[9];
							}
				//all
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[8];
							}
				//top/left/right
				if(w[curr1][curr+1]==0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[4];
							}
				//left/bottom/top
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]>0)
						if(w[curr1+1][curr]==0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[1];
							}
				//left/right/bottom
				if(w[curr1][curr+1]>0)
					if(w[curr1][curr-1]==0)
						if(w[curr1+1][curr]>0)
							if(w[curr1-1][curr]>0)
							{
								w[curr1][curr]=type[5];
							}
				}
			}
		}
	return;
}
Last edited on
Don't really understand what I am supposed to do in this game. Does remind me of an Etch-A-Sketch, though. I'm able to add a dot, move it, and connect a line from there to another dot. Don't really know what I'm doing, but it is impressive.
Don't know if the program is doing things correctly or not, as it may be getting data that is different than you are trying to program into it.
1 - int type[12];//types
That means type[0] to type[11], yet you're initializing it with 13.
1
2
3
4
5
6
7
8
9
10
11
12
13
type[0]=179;
	type[1]=180;
	type[2]=191;
	type[3]=192;
	type[4]=193;
	type[5]=194;
	type[6]=195;
	type[7]=196;
	type[8]=197;
	type[9]=217;
	type[10]=218;
	type[11]=169;
	type[12]=170;


2 - int optposy[1];
That's pretty much the same as saying int optposy; since the array is set for 1, optposy[0] remember, arrays start at zero to 1 less than what you declare it to be. So, when you initialize optposy as optposy[1]=0;, the array is out of bounds

You could get some very strange reactions in this game if it tries accessing some of those memory locations.
Last edited on
<whitenite1>
You aren't really supposed to do any thing will this game yet. Im planning to implement pulses, but rewriting it before i do that to fix what you said was wrong.
Thanks i did not notice that.
Hi CLman94,

Just some style points:

1. You have a lot of global variables - try to avoid them.
2. You a goto - forget it even exists, use a while loop instead.
3. set your indenting to 4 spaces rather than 8 - much better I think. Maybe your formatting isn't coming through properly - not your fault possibly.
4. Consider putting this type of thing into functions:

1
2
3
4
5
6
//bottom/top
if(w[curr1][curr+1]>0)
    if(w[curr1][curr-1]>0)
	if(w[curr1+1][curr]==0)
	    if(w[curr1-1][curr]==0)
		{w[curr1][curr]=type[0];}




This should make your code much easier to read.

Can you do the above code with &&'s instead?
1
2
if(w[curr1][curr+1]>0) && (w[curr1][curr-1]>0) && (w[curr1+1][curr]==0) && (w[curr1-1][curr]==0)
    {w[curr1][curr]=type[0];}




5. You can declare & initialise an array like this:

 
type[] = {179, 180,191, 192, 193, 194, 195, 196, 197, 217, 218, 169, 170}


The compiler counts how many items are in the array.

HTH
Last edited on
Totally removed int optposy[1];
This is my code now:
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
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int wwh; //height
int www; //width
int posx;
int posy;
int w[1000][1000];//world data
int type[] = {179, 180,191, 192, 193, 194, 195, 196, 197, 217, 218, 169, 170};//types
int tedit;//mode

void drawworld();
void setup();
void optdrawtype();
void updatewires();

int main(int argc, char* argv[])
{
	setup();
	int k;
	drawworld();
loop:

	k=getch();
	cout << k;
	if(tedit==1)
	{
		if(k==100)
			posx=posx+1;

		if(k==97)
			if(posx>0)
			posx=posx-1;
		if(k==115)
			posy=posy+1;

		if(k==119)
			if(posy>0)
				posy=posy-1;
		if(k==101)
		{
				w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=250;
				updatewires();
		}
		if(k==113)
		{
			w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=0;
			updatewires();
		}
		if(k==102)
			updatewires();
		drawworld();
	}

	goto loop;
	return 0;
}
void drawworld()
{
	COORD T={0,0};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE ),T);
	int curr;
	int curr1;
	char c;
    for(curr=posy; curr<(wwh+posy); curr++)
	{
		for(curr1=posx; curr1<(www+posx); curr1++)
		{
			c=w[curr1][curr];
			if(curr1==((www+posx)-(www/2)-1))
				if(curr==((wwh+posy)-(wwh/2)))
					c=16;
			if(curr1==((www+posx)-(www/2)+1))
				if(curr==((wwh+posy)-(wwh/2)))
					c=17;
			cout << c;
			

		}
		c=178;
		cout << c;
		if(curr==posy) cout << "Type : " << type;
		if(curr==posy+1) cout << "C : Controlls";
		
		cout << endl;
	}
	return;
}

void setup()
{
	int curr;
	int curr1;
	cout << "Loading . . ." << endl;
	tedit=1;
	posx=0;
	posy=0;
	www=60;
	wwh=24;
	for(curr=posy; curr<(wwh+posy); curr++)
		for(curr1=posx; curr1<(www+posx); curr1++)
			w[curr1][curr]=0;
	cout << "Done";
	return;
}

void updatewires()
{
	int curr;
	int curr1;
	    for(curr=posy; curr<(wwh+posy); curr++)
		{
			for(curr1=posx; curr1<(www+posx); curr1++)
			{
				if(w[curr1][curr]>0)
				{
				//none
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 && w[curr1+1][curr]==0 && w[curr1-1][curr]==0) w[curr1][curr]=250;
				//bottom
				if(w[curr1][(curr+1)]>0 && w[curr1][(curr-1)]==0 && w[(curr1+1)][curr]==0 && w[(curr1-1)][(curr)]==0) w[curr1][curr]=type[0];
				//top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 && w[curr1+1][curr]==0 && w[curr1-1][curr]==0) w[curr1][curr]=type[0];
				//bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 && w[curr1+1][curr]==0 && w[curr1-1][curr]==0) w[curr1][curr]=type[0];
				//right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 && w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[7];
				//right/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 && w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[10];
				//right/top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 && w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[3];
				//right/bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 && w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[6];
				//left
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 && w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[7];
				//left/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 && w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[2];
				//left/top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 && w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[9];
				//all
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 && w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[8];
				//top/left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 && w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[4];
				//left/bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 && w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[1];
				//left/right/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 && w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[5];
				//left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 && w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[7];
				}
			}
		}
	return;
}
Last edited on
OK looks a bit better now - though still some issues:

You still have the goto loop - it looks like never ending. Use a while loop with some condition to end. Goto's are really really bad - don't use them ever!!

Indentation - still is a 8 chars. The code is 2 screens wide on my system. There is a sort of rule that says code shouldn't be more than 80 chars per line, this is so it fits in one screen, and can be printed easily. It is possible to "fold" you lines of code, just press enter and continue on the next line - doesn't make any difference to the compiler.

This is at least unnecessary:

1
2
3
void Myunction() {
return;
}


void means that the function doesn't return anything, so putting a return statement is meaningless.

You still have lots of global variables, I know it seems easier to do it this way, but it is bad form and can lead to all kinds of problems. At least put them in main, and send whichever ones are necessary to the functions. If you need to change the value of some of them, send a pointer or reference to the function, change the value in the function, the changed value of the variable will still be there in main().

With the if statements - if (conditional) expression. Put the expression part on it's own line.

These if statements could still be put into functions. The functions would be short (2 or 3 lines, if you fold them), but it will make the code easier to read.

With variables, it's a good idea to initialise them to something (even 0) when you declare them - it will save you one day. Uninitialised variables are one of the biggest source of errors. Your variables are OK, this is just a handy hint for the future.


Could tedit be a bool type?


Could all this code in main be in a switch statement? I am guessing you don't need to test each one, just select one value of k
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
if(k==100)
    posx=posx+1;

if(k==97)
    if(posx>0)
	posx=posx-1;

if(k==115)
	posy=posy+1;

if(k==119)
	if(posy>0)
		posy=posy-1;

if(k==101) {
	w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=250;
	updatewires();
}

if(k==113) {
	w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=0;
	updatewires();
}

if(k==102)
	updatewires();  //do you need baces here?
	drawworld();



Here is what the switch could look like;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
switch (k ) {
    case 100:
         posx=posx+1;
         break;
    case 97:
         if(posx>0)
	      posx=posx-1;
         break;
//etc
//etc
     default:
          //error processing here

}


Hope this helps
Goto's removed!!
A wire connection issue has been fixed.Yay
Not the size of to screens, I think :\.
Unnecessary return; removed.
And here's my code so far:
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
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int wwh=24; //height
int www=60; //width
int posx=0;
int posy=0;
int w[1000][1000];//world data
int type[] = {179, 180,191, 192, 193, 194,
				195, 196, 197, 217, 218, 169, 170};//types
int tedit=1;//mode

void drawworld();
void setup();
void optdrawtype();
void updatewires();

int main(int argc, char* argv[])
{
	setup();
	int k;
	drawworld();
	while(true){
		k=getch();
		if(tedit==1)
		{
			switch(k){
				case 100:
					posx=posx+1;
					break;
				case 97:
					if(posx>0)
						posx=posx-1;
					break;
				case 115:
					posy=posy+1;
					break;

				case 119:
					if(posy>0)
						posy=posy-1;
					break;
				case 101:
					w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=250;
					updatewires();
					break;
				case 113:
					w[((www+posx)-(www/2))][((wwh+posy)-(wwh/2))]=0;
					updatewires();
					break;
				case 102:
					updatewires();
					break;
				//default:
			}
			drawworld();
		}
	}
	return 0;
}
void drawworld()
{
	COORD T={0,0};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE ),T);
	int curr;
	int curr1;
	char c;
    for(curr=posy; curr<(wwh+posy); curr++)
	{
		for(curr1=posx; curr1<(www+posx); curr1++)
		{
			c=w[curr1][curr];
			if(curr1==((www+posx)-(www/2)-1) && curr==((wwh+posy)-(wwh/2)))
					c=16;
			if(curr1==((www+posx)-(www/2)+1) && curr==((wwh+posy)-(wwh/2)))
					c=17;
			cout << c;
			

		}
		c=178;
		cout << c;
		if(curr==posy) cout << "Type : n/a";
		if(curr==posy+1) cout << "C : n/a";
		cout << endl;
	}
}

void setup()
{
	int curr;
	int curr1;
	cout << "Loading . . ." << endl;
	for(curr=posy; curr<(wwh+posy); curr++)
		for(curr1=posx; curr1<(www+posx); curr1++)
			w[curr1][curr]=0;
	cout << "Done";
}

void updatewires()
{
	int curr;
	int curr1;
	    for(curr=posy; curr<(wwh+posy); curr++)
		{
			for(curr1=posx; curr1<(www+posx); curr1++)
			{
				if(w[curr1][curr]>0)
				{
				//none
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]==0)w[curr1][curr]=250;
				//left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[7];
				//bottom
				if(w[curr1][(curr+1)]>0 && w[curr1][(curr-1)]==0 &&
					w[(curr1+1)][curr]==0 && w[(curr1-1)][(curr)]==0) w[curr1][curr]=type[0];
				//top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]==0) w[curr1][curr]=type[0];
				//bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]==0) w[curr1][curr]=type[0];
				//right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[7];
				//right/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[10];
				//right/top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[3];
				//right/bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]==0) w[curr1][curr]=type[6];
				//left
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[7];
				//left/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[2];
				//left/top
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[9];
				//all
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[8];
				//top/left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[4];
				//left/bottom/top
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]>0 &&
					w[curr1+1][curr]==0 && w[curr1-1][curr]>0) w[curr1][curr]=type[1];
				//left/right/bottom
				if(w[curr1][curr+1]>0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[5];
				}
			}
		}
}

I have not tried it yet but return;
could be used to end the function before the last line.
Last edited on
OK, goto removed, however you have while(true){ which is an infinite loop - can you think of an ending condition to put there instead of (true)

With the indenting, you still have it at 8, can you set the tabs to be equal to 4 spaces, so it looks like this:

1
2
3
4
5
6
7
8
9
10
void updatewires()
{
    int curr;
    int curr1;

    for(curr=posy; curr<(wwh+posy); curr++)
	{
	for(curr1=posx; curr1<(www+posx); curr1++)
        {
            if(w[curr1][curr]>0)


With these if statements:

1
2
3
//left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					w[curr1+1][curr]>0 && w[curr1-1][curr]>0) w[curr1][curr]=type[7];


change it so the action to be carried out is on it's own line - you have done the others just missed these ones. Like this:

1
2
3
4
5
//left/right
				if(w[curr1][curr+1]==0 && w[curr1][curr-1]==0 &&
					     w[curr1+1][curr]>0 && w[curr1-1][curr]>0) 
                                       { w[curr1][curr]=type[7];
                                                      }


I put braces around single if statement action expressions as a defensive measure - even though they are unnecessary, it will save you one day when you add more code.

I have not tried it yet but return;
could be used to end the function before the last line.


That was why I suggested you remove them, the functions don't return anything, so this doesn't make sense.

Now, have you thought about how to not have all those global variables? I gave some clues earlier.

The default: label in the switch statement is to catch anything that doesn't match any of the other cases - usually some sort of error. So you should have some code there to handle that situation.

HTH
Last edited on
With the updatewires function:

The first condition is either w[curr1][curr+1]==0 or w[curr1][curr+1]>0

The second condition is either w[curr1][curr-1]==0 or w[curr1][curr-1]>0

The third condition is either w[curr1+1][curr]==0 or w[curr1+1][curr]>0

The fourth condition is either w[curr1-1][curr]==0 or w[curr1-1][curr]>0

Can you think of a better way of combining these tests? Hint put all the left ones together, all the right ones together etc.

Topic archived. No new replies allowed.