質問編集履歴
1
記載する関数を増やしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,13 +58,155 @@
|
|
58
58
|
|
59
59
|
|
60
60
|
|
61
|
+
【display_info.h】
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
typedef struct{
|
66
|
+
|
67
|
+
char col ;
|
68
|
+
|
69
|
+
char row ;
|
70
|
+
|
71
|
+
} myposition_t;
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
【extern.h】
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
#include "macro.h"
|
82
|
+
|
83
|
+
#include "display_info.h"
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
extern void draw_pic(char display[DISPLAYROWMAX][DISPLAYCOLMAX]);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
/************************************/
|
92
|
+
|
93
|
+
/* initialize.c */
|
94
|
+
|
95
|
+
/************************************/
|
96
|
+
|
97
|
+
extern char initialize_main(char display[DISPLAYROWMAX][DISPLAYCOLMAX], myposition_t *position);
|
98
|
+
|
99
|
+
// extern char initialize_top(char display[DISPLAYROWMAX][DISPLAYCOLMAX]);
|
100
|
+
|
101
|
+
/************************************/
|
102
|
+
|
103
|
+
/* move.c */
|
104
|
+
|
105
|
+
/************************************/
|
106
|
+
|
107
|
+
// extern char move_right(mypositon_t *position);
|
108
|
+
|
109
|
+
// extern char move_left(myposition_t *position);
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
【macro.h】
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
#define DISPLAYCOLMAX (71)
|
120
|
+
|
121
|
+
#define DISPLAYROWMAX (200)
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
|
61
127
|
【invider.c】
|
62
128
|
|
63
129
|
```
|
64
130
|
|
131
|
+
#include <stdio.h>
|
132
|
+
|
133
|
+
#include <termios.h>
|
134
|
+
|
135
|
+
#include <unistd.h>
|
136
|
+
|
137
|
+
#include <fcntl.h>
|
138
|
+
|
139
|
+
#include "inc/extern.h"
|
140
|
+
|
65
141
|
#include "inc/display_info.h"
|
66
142
|
|
67
|
-
|
143
|
+
#include "inc/macro.h"
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
/****************************************************************/
|
150
|
+
|
151
|
+
/* WindowsのkbhitはLinuxでは使えないため、termios機能を使用する */
|
152
|
+
|
153
|
+
/* kbhit関数はネットのを引用 */
|
154
|
+
|
155
|
+
/****************************************************************/
|
156
|
+
|
157
|
+
int kbhit(void){
|
158
|
+
|
159
|
+
struct termios oldt, newt;
|
160
|
+
|
161
|
+
int ch;
|
162
|
+
|
163
|
+
int oldf;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
tcgetattr(STDIN_FILENO, &oldt);
|
168
|
+
|
169
|
+
newt = oldt;
|
170
|
+
|
171
|
+
newt.c_lflag &= ~(ICANON | ECHO);
|
172
|
+
|
173
|
+
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
174
|
+
|
175
|
+
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
176
|
+
|
177
|
+
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
ch = getchar();
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
186
|
+
|
187
|
+
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
if (ch != EOF) {
|
192
|
+
|
193
|
+
ungetc(ch, stdin);
|
194
|
+
|
195
|
+
return 1;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
return 0;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
/*****************************************************************/
|
206
|
+
|
207
|
+
/* メイン関数 */
|
208
|
+
|
209
|
+
/*****************************************************************/
|
68
210
|
|
69
211
|
int main(void){
|
70
212
|
|
@@ -82,7 +224,7 @@
|
|
82
224
|
|
83
225
|
|
84
226
|
|
85
|
-
initialize_main(display, &position);
|
227
|
+
initialize_main(display, &position);
|
86
228
|
|
87
229
|
|
88
230
|
|
@@ -94,7 +236,41 @@
|
|
94
236
|
|
95
237
|
switch(inputkey){
|
96
238
|
|
97
|
-
|
239
|
+
/* case 'l':
|
240
|
+
|
241
|
+
result = move_right(&position);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
if(result == 1){
|
246
|
+
|
247
|
+
continue;
|
248
|
+
|
249
|
+
}else{
|
250
|
+
|
251
|
+
break ;
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
case 'h':
|
258
|
+
|
259
|
+
result = move_left(&position);
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
if(result == 1){
|
264
|
+
|
265
|
+
continue;
|
266
|
+
|
267
|
+
}else{
|
268
|
+
|
269
|
+
break;
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
*/
|
98
274
|
|
99
275
|
case 'q':
|
100
276
|
|
@@ -118,18 +294,110 @@
|
|
118
294
|
|
119
295
|
}
|
120
296
|
|
297
|
+
|
298
|
+
|
299
|
+
void draw_pic(char display[DISPLAYROWMAX][DISPLAYCOLMAX]){
|
300
|
+
|
301
|
+
char loopcnt_row ;
|
302
|
+
|
303
|
+
char loopcnt_col ;
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
for(loopcnt_row = 0; loopcnt_row < DISPLAYROWMAX; loopcnt_row++){
|
308
|
+
|
309
|
+
for(loopcnt_col = 0; loopcnt_col < DISPLAYCOLMAX; loopcnt_col++){
|
310
|
+
|
311
|
+
printf("%s",display[loopcnt_row][loopcnt_col]);
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
121
|
-
```
|
319
|
+
```
|
122
|
-
|
320
|
+
|
321
|
+
|
322
|
+
|
123
|
-
【
|
323
|
+
【initialize.c】
|
124
|
-
|
324
|
+
|
125
|
-
```
|
325
|
+
```
|
326
|
+
|
126
|
-
|
327
|
+
#include <stdio.h>
|
328
|
+
|
329
|
+
#include "inc/macro.h"
|
330
|
+
|
331
|
+
#include "inc/display_info.h"
|
332
|
+
|
333
|
+
#include "inc/extern.h"
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
char initialize_main(char display[DISPLAYROWMAX][DISPLAYCOLMAX],
|
338
|
+
|
127
|
-
|
339
|
+
myposition_t *position){
|
340
|
+
|
128
|
-
|
341
|
+
char loopcnt_row ;
|
342
|
+
|
129
|
-
|
343
|
+
char loopcnt_col ;
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
130
|
-
|
349
|
+
position->col = 34;
|
350
|
+
|
351
|
+
position->row = DISPLAYCOLMAX - 1;
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
for(loopcnt_row = 0; loopcnt_row < DISPLAYROWMAX; loopcnt_row++){
|
356
|
+
|
357
|
+
for(loopcnt_col = 0; loopcnt_col < DISPLAYCOLMAX; loopcnt_col++){
|
358
|
+
|
359
|
+
if(loopcnt_col == DISPLAYCOLMAX-1){
|
360
|
+
|
361
|
+
display[loopcnt_row][loopcnt_col] = '\n' ;
|
362
|
+
|
363
|
+
}else if(loopcnt_row == position->row &&
|
364
|
+
|
365
|
+
loopcnt_col == position->col){
|
366
|
+
|
367
|
+
display[loopcnt_row][loopcnt_col] = '_' ;
|
368
|
+
|
369
|
+
}else{
|
370
|
+
|
371
|
+
display[loopcnt_row][loopcnt_col] = ' ';
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
/* char initialize_top(char display[DISPLAYROWMAX][DISPLAYCOLMAX]){
|
384
|
+
|
131
|
-
char
|
385
|
+
char loopcnt_col ;
|
386
|
+
|
132
|
-
|
387
|
+
for(loopcnt_col = 0;loopcnt_col < DISPLAYCOLMAX-1; loopcnt_col++){
|
388
|
+
|
389
|
+
display[DISPLAYROWMAX-1][loopcnt_col] = '-' ;
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
display[DISPLAYROWMAX-1][DISPLAYCOLMAX-1] = '\n' ;
|
396
|
+
|
397
|
+
|
398
|
+
|
133
|
-
|
399
|
+
return 1 ;
|
400
|
+
|
134
|
-
|
401
|
+
}*/
|
402
|
+
|
135
|
-
```
|
403
|
+
```
|