ahmed0saber

Using array as a map for a moving character in C++

Nov 13th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4. int main()
  5. {
  6.     char move;
  7.     int map[3][3]={{0,0,0},{0,1,0},{0,0,0}},x=1,y=1;
  8.     cout<<"\t\t\tUse the arrows to move\n\n";
  9.     while(true)
  10.     {
  11.         cout<<"\t\t\t\t|"<<map[0][0]<<"|"<<map[0][1]<<"|"<<map[0][2]<<"|\n\t\t\t\t|"<<map[1][0]<<"|"<<map[1][1]<<"|"<<map[1][2]<<"|\n\t\t\t\t|"<<map[2][0]<<"|"<<map[2][1]<<"|"<<map[2][2]<<"|\n\n\n\n\n\n";
  12.         move=getch();
  13.         map[x][y]=0;
  14.         if(move==72&&x>0)
  15.         {x--;}
  16.         if(move==80&&x<2)
  17.         {x++;}
  18.         if(move==75&&y>0)
  19.         {y--;}
  20.         if(move==77&&y<2)
  21.         {y++;}
  22.         map[x][y]=1;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment