Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <iomanip>
- #include <random>
- using namespace std;
- const double MIN_SALARY = 330.0;
- bool hasFinished = false;
- int average_speed = 0;
- int rand_frames = 0;
- void clearScreen();
- void movable_car(int speed_kmh, int allowed_speed_kmh);
- int main() {
- int car_speed = 0;
- int allowed_speed = 0;
- //int sanction = 0;
- cout << "Enter speed in km\\h: ";
- cin >> car_speed;
- cout << "Enter allowed speed in km\\h: ";
- cin >> allowed_speed;
- system("cls");
- movable_car(car_speed, allowed_speed);
- system("cls");
- hasFinished ? cout << "\nThe delivery has finished! | Average driver speed: " << average_speed / rand_frames << "km\\h" : cout << "The delivery guy crashed!";
- return 0;
- }
- void clearScreen()
- {
- HANDLE hOut;
- COORD Position;
- hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- Position.X = 0;
- Position.Y = 0;
- SetConsoleCursorPosition(hOut, Position);
- }
- void movable_car(int speed_kmh, int allowed_speed_kmh) {
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- unsigned int frames;
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
- frames = csbi.srWindow.Right - csbi.srWindow.Left + 1;
- srand (time(NULL));
- for (size_t i = 0; i < frames - 1; i++) {
- clearScreen();
- int random_int = rand() % (allowed_speed_kmh + speed_kmh);
- average_speed += random_int;
- rand_frames++;
- cout << setw(i - 5) << " .--------." << endl;
- cout << setw(i) << "___/_____|___ \\____" << endl;
- cout << setw(i + 1) << "* _ - | _ O" << endl;
- cout << setw(i) << "'--(_)-------(_)--'" << endl;
- cout << "\n\n" <<"Status: " << (hasFinished ? "Finished | " : "Driving | ") << random_int << "km\\h";
- Sleep(random_int);
- }
- hasFinished = !hasFinished;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement