Browse Source

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

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

50
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'){
printf("W");
}
else if(key=='a'){
printf("A");
}
else if(key=='s'){
printf("S");
}
else if(key=='d'){
printf("D");
}
else if(key=='q'){
printf("quit");
}
else if(key=='p'){
printf("\033[31mgame paused, p to continue");
printf("\033[0m");
pause();
printf("\033[32mgame continued");
printf("\033[0m");
switch(key){
case 'w':
printf("W");
break;
case 'a':
printf("A");
break;
case 's':
printf("S");
break;
case 'd':
printf("D");
break;
case 'q':
printf("quit");
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