-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbles.c
More file actions
114 lines (98 loc) · 2.18 KB
/
Copy pathBubbles.c
File metadata and controls
114 lines (98 loc) · 2.18 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <windows.h>
#include <conio.h>
void gotoXY(int, int);
void bubble(char c[][140], int, int, int, int);
void hidecursor();
int main(void) {
hidecursor();
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, 0);
system("color F2");
char a[30][140];
int row = 26, column,no_of_bubbles;
gotoXY(25, 10);
printf("Enter no. of bubbles:");
gotoXY(25, 11);
scanf_s("%d", &no_of_bubbles);
int var = 10, up = 3, down = 3;
char q = '1';
gotoXY(90,37);
printf("Press Up/Down to change size");
while (1) {
hidecursor();
memset(a, ' ', 140*30 * sizeof(a[0][0]));
srand(var);
int temp_bubbles = no_of_bubbles;
for (temp_bubbles; temp_bubbles > 0; temp_bubbles--) {
column = rand() % 120 - up;
bubble(a, row, column, up, down);
}
row--;
if (_kbhit()) {
if (GetAsyncKeyState(VK_UP) && up<7) {
up++;
down++;
}
if (GetAsyncKeyState(VK_DOWN) && up>2) {
up--;
down--;
}
q = _getch();
if (q == '0') {
break;
}
}
if (row == 0 + up) {
row = row + 26;
}
if (row == 26 + up) {
var = var + 10;
}
for (int i = 0; i < 30; i++) {
gotoXY(10, 7 + i);
for (int j = 0; j < 140; j++) {
printf("%c", a[i][j]);
}
}
}
}
/*
Function taken from https://cboard.cprogramming.com/
to set cursor poistion
*/
void gotoXY(int x, int y) {
COORD coord = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
/*
Function to hide cursor
taken from https://stackoverflow.com/questions/30126490/how-to-hide-console-cursor-in-c
*/
void hidecursor()
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 10;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
/*
Function to create bubble at given row and column
with width a and length b
*/
void bubble(char c[][140], int row, int column, int a, int b) {
for (int r = column; r <= (column + a); r++)
{
for (int s = row; s >= (row - b); s--) {
if (s<row && s>(row - b)) {
if (r == column || r == (column + a))
c[s][r] = '.';
}
if (s == row || s == (row - b))
{
if (r > column && r < (column + a))
c[s][r] = '.';
}
}
}
}