Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Use A, S, D, and W to move the icon
- * across the grid.
- */
- #include <cstdio>
- #include <cstdlib>
- #include <conio.h>
- #define width 10
- void printmap(char grid[][width],int h,int w);
- void fill(char grid[][width],int h,int w,char c);
- char map[10][width];
- int main() {
- fill(map,10,10,'.');
- map[1][1]='0';
- printmap(map,10,10);
- int x=1,y=1;
- while (true) {
- map[x][y]='.';
- int i;
- while (i==0) {
- i=kbhit();
- }
- char c=getch();
- switch (c) {
- case 97: //ascii a
- if (y==1) {y=10;} else {y--;}
- break;
- case 115: //ascii s
- if (x==10) {x=1;} else {x++;}
- break;
- case 100: //ascii d
- if (y==10) {y=1;} else {y++;}
- break;
- case 119: //ascii w
- if (x==1) {x=10;} else {x--;}
- break;
- }
- map[x][y]='0';
- system("cls");
- printmap(map,10,10);
- }
- system("pause>nul");
- return 0;
- }
- void printmap(char grid[][width],int h,int w) {
- for (int i=1;i<=h;i++) {
- for (int j=1;j<=w;j++) {
- printf("%c",grid[i][j]);
- }
- printf("\n");
- }
- }
- void fill(char grid[][width],int h,int w,char c) {
- for (int i=1;i<=h;i++) {
- for (int j=1;j<=w;j++) {
- grid[i][j]=c;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement