I'm working on Snake game. Although I have a little problem. I created enum with possible directions:
enum Direction{
n = 0, // north
e = 1, // east
s = 2, // south
w = 3 // west
};
And then I created a ChangeDirection() function, which basing on previous direction will change it. (For example, if you go to the right/east, you can't switch to left/west):
void ChangeDirection(char key){
switch (key){
case 'w':
if (Direction != 2)
Direction = 0;
break;
case 'd':
if (Direction != 3)
Direction = 1;
break;
case 's':
if (Direction != 0)
Direction = 2;
break;
case 'a':
if (Direction != 1)
Direction = 3;
break;
}
But my ifs clearly don't work; following error occurs:
Expected primary-expression before '!=' token
Anyone could help? How can I rearrange it to work? Why doesn't it work? Thanks!
Aucun commentaire:
Enregistrer un commentaire