-
Notifications
You must be signed in to change notification settings - Fork 1
/
sastantua.c
executable file
·128 lines (117 loc) · 3.09 KB
/
sastantua.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sastantua.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madonis <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/25 15:13:02 by madonis #+# #+# */
/* Updated: 2018/09/25 15:13:08 by madonis ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
int base_ln_len(int size, int floor_num)
{
int alpha;
int beta;
if (floor_num == size)
return (1);
alpha = 4;
beta = floor_num;
while (beta <= size)
{
if ((floor_num % 2 == 0) && (beta % 2 == 1))
alpha += 4;
else if (floor_num % 2 == 0)
alpha += 2;
else if ((floor_num % 2 == 1) && (beta % 2 == 1))
alpha += 2;
else
alpha += 4;
beta++;
}
return (base_ln_len(size, floor_num + 1) + alpha);
}
void build_line(int length, int offset, int door_size, int door_knob)
{
int l;
int d_s;
l = length;
d_s = door_size;
while (--offset >= 0)
ft_putchar(' ');
ft_putchar('/');
if (door_size == 0)
while (--length >= 0)
ft_putchar('*');
else
{
while (--length >= ((l - door_size) / 2 + door_size))
ft_putchar('*');
while (--d_s >= 0)
if (door_knob && door_size > 3 && d_s == 1)
ft_putchar('$');
else
ft_putchar('|');
while (--length >= door_size - 1)
ft_putchar('*');
}
ft_putchar('\\');
ft_putchar('\n');
}
void build_floor_with_door(int size, int floor_num, int lvls, int length)
{
int offset;
int base_offset;
int door_size;
base_offset = ((base_ln_len(size, 1) - base_ln_len(size, floor_num)) / 2);
door_size = size;
if (size % 2 == 0)
door_size--;
while (--lvls > 0)
{
offset = base_offset + lvls - 7 + ((floor_num + 5));
if (lvls > door_size)
build_line(length, offset, 0, 0);
else
{
if ((door_size / 2) == (door_size - lvls))
build_line(length, offset, door_size, 1);
else
build_line(length, offset, door_size, 0);
}
length += 2;
}
}
void build_floor(int size, int floor_num)
{
int levels;
int offset;
int length;
int base_offset;
levels = 3 + (size - floor_num);
length = base_ln_len(size, floor_num);
base_offset = ((base_ln_len(size, 1) - base_ln_len(size, floor_num)) / 2);
while (levels > 0)
{
offset = base_offset + levels - 7 + ((floor_num + 5));
build_line(length, offset, 0, 0);
levels--;
length += 2;
}
}
void sastantua(int size)
{
int floor_num;
int volume;
int length;
floor_num = size;
while (floor_num > 1)
{
build_floor(size, floor_num);
floor_num--;
}
volume = 4 + (size - floor_num);
length = base_ln_len(size, floor_num);
build_floor_with_door(size, floor_num, volume, length);
}