# someone who is good at finding and fixing bugs?

• 06-06-2002
elfjuice
someone who is good at finding and fixing bugs?
i need some help... im make a game where you can walk around and there are trees and stuff... here is my code so far...

Code:

```#include <iostream> #include <stdlib.h> #include <conio.h> #include <stdio.h> #define SPACE  32 int main() {   int map[9][9];   map[1][1] = 1;   map[1][2] = SPACE;   map[1][3] = 6;   map[1][4] = 6;   map[1][5] = 6;   map[1][6] = 6;   map[1][7] = 6;   map[1][8] = 6;   map[1][9] = SPACE;   map[1][10] = SPACE;   map[1][11] = SPACE;   map[1][12] = SPACE;   map[1][13] = 178;   map[2][1] = SPACE;   map[2][2] = SPACE;   map[2][3] = 6;   map[2][4] = 6;   map[2][5] = 6;   map[2][6] = 6;   map[2][7] = 6;   map[2][8] = 6;   map[2][9] = SPACE;   map[2][10] = SPACE;   map[2][11] = 6;   map[2][12] = SPACE;   map[2][13] = 178;   map[3][1] = SPACE;   map[3][2] = 6;   map[3][3] = 6;   map[3][4] = 6;   map[3][5] = 6;   map[3][6] = 6;   map[3][7] = 6;   map[3][8] = 6;   map[3][9] = 6;   map[3][10] = 6;   map[3][11] = 6;   map[3][12] = SPACE;   map[3][13] = 178;   int whereToGo;   int x = 1;   int y = 1;   do{   if(whereToGo == 80)   {   if(map[y + 1][x] == 6)   {     }   else   {   map[y][x] = SPACE;   y++;   map[y][x] = 1;   }   }   if(whereToGo == 72)   {   if(map[y - 1][x] == 6)   {     }   else   {   map[y][x] = SPACE;   y--;   map[y][x] = 1;   }   }   if(whereToGo == 77)   {   if(map[y][x + 1] == 6)   {     }   else   {   map[y][x] = SPACE;   x++;   map[y][x] = 1;   }   }   if(whereToGo == 75)   {   if(map[y][x - 1] == 6)   {     }   else   {   map[y][x] = SPACE;   x--;   map[y][x] = 1;   }   }   putchar(map[1][1]);   putchar(map[1][2]);   putchar(map[1][3]);   putchar(map[1][4]);   putchar(map[1][5]);   putchar(map[1][6]);   putchar(map[1][7]);   putchar(map[1][8]);   putchar(map[1][9]);   putchar(map[1][10]);   putchar(map[1][11]);   putchar(map[1][12]);   putchar(map[1][13]);   cout << "\n";   putchar(map[2][1]);   putchar(map[2][2]);   putchar(map[2][3]);   putchar(map[2][4]);   putchar(map[2][5]);   putchar(map[2][6]);   putchar(map[2][7]);   putchar(map[2][8]);   putchar(map[2][9]);   putchar(map[2][10]);   putchar(map[2][11]);   putchar(map[2][12]);   putchar(map[2][13]);   cout << "\n";   putchar(map[3][1]);   putchar(map[3][2]);   putchar(map[3][3]);   putchar(map[3][4]);   putchar(map[3][5]);   putchar(map[3][6]);   putchar(map[3][7]);   putchar(map[3][8]);   putchar(map[3][9]);   putchar(map[3][10]);   putchar(map[3][11]);   putchar(map[3][12]);   putchar(map[3][13]);   whereToGo = getch();   system("cls");   }while(whereToGo != 27);   return 0; }```
if you look at that code... you probebly see what im trying to do... but i need a good way to loop and show the map.. please help.
• 06-06-2002
elfjuice
OH!!!!! nevermind... I got it!!
• 06-06-2002
elfjuice
I have another problem now...

Code:

```#include <iostream> #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <windows.h> #define SPACE  32 using namespace std; int main() {   int map[50][50];   map[1][1] = 1;   map[1][2] = SPACE;   map[1][3] = 6;   map[1][4] = 6;   map[1][5] = 6;   map[1][6] = 6;   map[1][7] = 6;   map[1][8] = 6;   map[1][9] = SPACE;   map[1][10] = SPACE;   map[1][11] = SPACE;   map[1][12] = SPACE;   map[1][13] = 221;   map[2][1] = SPACE;   map[2][2] = SPACE;   map[2][3] = 6;   map[2][4] = 6;   map[2][5] = 6;   map[2][6] = 6;   map[2][7] = 6;   map[2][8] = 6;   map[2][9] = SPACE;   map[2][10] = SPACE;   map[2][11] = 6;   map[2][12] = SPACE;   map[2][13] = 221;   map[3][1] = SPACE;   map[3][2] = 6;   map[3][3] = 6;   map[3][4] = 6;   map[3][5] = 6;   map[3][6] = 6;   map[3][7] = 6;   map[3][8] = 6;   map[3][9] = 6;   map[3][10] = 6;   map[3][11] = 6;   map[3][12] = SPACE;   map[3][13] = 221;   map[4][1] = SPACE;   map[4][2] = SPACE;   map[4][3] = 6;   map[4][4] = SPACE;   map[4][5] = 6;   map[4][6] = SPACE;   map[4][7] = SPACE;   map[4][8] = 6;   map[4][9] = 6;   map[4][10] = 6;   map[4][11] = 6;   map[4][12] = SPACE;   map[4][13] = 221;   map[5][1] = SPACE;   map[5][2] = SPACE;   map[5][3] = SPACE;   map[5][4] = SPACE;   map[5][5] = SPACE;   map[5][6] = SPACE;   map[5][7] = SPACE;   map[5][8] = 6;   map[5][9] = 6;   map[5][10] = 6;   map[5][11] = 6;   map[5][12] = SPACE;   map[5][13] = 221;   map[6][1] = 6;   map[6][2] = SPACE;   map[6][3] = SPACE;   map[6][4] = SPACE;   map[6][5] = SPACE;   map[6][6] = 12;   map[6][7] = SPACE;   map[6][8] = SPACE;   map[6][9] = SPACE;   map[6][10] = SPACE;   map[6][11] = SPACE;   map[6][12] = SPACE;   map[6][13] = 221;   map[7][1] = 6;   map[7][2] = 6;   map[7][3] = SPACE;   map[7][4] = 5;   map[7][5] = SPACE;   map[7][6] = 176;   map[7][7] = 176;   map[7][8] = 176;   map[7][9] = 176;   map[7][10] = SPACE;   map[7][11] = SPACE;   map[7][12] = SPACE;   map[7][13] = 186;   int whereToGo;   int x = 1;   int y = 1;   int money = 100;   HANDLE h;   h = GetStdHandle ( STD_OUTPUT_HANDLE );   do{   if(whereToGo == 80)   {   if(map[y + 1][x] != SPACE)   {     }   else   {   map[y][x] = SPACE;   y++;   map[y][x] = 1;   }   }   if(whereToGo == 72)   {   if(map[y - 1][x] != SPACE)   {     }   else   {   map[y][x] = SPACE;   y--;   map[y][x] = 1;   }   }   if(whereToGo == 77)   {   if(map[y][x + 1] != SPACE)   {     }   else   {   map[y][x] = SPACE;   x++;   map[y][x] = 1;   }   }   if(whereToGo == 75)   {   if(map[y][x - 1] != SPACE)   {     }   else   {   map[y][x] = SPACE;   x--;   map[y][x] = 1;   }   }   /* Draw Map */   putchar(218);   for(int i = 0; i < 14; i++)   putchar(196);   putchar(191);   cout << "\n";   for(int i = 0; i < 8; i++)   {   putchar(179);   for(int j = 0; j < 14; j++)   {   if(map[i][j] == 6)   {   SetConsoleTextAttribute ( h, FOREGROUND_GREEN );   putchar(map[i][j]);   SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );   }   else   {   putchar(map[i][j]);   }   }   putchar(179);   cout << "\n";   }   putchar(192);   for(int i = 0; i < 14; i++)   putchar(196);   putchar(217);   /* Draw Map End */   whereToGo = getch();   system("cls");   }while(whereToGo != 27);   return 0; }```
it works pretty good... but when you move... it skips and stuff... i need a better function to erase everything than system("cls")!

Any ideas?
• 06-06-2002
Imperito
You might try iterating through the set, and iff a value is different, gotoxy() there and change it. That way you would only update those values that needed updating.

Additionally, your programming style is somewhere between unspeakable and horrific, you might consider applying some objective thinking in order to make your code more elegant, and more readable.

A vector of vectors of structs containing enums and mutable bools, for example, would make your map much more elegant, and would not impose a significant overhead.
• 06-06-2002
frenchfry164
It would also be cleaner if you used loops instead of typing all that stuff out, it will be heck to debug that, very ugly, and ugh, that is horrifying.

I wish I still had my bookmark to the structured programming site, it had a lot of useful stuff you need.
• 06-06-2002
elfjuice
Quote:

Originally posted by Imperito
You might try iterating through the set, and iff a value is different, gotoxy() there and change it. That way you would only update those values that needed updating.

Additionally, your programming style is somewhere between unspeakable and horrific, you might consider applying some objective thinking in order to make your code more elegant, and more readable.

A vector of vectors of structs containing enums and mutable bools, for example, would make your map much more elegant, and would not impose a significant overhead.

dont be too hard on me... this is my first week of c++... ;)

i dont know what vector of vectors of structs containing enums and mutable bools are!!

can you give me an example of how i shoudl do it? because i do not understand what you mean
• 06-07-2002
elfjuice
"Bump"
• 06-07-2002
Imperito
Well, a few notes then:

1) Find an IDE that indents for you, or develop the habit of using a consistant indentatrion scheme. Doesn't seem that important now, but when your wndproc() gets five or six levels deep, you will see why this is important.

2) Remember that everything in C++ begins at 0 and goes to n-1. I noticed in your use of a built in array, you started counting at [1][1]. You really ought to be starting ar [0][0].

//Gotta go, post again later
• 06-07-2002
elfjuice
ok... thanks... can you give me an example of how my game engine should be? and would it be hard if the levels were txt files and my game read them?
thanks