- #include <stdio.h>
- int main(int argc, const char * argv[])
- {
- char c = 0;
- char c1 = 0;
- int x = 1;
- while (x)
-
- {
- printf("请输入W.A.S.D,w.上,a.左,s.下,d.右\n");
- rewind(stdin);
-
- scanf("%c",&c);
-
- while (c!=0&&c!='w'&&c!='a'&&c!='s'&&c!='d'&&c!='W'&&c!='A'&&c!='S'&&c!='D'&&c!='q'&&c!='Q')
- {
-
- printf("按要求重新输入\n");
- rewind(stdin);
- scanf("%c",&c);
-
- }
- if (c=='w'||c=='W')
- {
- printf("向上走\n");
- rewind(stdin);
- }
- else if (c=='a'||c=='A')
- {
- printf("向左走\n");
- rewind(stdin);
- }
- else if (c=='s'||c=='S')
- {
- printf("向下走\n");
- rewind(stdin);
- }
- else if (c=='d'||c=='D')
- {
- printf("向右走\n");
- rewind(stdin);
- }
- else if (c=='q'||c=='Q')
- {
-
- printf("程序即将结束,请确认? Y确认,输入任意不退出\n");
- rewind(stdin);
-
- scanf("%c",&c1);
-
- if (c1 == 'y'||c1=='Y')
- {
- printf("程序以退出\n");
- x--;
- }
-
- }
-
-
- }
-
- return 0;
- }
复制代码 |