Browse Source

refactoring:if-else for other input to switch for visibility

main
fdai7184 2 years ago
parent
commit
054f296503
  1. 30
      src/input.c

30
src/input.c

@ -8,12 +8,12 @@ int kbhit(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.");
while(1){
getInput();
}
}
}*/
/** 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
@ -24,7 +24,6 @@ void getInput(){
if(key == '\033'){
getch();
char key = getch();
switch(key){
case 'A':
printf("up");
@ -41,27 +40,30 @@ void getInput(){
}
}
else{
if(key=='w'){
switch(key){
case 'w':
printf("W");
}
else if(key=='a'){
break;
case 'a':
printf("A");
}
else if(key=='s'){
break;
case 's':
printf("S");
}
else if(key=='d'){
break;
case 'd':
printf("D");
}
else if(key=='q'){
break;
case 'q':
printf("quit");
}
else if(key=='p'){
break;
case 'p':
printf("\033[31mgame paused, p to continue");
printf("\033[0m");
pause();
printf("\033[32mgame continued");
printf("\033[0m");
break;
}
}

Loading…
Cancel
Save