-
Notifications
You must be signed in to change notification settings - Fork 1
/
framer.cpp
100 lines (93 loc) · 1.76 KB
/
framer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <time.h>
using namespace std;
#define WIDTH 20
#define HEIGHT 20
bool board[WIDTH][HEIGHT];
bool lefttoright = true;
void clearBoard () {
for (int h = 0; h < HEIGHT; h++) {
for (int w = 0; w < WIDTH; w++) {
board[w][h] = false;
}
}
}
void draw () {
for (int a = 0; a != 5; a++) {
cout << "\n";
}
for (int h = 0; h < HEIGHT; h++) {
for (int w = 0; w < WIDTH; w++) {
if (board[w][h] == true) {
cout << '*';
}
else {
cout << '.';
}
cout << "\n";
}
}
}
void logic () {
bool previous_board[WIDTH][HEIGHT];
if (lefttoright == true) {
for (int h = 0; h < HEIGHT; h++) {
for (int w = 0; w < WIDTH; w++) {
previous_board[w][h] = board[w][h];
}
}
}
else {
for (int h = HEIGHT; h < 0; h--) {
for (int w = WIDTH; w < 0; w--) {
previous_board[w][h] = board[w][h];
}
}
}
clearBoard();
if (lefttoright == true) {
for (int h = 0; h < HEIGHT; h++) {
for (int w = 0; w < WIDTH; w++) {
if (previous_board[w][h] == true) {
if (w+1 < WIDTH) {
board[w+1][h] = true;
}
else {
lefttoright = false;
}
}
}
}
}
else {
for (int h = HEIGHT; h > 0; h--) {
for (int w = WIDTH; w > 0; w--) {
if (previous_board[w][h] == true) {
if (w-1 > 0) {
board[w-1][h] = true;
}
else {
lefttoright = false;
}
}
}
}
}
}
void sleep () {
int milisec = 500; // length of time to sleep, in miliseconds
struct timespec req = {0};
req.tv_sec = 0;
req.tv_nsec = milisec * 1000000L;
nanosleep(&req, (struct timespec *)NULL);
}
int main () {
clearBoard ();
board[0][HEIGHT/2] = true;
while(true) {
draw ();
logic ();
sleep ();
}
return 0;
}