Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include<Windows.h>
  2. #include<iostream>
  3. #include<conio.h>
  4. using namespace std;
  5. void Design(char Mat[][80])
  6. {
  7.     for (int c = 0; c < 80; c++)
  8.     {
  9.         Mat[0][c] = 205;
  10.         Mat[23][c] = 205;
  11.     }
  12.     for (int r = 1; r < 23; r++)
  13.     {
  14.         for (int i = 1; i < 80 - 1; i++)
  15.         {
  16.             Mat[r][i] = ' ';
  17.         }
  18.     }
  19.     for (int r = 1; r < 23; r++)
  20.     {
  21.         Mat[r][0] = 186;
  22.     }
  23.     Mat[0][0] = 201;
  24. }
  25. void Display(char Mat[][80])
  26. {
  27.     system("cls");
  28.     for (int r = 0; r < 24; r++)
  29.     {
  30.         for (int c = 0; c < 80; c++)
  31.         {
  32.             cout << Mat[r][c];
  33.         }
  34.         cout << endl;
  35.     }
  36.     cout.flush();
  37.     Sleep(100);
  38. }
  39. void SetEnemy(char Mat[][80], int RE, int CE)
  40. {
  41.     Mat[RE][CE] = 1;
  42.     Mat[RE + 1][CE] = '|';
  43.     Mat[RE + 2][CE] = '|';
  44.     Mat[RE + 3][CE - 1] = '/';
  45.     Mat[RE + 3][CE + 1] = '\\';
  46. }
  47. void SetHero(char Mat[][80], int RH, int CH)
  48. {
  49.     Mat[RH][CH] = 2;
  50.     Mat[RH + 1][CH] = 219;
  51.     Mat[RH + 2][CH] = 219;
  52. }
  53. void MoveEnemy(int &RE, int &CE)
  54. {
  55.     CE++;
  56. }
  57. void MoveHero(int &RH, int &CH, char k)
  58. {
  59.     if (k == 'a')
  60.     {
  61.         CH--;
  62.     }
  63.     if (k == 'd')
  64.     {
  65.         CH++;
  66.     }
  67.     if (k == 'w')
  68.     {
  69.         RH--;
  70.     }
  71.     if (k == 's')
  72.     {
  73.         RH++;
  74.     }
  75. }
  76. void main()
  77. {
  78.     char Mat[24][80];
  79.  
  80.     int RE = 5;
  81.     int CE = 12;
  82.  
  83.     int RH = 10;
  84.     int CH = 20;
  85.     while (true)
  86.     {
  87.         while (!_kbhit())
  88.         {
  89.             Design(Mat);
  90.             MoveEnemy(RE, CE);
  91.             SetEnemy(Mat, RE, CE);
  92.             SetHero(Mat, RH, CH);
  93.  
  94.             Display(Mat);
  95.         }
  96.         Design(Mat);
  97.         MoveEnemy(RE, CE);
  98.         SetEnemy(Mat, RE, CE);
  99.  
  100.         char k = _getch();
  101.         MoveHero(RH, CH, k);
  102.         SetHero(Mat, RH, CH);
  103.  
  104.         Display(Mat);
  105.     }
  106.     system("pause");
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement