|
@ -8,12 +8,12 @@ int kbhit(void); |
|
|
char getch(void); |
|
|
char getch(void); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*int main(int argc, char ** argv){ |
|
|
|
|
|
|
|
|
int main(int argc, char ** argv){ |
|
|
printf("wasd or arrows to control snake, q to quit, p to pause game."); |
|
|
printf("wasd or arrows to control snake, q to quit, p to pause game."); |
|
|
while(1){ |
|
|
while(1){ |
|
|
getInput(); |
|
|
getInput(); |
|
|
} |
|
|
} |
|
|
}*/ |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** getInput gets the userinput and reacts to input of w,a,s,d, arrow keys, p or q |
|
|
/** getInput gets the userinput and reacts to input of w,a,s,d, arrow keys, p or q |
|
|
* utilises getch() and kbhit, no parameters, no returns |
|
|
* utilises getch() and kbhit, no parameters, no returns |
|
@ -24,17 +24,20 @@ void getInput(){ |
|
|
if(key == '\033'){ |
|
|
if(key == '\033'){ |
|
|
getch(); |
|
|
getch(); |
|
|
char key = getch(); |
|
|
char key = getch(); |
|
|
if(key=='A'){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(key){ |
|
|
|
|
|
case 'A': |
|
|
printf("up"); |
|
|
printf("up"); |
|
|
} |
|
|
|
|
|
else if(key=='B'){ |
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
case 'B': |
|
|
printf("down"); |
|
|
printf("down"); |
|
|
} |
|
|
|
|
|
else if(key=='C'){ |
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
case 'C': |
|
|
printf("right"); |
|
|
printf("right"); |
|
|
} |
|
|
|
|
|
else if(key=='D'){ |
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
case 'D': |
|
|
printf("left"); |
|
|
printf("left"); |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|