質問編集履歴
1
記載する関数を増やしました
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,10 +28,81 @@
|
|
28
28
|
解決法をご存知の方がいらっしゃれば、よろしくお願いいたします。
|
29
29
|
|
30
30
|
|
31
|
+
【display_info.h】
|
32
|
+
```
|
33
|
+
typedef struct{
|
34
|
+
char col ;
|
35
|
+
char row ;
|
36
|
+
} myposition_t;
|
37
|
+
```
|
38
|
+
|
39
|
+
【extern.h】
|
40
|
+
```
|
41
|
+
#include "macro.h"
|
42
|
+
#include "display_info.h"
|
43
|
+
|
44
|
+
extern void draw_pic(char display[DISPLAYROWMAX][DISPLAYCOLMAX]);
|
45
|
+
|
46
|
+
/************************************/
|
47
|
+
/* initialize.c */
|
48
|
+
/************************************/
|
49
|
+
extern char initialize_main(char display[DISPLAYROWMAX][DISPLAYCOLMAX], myposition_t *position);
|
50
|
+
// extern char initialize_top(char display[DISPLAYROWMAX][DISPLAYCOLMAX]);
|
51
|
+
/************************************/
|
52
|
+
/* move.c */
|
53
|
+
/************************************/
|
54
|
+
// extern char move_right(mypositon_t *position);
|
55
|
+
// extern char move_left(myposition_t *position);
|
56
|
+
```
|
57
|
+
|
58
|
+
【macro.h】
|
59
|
+
```
|
60
|
+
#define DISPLAYCOLMAX (71)
|
61
|
+
#define DISPLAYROWMAX (200)
|
62
|
+
```
|
63
|
+
|
31
64
|
【invider.c】
|
32
65
|
```
|
66
|
+
#include <stdio.h>
|
67
|
+
#include <termios.h>
|
68
|
+
#include <unistd.h>
|
69
|
+
#include <fcntl.h>
|
70
|
+
#include "inc/extern.h"
|
33
71
|
#include "inc/display_info.h"
|
72
|
+
#include "inc/macro.h"
|
34
73
|
|
74
|
+
|
75
|
+
/****************************************************************/
|
76
|
+
/* WindowsのkbhitはLinuxでは使えないため、termios機能を使用する */
|
77
|
+
/* kbhit関数はネットのを引用 */
|
78
|
+
/****************************************************************/
|
79
|
+
int kbhit(void){
|
80
|
+
struct termios oldt, newt;
|
81
|
+
int ch;
|
82
|
+
int oldf;
|
83
|
+
|
84
|
+
tcgetattr(STDIN_FILENO, &oldt);
|
85
|
+
newt = oldt;
|
86
|
+
newt.c_lflag &= ~(ICANON | ECHO);
|
87
|
+
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
88
|
+
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
89
|
+
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
90
|
+
|
91
|
+
ch = getchar();
|
92
|
+
|
93
|
+
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
94
|
+
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
95
|
+
|
96
|
+
if (ch != EOF) {
|
97
|
+
ungetc(ch, stdin);
|
98
|
+
return 1;
|
99
|
+
}
|
100
|
+
return 0;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*****************************************************************/
|
104
|
+
/* メイン関数 */
|
105
|
+
/*****************************************************************/
|
35
106
|
int main(void){
|
36
107
|
char inputkey; //入力キー
|
37
108
|
// int position; //自分のキャラの位置
|
@@ -40,13 +111,30 @@
|
|
40
111
|
char display [DISPLAYROWMAX][DISPLAYCOLMAX] = {' '} ; // ゲーム画面
|
41
112
|
char *first_flg ;
|
42
113
|
|
43
|
-
initialize_main(display, &position);
|
114
|
+
initialize_main(display, &position);
|
44
115
|
|
45
116
|
while (1) {
|
46
117
|
if (kbhit()) {
|
47
118
|
inputkey = getchar();
|
48
119
|
switch(inputkey){
|
120
|
+
/* case 'l':
|
121
|
+
result = move_right(&position);
|
49
122
|
|
123
|
+
if(result == 1){
|
124
|
+
continue;
|
125
|
+
}else{
|
126
|
+
break ;
|
127
|
+
}
|
128
|
+
|
129
|
+
case 'h':
|
130
|
+
result = move_left(&position);
|
131
|
+
|
132
|
+
if(result == 1){
|
133
|
+
continue;
|
134
|
+
}else{
|
135
|
+
break;
|
136
|
+
}
|
137
|
+
*/
|
50
138
|
case 'q':
|
51
139
|
goto exit;
|
52
140
|
default:
|
@@ -58,11 +146,57 @@
|
|
58
146
|
exit:
|
59
147
|
return 0;
|
60
148
|
}
|
149
|
+
|
150
|
+
void draw_pic(char display[DISPLAYROWMAX][DISPLAYCOLMAX]){
|
151
|
+
char loopcnt_row ;
|
152
|
+
char loopcnt_col ;
|
153
|
+
|
154
|
+
for(loopcnt_row = 0; loopcnt_row < DISPLAYROWMAX; loopcnt_row++){
|
155
|
+
for(loopcnt_col = 0; loopcnt_col < DISPLAYCOLMAX; loopcnt_col++){
|
156
|
+
printf("%s",display[loopcnt_row][loopcnt_col]);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
61
160
|
```
|
161
|
+
|
62
|
-
【
|
162
|
+
【initialize.c】
|
63
163
|
```
|
164
|
+
#include <stdio.h>
|
165
|
+
#include "inc/macro.h"
|
166
|
+
#include "inc/display_info.h"
|
167
|
+
#include "inc/extern.h"
|
168
|
+
|
169
|
+
char initialize_main(char display[DISPLAYROWMAX][DISPLAYCOLMAX],
|
64
|
-
|
170
|
+
myposition_t *position){
|
171
|
+
char loopcnt_row ;
|
65
|
-
|
172
|
+
char loopcnt_col ;
|
173
|
+
|
174
|
+
|
175
|
+
position->col = 34;
|
176
|
+
position->row = DISPLAYCOLMAX - 1;
|
177
|
+
|
178
|
+
for(loopcnt_row = 0; loopcnt_row < DISPLAYROWMAX; loopcnt_row++){
|
179
|
+
for(loopcnt_col = 0; loopcnt_col < DISPLAYCOLMAX; loopcnt_col++){
|
180
|
+
if(loopcnt_col == DISPLAYCOLMAX-1){
|
181
|
+
display[loopcnt_row][loopcnt_col] = '\n' ;
|
182
|
+
}else if(loopcnt_row == position->row &&
|
183
|
+
loopcnt_col == position->col){
|
184
|
+
display[loopcnt_row][loopcnt_col] = '_' ;
|
185
|
+
}else{
|
186
|
+
display[loopcnt_row][loopcnt_col] = ' ';
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
/* char initialize_top(char display[DISPLAYROWMAX][DISPLAYCOLMAX]){
|
66
|
-
char
|
193
|
+
char loopcnt_col ;
|
194
|
+
for(loopcnt_col = 0;loopcnt_col < DISPLAYCOLMAX-1; loopcnt_col++){
|
195
|
+
display[DISPLAYROWMAX-1][loopcnt_col] = '-' ;
|
196
|
+
}
|
197
|
+
|
198
|
+
display[DISPLAYROWMAX-1][DISPLAYCOLMAX-1] = '\n' ;
|
199
|
+
|
67
|
-
|
200
|
+
return 1 ;
|
201
|
+
}*/
|
68
202
|
```
|