-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.cpp
More file actions
59 lines (48 loc) · 1.26 KB
/
Copy pathball.cpp
File metadata and controls
59 lines (48 loc) · 1.26 KB
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
#include <iostream>
#include <string>
// #include "ball.hpp"
#include <windows.h>
using namespace std;
#define DELAY 10000000L
#define CLS (cout << "\033[2J");
/* i liked this CLS part */
#define LOCATE(z, s) (cout << "\033[" << z << ';' << s << 'H')
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
int main(){
int x = 2,
y = 3,
dx = 1,
speed = 0;
string floor(79, '-'), header = "--- jumping ball ---";
/* the required block */
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
GetConsoleMode(hOut, &dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hOut, dwMode);
CLS;
LOCATE(1, 25);
cout << header;
LOCATE(25, 1);
cout << floor;
while(1){
LOCATE(y, x); cout << 'o' << endl;
for (long wait = 0; wait < DELAY; ++wait)
;
/* gotta be both false */
if (x == 1 || x == 79)
dx = -dx;
if (y == 24){
speed = -speed;
if (speed == 0) speed = -7;
}
Sleep(1);
speed += 1;
LOCATE(y, x); cout << ' ';
y += speed; x += dx;
}
return 0;
}
/* i thought this was going to be a little interactive
-- but i was wrong
edit -- this does work */