Hi, I'm nearly finished on this little project (a maze game) I've been working on, but have come up against a stumbling block. I'll try to explain it the best I can without just posting all of the code.
Right, it all started with a simple few IF statements in the key function:
Code:
#define PLAYER '@'
#define MONSTER '#'
#define EMPTY ' '
#define OWALL '£'
#define IWALL '&'
void keyTest()
{
.......
.......
while(!done)
{
switcher = _getch();
switch(switcher)
{
case UPKEY:
if(board[x][y - 1] == OWALL)
break;
if(board[x][y - 1] == EXIT)
{
system("CLS");
gotoxy(70, 25);
printf("YOU WIN!!!");
done = TRUE;
_getch();
break;
}
if(board[x][y - 1] == MONSTER)
{
system("CLS");
gotoxy(70, 25);
printf("YOU LOSE!!!");
done = TRUE;
_getch();
break;
}
else
{
board[x][y] = EMPTY;
printf("%c", EMPTY);
y--;
board[x][y] = PLAYER;
gotoxy(x, y);
printf("%c", PLAYER);
}
break;
.......
.......
}
The board[x][y] is a char array that I'm using to try and randomly generate content (instead of drawing ASCII art in a text file and using a pointer).
Now the problem I had there was that the collision detection wasn't really performing and was detecting a monster hit when I was nowhere near it. I eventually figured that because I was using gotoxy for the screen positioning, the array co-ordinates were different from the values of X and Y.
To get around this, I used this:
Code:
void initBoard()
{
.......
.........
for(i = 0 ; i< XRES; i++)
{
for(j = 0; j< YRES; j++)
{
if((board[i][j]) == PLAYER)
{
x = i;
y = j;
}
}
}
.....
.......
}
The next problem was passing X and Y from the initBoard function into the keyTest function. Long story short, my main function looked like this:
Code:
int main(void)
{
conWindow();
/* Seed rand */
srand(time(NULL));
title();
initBoard();
gotoxy(2, 2);
keyTest();
return 0;
}
which meant that I had to not only pass a value into the keyTest function from the initBoard function, but also had to give it another value from main. This was messing up my program.
So my somewhat contrived solution was to pass the values from the initBoard function, into the main function, then from there into the keyTest function, which I achieved like this:
Code:
void initBoard()
{
.......................................
main(&x, &y);
..................
}
//////////////////////////////////////////////////////////
int main(int *ref, int *ref2)
{
.........
ref = &x;
ref2 = &y;
keyTest(&ref,&ref2);
.........
}
/////////////////////////////////////////////////////
void keyTest(int *pass, int *pass2)
{
..........
x = &pass;
y = &pass2;
..........
}
As you can probably tell, now I'm just really confused and I know that has to be a better way of doing this but can't think of a way around it.
NOTE: The ............... inside the code is to signify that there is more code there, but I'm not sure that it's relevant.
Any help/comments/musings would be greatly appreciated.
Thanks
SM