Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <thread>
  4. #include <chrono>
  5. #include <Windows.h>
  6.  
  7. using namespace std::chrono_literals;
  8. using std::chrono::system_clock;//(for s,ms,min..)
  9.                                 //if using namespace std then using namespace chrono::system_clock
  10.  
  11.  
  12. char DrawArr[7][50];
  13. int Dx;
  14. int Dy;
  15.  
  16. void Draw() {
  17.     for (unsigned y = 0; y < 7; ++y) {
  18.         for (unsigned x = 0; x < 50; ++x) {
  19.             if (DrawArr[y][x] == '>') {
  20.                 Dx = x;
  21.                 Dy = y;
  22.             }
  23.             std::cout << DrawArr[y][x];
  24.         }
  25.         std::cout << std::endl;
  26.     }
  27. }
  28.  
  29. void Change() {
  30.     bool chck = true;
  31.     for (unsigned y = 0; y < 7; ++y) {
  32.         for (unsigned x = 0; x < 50; ++x) {
  33.             if (DrawArr[y][x] == '>' && chck) {
  34.                 DrawArr[y][x + 1] = '>';
  35.                 DrawArr[y][x] = '.';
  36.                 chck = false;
  37.             }
  38.         }
  39.         std::cout << std::endl;
  40.     }
  41. }
  42.  
  43. bool Move() {
  44.     if (GetAsyncKeyState(VK_UP)) {
  45.         DrawArr[Dy - 1][Dx] = '>';
  46.         DrawArr[Dy][Dx] = '.';
  47.     }
  48.     if (GetAsyncKeyState(VK_DOWN)) {
  49.         DrawArr[Dy + 1][Dx] = '>';
  50.         DrawArr[Dy][Dx] = '.';
  51.     }
  52.     if (DrawArr[Dy][Dx + 1] == '*')
  53.         return true;
  54.     return false;
  55. }
  56.  
  57.  
  58. int main() {
  59.  
  60.     srand(static_cast<unsigned int>(time(0)));
  61.  
  62.     bool start = true;
  63.     int counter = 0;
  64.     while (true) {
  65.  
  66.         if (start) {
  67.             for (unsigned y = 0; y < 7; ++y) {
  68.                 for (unsigned x = 0; x < 50; ++x) {
  69.                     if (x == 0 && y == 3)
  70.                         DrawArr[y][x] = '>';
  71.                     else if (x > 5&&x%3==0 && ((rand() % 4)) == 0)
  72.                         DrawArr[y][x] = '*';
  73.                     else
  74.                         DrawArr[y][x] = '.';
  75.                 }
  76.             }
  77.             start = false;
  78.         }
  79.         Draw();
  80.         if (GetAsyncKeyState)
  81.             if (Move())
  82.                 break;
  83.  
  84.         if (counter > 2) {
  85.             Change();
  86.             counter = 0;
  87.         }
  88.        
  89.        
  90.         ++counter;
  91.         std::this_thread::sleep_until(system_clock::now() + 100ms);
  92.         system("CLS");
  93.     }
  94.     system("CLS");
  95.     std::cout << "OIOIOIO You lose \n";
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement