回答編集履歴
1
追記
test
CHANGED
@@ -81,3 +81,241 @@
|
|
81
81
|
|
82
82
|
|
83
83
|
あとopen関数が見当たらないのですが記載もれでしょうか?
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
----------以下追記--------------
|
88
|
+
|
89
|
+
参考としてコードを示します。ご自身のと比べて見て下さい。
|
90
|
+
|
91
|
+
```C
|
92
|
+
|
93
|
+
//min.c
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
#include<stdio.h>
|
98
|
+
|
99
|
+
#include<string.h>
|
100
|
+
|
101
|
+
#include<time.h>
|
102
|
+
|
103
|
+
#include<stdlib.h>
|
104
|
+
|
105
|
+
#include<stdbool.h>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
#define MINE 10
|
110
|
+
|
111
|
+
#define BORD_wide 9
|
112
|
+
|
113
|
+
#define BORD_high 9
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
bool g_open[BORD_wide+2][BORD_high+2];
|
118
|
+
|
119
|
+
bool g_mine[BORD_wide+2][BORD_high+2];
|
120
|
+
|
121
|
+
char g_near[BORD_wide+2][BORD_high+2];
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
int init_board(){
|
126
|
+
|
127
|
+
int x,y,i;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
for(x=0;x<11;x++){
|
132
|
+
|
133
|
+
for(y=0;y<11;y++){
|
134
|
+
|
135
|
+
g_mine[x][y]=false;
|
136
|
+
|
137
|
+
g_near[x][y]=0;
|
138
|
+
|
139
|
+
g_open[x][y]=false;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
for(i=0;i<10;i++){
|
148
|
+
|
149
|
+
int x,y;
|
150
|
+
|
151
|
+
do{
|
152
|
+
|
153
|
+
x=rand()%10;
|
154
|
+
|
155
|
+
y=rand()%10;
|
156
|
+
|
157
|
+
}while(g_mine[x][y]);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
g_mine[x][y]=true;
|
162
|
+
|
163
|
+
g_near[x-1][y-1]+=1;
|
164
|
+
|
165
|
+
g_near[x][y-1]+=1;
|
166
|
+
|
167
|
+
g_near[x+1][y-1]+=1;
|
168
|
+
|
169
|
+
g_near[x-1][y]+=1;
|
170
|
+
|
171
|
+
g_near[x][y]+=1;
|
172
|
+
|
173
|
+
g_near[x+1][y]+=1;
|
174
|
+
|
175
|
+
g_near[x-1][y+1]+=1;
|
176
|
+
|
177
|
+
g_near[x][y+1]+=1;
|
178
|
+
|
179
|
+
g_near[x+1][y+1]+=1;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
const char *digitStr[]={
|
188
|
+
|
189
|
+
"1","2","3","4","5","6","7","8","9",
|
190
|
+
|
191
|
+
};
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
int pboard(bool sweeped){
|
196
|
+
|
197
|
+
int x,y;
|
198
|
+
|
199
|
+
printf("\n 123456789\n");
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
for(y=1;y<=9;y++){
|
204
|
+
|
205
|
+
printf("%d",y);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
for(x=1;x<=9;x++){
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
if(!g_mine[x][y])
|
214
|
+
|
215
|
+
printf("?");
|
216
|
+
|
217
|
+
else if(sweeped && g_mine[x][y]) //爆弾未発見時は非表示
|
218
|
+
|
219
|
+
printf("*");
|
220
|
+
|
221
|
+
else if(!g_near[x][y])
|
222
|
+
|
223
|
+
printf("#");
|
224
|
+
|
225
|
+
else
|
226
|
+
|
227
|
+
printf("%d",g_near[x][y]);
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
printf("\n");
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
printf("\n");
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
bool checkSweeped(){
|
242
|
+
|
243
|
+
int x,y;
|
244
|
+
|
245
|
+
for(x=1;x<=9;x++){
|
246
|
+
|
247
|
+
for(y=1;y<=9;y++){
|
248
|
+
|
249
|
+
if(!g_mine[x][y]&&!g_open[x][y])
|
250
|
+
|
251
|
+
return false;
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
return true;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
int main(void){
|
264
|
+
|
265
|
+
int xx,yy;
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
srand((int)time(NULL));
|
270
|
+
|
271
|
+
printf("start minsweeper!");
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
for(;;){
|
276
|
+
|
277
|
+
init_board();
|
278
|
+
|
279
|
+
bool sweeped=false;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
while(!sweeped){
|
284
|
+
|
285
|
+
pboard(sweeped);
|
286
|
+
|
287
|
+
printf("if you stop the game,put control+c.\n");
|
288
|
+
|
289
|
+
printf("input the coordinate. [x][y] : ");
|
290
|
+
|
291
|
+
scanf("%d %d",&xx,&yy);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
if(g_mine[xx][yy])
|
296
|
+
|
297
|
+
break;
|
298
|
+
|
299
|
+
sweeped=checkSweeped();
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
pboard();
|
306
|
+
|
307
|
+
if(sweeped)
|
308
|
+
|
309
|
+
printf("cleared!!\n");
|
310
|
+
|
311
|
+
else
|
312
|
+
|
313
|
+
printf("Oh,no!you've failed.");
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
return 0;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
```
|