Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions C++/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// DVD Logo simulator in C++ (terminal based)
// Jobega was here

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

const int SCREEN_WIDTH = 80;
const int SCREEN_HEIGHT = 25;

class DVDSimulator {
public:
DVDSimulator() : x(0), y(0), xSpeed(1), ySpeed(1) {}

void move() {
x += xSpeed;
y += ySpeed;

if (x <= 0 || x >= SCREEN_WIDTH - 1) {
xSpeed = -xSpeed;
}

if (y <= 0 || y >= SCREEN_HEIGHT - 1) {
ySpeed = -ySpeed;
}
}

void display() const {
system("clear");
for (int i = 0; i < y; ++i) {
cout << endl;
}
for (int i = 0; i < x; ++i) {
cout << ' ';
}
cout << "DVD" << endl;
}

private:
int x, y;
int xSpeed, ySpeed;
};

int main() {
srand(static_cast<unsigned>(time(nullptr)));
DVDSimulator dvd;

while (true) {
dvd.move();
dvd.display();
for (int i = 0; i < 1000000; ++i) {
}
}

return 0;
}