-
Notifications
You must be signed in to change notification settings - Fork 2
/
wasd.c
68 lines (49 loc) · 860 Bytes
/
wasd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int a[10][10];
int i,j;
void display(int, int);
int main(){
int endLoop = 0;
char c;
i = 5;
j = 5;
display(5,5);
while(endLoop == 0){
c = getch();
switch(c){
case 'w':
i -= 1;
display(i,j);
break;
case 'a':
j -= 1;
display(i,j);
break;
case 's':
i += 1;
display(i,j);
break;
case 'd':
j += 1;
display(i,j);
break;
case ';':
endLoop = 1;
break;
}
}
}
void display(int ipos, int jpos){
int i,j;
system("cls");
for(i = 0; i < 10; i++){
for(j = 0; j < 10; j++){
if(i == ipos && j == jpos) printf("1");
else printf(".");
}
printf("\n");
}
printf("\nPress W A S D to move, and ; to exit\n");
}