Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <thread>
- #include <chrono>
- #include <Windows.h>
- using namespace std::chrono_literals;
- using std::chrono::system_clock;//(for s,ms,min..)
- //if using namespace std then using namespace chrono::system_clock
- char DrawArr[7][50];
- int Dx;
- int Dy;
- void Draw() {
- for (unsigned y = 0; y < 7; ++y) {
- for (unsigned x = 0; x < 50; ++x) {
- if (DrawArr[y][x] == '>') {
- Dx = x;
- Dy = y;
- }
- std::cout << DrawArr[y][x];
- }
- std::cout << std::endl;
- }
- }
- void Change() {
- bool chck = true;
- for (unsigned y = 0; y < 7; ++y) {
- for (unsigned x = 0; x < 50; ++x) {
- if (DrawArr[y][x] == '>' && chck) {
- DrawArr[y][x + 1] = '>';
- DrawArr[y][x] = '.';
- chck = false;
- }
- }
- std::cout << std::endl;
- }
- }
- bool Move() {
- if (GetAsyncKeyState(VK_UP)) {
- DrawArr[Dy - 1][Dx] = '>';
- DrawArr[Dy][Dx] = '.';
- }
- if (GetAsyncKeyState(VK_DOWN)) {
- DrawArr[Dy + 1][Dx] = '>';
- DrawArr[Dy][Dx] = '.';
- }
- if (DrawArr[Dy][Dx + 1] == '*')
- return true;
- return false;
- }
- int main() {
- srand(static_cast<unsigned int>(time(0)));
- bool start = true;
- int counter = 0;
- while (true) {
- if (start) {
- for (unsigned y = 0; y < 7; ++y) {
- for (unsigned x = 0; x < 50; ++x) {
- if (x == 0 && y == 3)
- DrawArr[y][x] = '>';
- else if (x > 5&&x%3==0 && ((rand() % 4)) == 0)
- DrawArr[y][x] = '*';
- else
- DrawArr[y][x] = '.';
- }
- }
- start = false;
- }
- Draw();
- if (GetAsyncKeyState)
- if (Move())
- break;
- if (counter > 2) {
- Change();
- counter = 0;
- }
- ++counter;
- std::this_thread::sleep_until(system_clock::now() + 100ms);
- system("CLS");
- }
- system("CLS");
- std::cout << "OIOIOIO You lose \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement