Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. #include <conio.h>
  5. using namespace std;
  6.  
  7. char mapa[10][10];
  8. char key;
  9. int a=4,b=5;
  10. void RysujMape()
  11. {
  12.     system("cls");
  13.     for (int i=0;i<10;i++)
  14.     {
  15.         for (int j=0;j<20;j++)
  16.         {
  17.             mapa[i][j]='p';
  18.         }
  19.     }
  20.     cout<<" --------------------"<<endl;
  21.     for (int i=0;i<10;i++)
  22.     {
  23.         cout<<"|";
  24.         for (int j=0;j<20;j++)
  25.         {
  26.             if (mapa[i][j]=='p')
  27.                 cout<<" ";
  28.             if (i==a && j==b)
  29.             {
  30.                 mapa[a][b]='g';
  31.                 cout<<"@";
  32.             }
  33.         }
  34.         cout<<"|"<<endl;
  35.     }
  36.     cout<<" --------------------"<<endl;
  37. }
  38.  
  39. void Ruch()
  40. {
  41.     switch(key)
  42.     {
  43.     case 'w':
  44.         mapa[a][b]='p';
  45.         a-=1;b=b;
  46.         mapa[a-1][b]='g';
  47.         RysujMape();
  48.     break;
  49.  
  50.     case 's':
  51.         mapa[a][b]='p';
  52.         a+=1;b=b;
  53.         mapa[a+1][b]='g';
  54.         RysujMape();
  55.     break;
  56.     case 'a':
  57.         mapa[a][b]='p';
  58.         a=a;b-=1;
  59.         mapa[a][b-1]='g';
  60.         RysujMape();
  61.     break;
  62.     case 'd':
  63.         mapa[a][b]='p';
  64.         a=a;b+=1;
  65.         mapa[a][b+1]='g';
  66.         RysujMape();
  67.     break;
  68.     }
  69. }
  70.  
  71. int main()
  72. {
  73.     RysujMape();
  74.     for(;;)
  75.     {
  76.     key=getch();
  77.     Ruch();
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement