Need help guys, any input will be greatly appreciated!
4 posters
RUSES :: Part 1 :: Programming :: Coursework
Page 1 of 1
Need help guys, any input will be greatly appreciated!
Hey guys,
Just want to say that I'm a terrible programmer, I can understand the purpose of all the elements we have learnt over the module this year, why they work and why we use them, but when it comes to implementing them and making them all work together I'm more than useless.
So i have been adapting the code I had already had working to try and add some more interesting features to my maze game. Whilst doing this though I've managed to balls everything up.
I have my maze to be displayed as:
And my player movement function and check function as:
But neither of the if statements i have attempted stop the player from passing straight through the walls. I would've thought the parts checking whether the space is a # would accomplish this. Is there a better way to do it? I know it will have to be some kind of comparative test used with a logical operator to ensure all the conditions are met, but i have most likely been using the wrong data type throughout and there is no means of comparing such things.
You guys are all so much better at programming than i am, and i just don't have the right kind of mind for it (more of an engineer) i would appreciate any help i can get, anything that would make me realise what I've done wrong and why it is wrong so that i can learn from it would be just fantastic.
thank you so much
Catch
Just want to say that I'm a terrible programmer, I can understand the purpose of all the elements we have learnt over the module this year, why they work and why we use them, but when it comes to implementing them and making them all work together I'm more than useless.
So i have been adapting the code I had already had working to try and add some more interesting features to my maze game. Whilst doing this though I've managed to balls everything up.
I have my maze to be displayed as:
- Code:
char map[15][40]=// maze design within array
{
"#######################################",
"#P # # #",
"######## ### ########## ## ############",
"# # # # # # #",
"# ### ############ ###### ######### ##",
"# #",
"#################################### ##",
"# # # #",
"#### ################## ## #### ## #",
"# # # F # # # #",
"# # ####### ############ ######## #",
"# # # # # #",
"## ### ### ### ################ #######",
"# # #",
"#######################################"
};
And my player movement function and check function as:
- Code:
//=============| User Input Function |=============
char enter()
{
char move;
do
{
cout << "W(up), S(down), A(left), D(right)" << endl;
cin >> move;
} while ((move != 'W') && (move != 'w') && (move != 'S') && (move != 's')
&& (move != 'A') && (move != 'a') && (move != 'D') && (move != 'd'));
return move;
}
//=============| Player Movement Within Array |=============
void Pmove(char move, char map[15][40], int *ud, int *rl)
{
if (((move == 'W') || (move == 'w')) && (map[15][40] != '#'))
{
(*ud)--;
}
if (((move == 'S') || (move == 's')) && (map[15][40] != '#'))
{
(*ud)++;
}
if (((move == 'D') || (move == 'd')) && (map[15][40] != '#'))
{
(*rl)++;
}
if (((move == 'A') || (move == 'a')) && (map[15][40] != '#'))
{
(*rl)--;
}
}
//=============| Check Movement is within the Array |=============
void check(int *rowP, int *colP)
{
if (((*rowP) <= -1) || ((*rowP) == '#'))
{
(*rowP)++ ;
};
if (((*rowP) >= 15) || ((*rowP) == '#'))
{
(*rowP)--;
};
if (((*colP) <= -1) || ((*colP) == '#'))
{
(*colP)++;
};
if (((*colP) >= 40) || ((*colP) == '#'))
{
(*colP)--;
};
}
But neither of the if statements i have attempted stop the player from passing straight through the walls. I would've thought the parts checking whether the space is a # would accomplish this. Is there a better way to do it? I know it will have to be some kind of comparative test used with a logical operator to ensure all the conditions are met, but i have most likely been using the wrong data type throughout and there is no means of comparing such things.
You guys are all so much better at programming than i am, and i just don't have the right kind of mind for it (more of an engineer) i would appreciate any help i can get, anything that would make me realise what I've done wrong and why it is wrong so that i can learn from it would be just fantastic.
thank you so much
Catch
Re: Need help guys, any input will be greatly appreciated!
I just had a brief look at my programming sucks too but I think the if statement still goes if there is a #. Try != '#' in the if statement
ie
if (((*rowP) <= -1) || ((*rowP) != '#'))
ie
if (((*rowP) <= -1) || ((*rowP) != '#'))
lee- Posts : 22
Join date : 2012-02-23
Re: Need help guys, any input will be greatly appreciated!
Thanks Lee,
Still no success, I've tried it with the OR, AND and NOT operators but no combination seems to work
So frustrating!
Catch
Still no success, I've tried it with the OR, AND and NOT operators but no combination seems to work
So frustrating!
Catch
Re: Need help guys, any input will be greatly appreciated!
when you do this bit, you aren't checking the space in the array you're moving to, should be something like :if (((move == 'W') || (move == 'w')) && (map[15][40] != '#'))
if (((move == 'W') || (move == 'w')) && (map]*ud]]*rl] != '#'))
but then you're still only checking the current space you're in, not the space being moved to.
mine works by moving, checking it and then moving back if it's wrong, hope this helps. we're in g46 atm now though if you are getting uber stuck
Last edited by ElliottH on Sun Mar 18, 2012 2:29 am; edited 1 time in total (Reason for editing : fixed coloured bits)
ElliottH- Admin
- Posts : 16
Join date : 2012-02-23
Re: Need help guys, any input will be greatly appreciated!
coloured bits messed up a bit there but it should be
(map[*ud][*rl] != '#')
(map[*ud][*rl] != '#')
ElliottH- Admin
- Posts : 16
Join date : 2012-02-23
Re: Need help guys, any input will be greatly appreciated!
- Code:
(((move == 'W') || (move == 'w')) && (map[15][40] != '#'))
- Code:
void check(int *rowP, int *colP)
E.g.
- The first function moves the player into a place by incrementing the array, but the display isn't updated yet so you don't see you've moved.
- The check function sees if the new space is allowed, i.e. is it a monster, is it a wall, etc.
- If the conditions aren't met it undoes the increment and moves the player back to where he was.
- Then the display is updated.
Problem is that it doesn't recognise the wall as not allowed, you can pass straight through it. I don't know why though. Probably because the walls are chars and the comparison operators only work on numbers? I'm not sure...
Been here for ages, i must've tried everything.
Thanks man
Catch
Re: Need help guys, any input will be greatly appreciated!
ahhh yours is confusingg, pointers and other scary bits, sorry i cant help
here is mine:
this is just the movement for up, and the movecheck function
here is mine:
- Code:
char move;
move = getch();
if (move == 'w')
{
playerY--;
if (movecheck() == 0)
{
cout << "Can't move through walls!" << endl;
playerY++;
return 0;
}
else if (movecheck() == 2)
{return 1;}
else
{
tempprev = tempnow;
tempnow = maps[playerY][playerX];
maps[playerY][playerX] = 'O';
maps[playerY + 1][playerX] = tempprev;
return 0;
}
}
int levels::movecheck()
{
if (maps[playerY][playerX] == '#')
{return 0;}
else if (maps[playerY][playerX] == 'E')
{return 2;}
else
{return 1;}
}
this is just the movement for up, and the movecheck function
ElliottH- Admin
- Posts : 16
Join date : 2012-02-23
Re: Need help guys, any input will be greatly appreciated!
I think the problem with moving and then checking is that # character will already have been replaced by the player, so when you're calling your
function it doesn't see the # it sees the P and so it doesn't do anything. It would probably be better to check if the space you're trying to move into is free and then move into it, as opposed to moving then checking.
It looks like you've already tried to do that with your
checks, and that doesn't work at the moment because you're checking the map[15][40] character to see if it's a # as opposed to the character you're trying to move to. Something roughly like the following should work instead:
- Code:
void check(int *rowP, int *colP)
function it doesn't see the # it sees the P and so it doesn't do anything. It would probably be better to check if the space you're trying to move into is free and then move into it, as opposed to moving then checking.
It looks like you've already tried to do that with your
- Code:
if (((move == 'W') || (move == 'w')) && (map[15][40] != '#'))
checks, and that doesn't work at the moment because you're checking the map[15][40] character to see if it's a # as opposed to the character you're trying to move to. Something roughly like the following should work instead:
- Code:
if (((move == 'W') || (move == 'w')) && (map[*rowP-1][*colP] != '#'))
// by subtracting 1 to the current row value you're
// checking to see that the space above is available
Charlie- Posts : 16
Join date : 2012-02-23
Re: Need help guys, any input will be greatly appreciated!
Thanks man,
I think you might be onto something there, it should work i just need to get the right variables in the right places..
Thanks so much
if anyone else has any ideas I'm still willing to hear them
Catch
I think you might be onto something there, it should work i just need to get the right variables in the right places..
Thanks so much
if anyone else has any ideas I'm still willing to hear them
Catch
Re: Need help guys, any input will be greatly appreciated!
Didn't quite work but I'm gonna get Karsten (the legend) to have a look at some point
RUSES :: Part 1 :: Programming :: Coursework
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum