-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
249 lines (223 loc) · 5.67 KB
/
util.c
File metadata and controls
249 lines (223 loc) · 5.67 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include <stdlib.h>
#include <stdio.h>
# include <termios.h>
# include <unistd.h>
#include "rpg42.h"
int linux_kbhit(void);
void go_next(void)
{
printf("\n (n)뒤로 가기\n");
}
void input_error(void){
int kb = 0;
while (1)
{
print_header();
printf(" error(입력 오류) : 올바른 값을 입력해 주세요.\n\n\n\n");
go_next();
print_footer();
kb = linux_kbhit();
if (kb == 'n')
break ;
}
}
void print_title(void){
int kb = 0;
while (!kb){
print_header();
printf("\n\n");
printf(" _______ _______ ______ __ __ ______ \n");
printf(" | \\ | \\ / \\ | \\ | \\ / \\ \n ");
printf(" | $$$$$$$\\| $$$$$$$\\| $$$$$$\\ | $$ | $$| $$$$$$\n");
printf(" | $$__/ $$| $$__| $$| $$ __\\$$ | $$__| $$ \\$$__| $$\n");
printf(" | $$ $$| $$ $$| $$| \\ | $$ $$ / $$\n");
printf(" | $$$$$$$ | $$$$$$$\\| $$ \\$$$$ \\$$$$$$$$| $$$$$$ \n");
printf(" | $$ | $$| $$| $$__| $$ | $$| $$_____ \n");
printf(" | $$ | $$| $$ \\$$ $$ | $$| $$ \\\n");
printf(" \\$$ \\$$ \\$$ \\$$$$$$ \\$$ \\$$$$$$$$\n");
printf("\n\n");
print_footer();
printf("press any key to start!");
kb = linux_kbhit();
}
}
char select_charictor(void){
char chrtype;
int kb = 0;
while (1)
{
print_header();
printf(" 캐릭터를 선택해 주세요.\n");
printf("\n");
printf(" ------------------------------------------------------------------------\n\n\n");
printf(" a) 전공자 : 컴퓨터공학과를 다녀 컴퓨터 관련 지식을 상당히 가지고 있음\n\n");
printf(" b) 비전공자 : 비전공자로 컴퓨터 공부를 처음 한다\n\n\n");
printf(" ------------------------------------------------------------------------\n");
print_footer();
printf("\n\n\n");
printf(" 입력(a or b) :");
kb = linux_kbhit();
if (kb == 'a' || kb == 'b')
{
print_header();
if (kb == 'a')
{
printf("\n '전공자'캐릭터를 선택하셨습니다.\n");
chrtype = 'a';
}
else if (kb == 'b')
{
printf("\n '비전공자'캐릭터를 선택하셨습니다.\n");
chrtype = 'b';
}
print_footer();
sleep(1);
return (chrtype);
}
else
input_error();
}
}
int linux_kbhit(void)
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
// switch(day){
// case monday:
// break ;
// case thesday:
// // 선택지 함수
// break ;
// case weekend:
// // 함수
// break ;
// default :
// break;
// }
int use_action_point(t_user *user)
{
int use = 0;
while (1)
{
print_header();
printf("\n\n 남은 행동력 : %d\n\n", user->status->activ_point);
printf(" 사용할 행동력 : ");
scanf("%d", &use);
if (use > user->status->activ_point || use < 0)
input_error();
else
{
user->status->activ_point -= use;
return use;
}
printf("\n\n\n\n");
print_footer();
}
return (0);
}
int basic_information_key(int kb, t_user *user)
{
if (kb == 's')
print_user_status(user);
else if (kb == 'i')
print_item(user);
else if (kb == 'e')
print_equip(user);
else if (kb == 'w')
print_work(user);
return kb;
}
static size_t ft_count_strs(char const *s, char c)
{
size_t i;
i = 0;
while (*s)
{
if (*s != c && *s)
{
while (*s != c && *s)
s++;
i++;
}
else
s++;
}
return (i);
}
static size_t ft_count_chars(char const *s, char c)
{
size_t i;
i = 0;
while (s[i] != c && s[i])
i++;
return (i);
}
static char const *ft_next_strs(char const *s, char c, int i)
{
if (i == 0)
while (*s && *s == c)
s++;
else
while (*s && *s != c)
s++;
return (s);
}
static char **ft_free_strs(char **strs)
{
size_t i;
i = 0;
while (strs[i])
{
free(strs[i]);
strs[i++] = 0;
}
free(strs);
return (0);
}
char **ft_split(char const *s, char c)
{
size_t i;
size_t num_strs;
char **ptrs;
if (!s)
return (0);
i = 0;
num_strs = ft_count_strs(s, c) + 1;
ptrs = (char **)calloc(num_strs, sizeof(char *));
if (!ptrs)
return (0);
while (i + 1 < num_strs)
{
s = ft_next_strs(s, c, 0);
ptrs[i] = (char *)calloc(ft_count_chars(s, c) + 1, sizeof(char));
if (!ptrs[i])
return (ft_free_strs(ptrs));
strlcpy(ptrs[i++], s, ft_count_chars(s, c) + 1);
s = ft_next_strs(s, c, 1);
}
return (ptrs);
}
int ask_exit(t_user *user, t_event_day *day)
{
int kb = 0;
while (1)
{
print_screen(user, day, "집에 가시겠습니까?", "집에 간다,집에 안간다");
kb = linux_kbhit();
basic_information_key(kb, user);
if (kb == 'z')
return (1);
else if (kb == 'x')
return (0);
else if (kb == 'n')
return (0);
}
}