Stargazer

군대에서 할거 없을때 만든 지뢰 찾기 본문

카테고리 없음

군대에서 할거 없을때 만든 지뢰 찾기

COM2IT 2019. 7. 18. 20:09
반응형

군대컴에는 컴파일러를 깔수 없다

 

?????

 

근데 어떻게 개발 했냐!!

 

윈도우7이상의 컴퓨터에는

.net framwork 가 내장 되어있었다!!

 

덕분에 짬짬이 만들었다

기간은 2주 정도 걸린것 같다

만든 코드를 다시 복사해서 인터넷으로 옮기는 작업은

일일이 손으로 타이핑 해야만 했다

그작업만 1시간 30분이 걸렸다.

(손아파ㅠㅠㅠㅠ... 특히 새끼손가락 너무 많이 썼어)

 

어찌저찌 해서 복사 완성 하였다

 

코드는 걍 공개 하겠다

원래는 저작권을 중시하는 성격 이지만

굳이 지뢰찾기를 숨길 필요가 뭐가 있겠나

공유하면서 발전할 수 있다면 나는 상관 없다(크~ 멋있다(ㅈㅅ))

 

보기 좋게 코드 스크립터로 공개 합니다.

이참에 프로그램도 같이 업로드 합니다.

 

아, 참고로 개발 언어는 c#입니다.

.net framework는 c#컴파일러가 있어서 그걸로 했습니다.

군대 와서 처음 하는건데도 c++,java 짬뽕 시켜놓은 것 같아서 할만 했다.

 

자 이제 공개!!

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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
using System;
 
namespace mine{
    public class Player{
        int x, y;
        string shape = "㉯";
        string message ="";
        
        public Player(int x = 0int y=0){
            this.x = x;
            this.y = y;
        }
        
        public void show(){
            Console.SetCursorPosition(x*2,y);
            Console.Write(shape);
        }
        
        public Player input(char dir){
            message ="";
            switch(dir){
                case 'w':
                if(y>0){
                    y--;
                    message = "up";
                }
                break;
                
                case 's':
                if(y+1<Map.y){
                    y++;
                    message = "down";
                }
                break;
                case 'a':
                if(x>0){
                    x--;
                    message = "left";
                }
                break;
                case 'd':
                if(x+1 < Map.x){
                    x++;
                    message = "right";
                }
                break;
                
                case 'p':
                message = "flag";
                break;
                
                case 'o':
                message = "enter";
                break;
                
                case 'q':
                message = "quit";
                break;
            }
            return this;
        }
        
        public int getx() {return x;}
        public int gety() {return y;}
        public void setx(int x){this.x = x;}
        public void sety(int y){this.y = y;}
        public string send(){
            return message;
        }
    }
    
    public class Map{
        public static int x, y;
        int mineNum;
        int[,] numMap;
        bool[,] open;
        bool[,] mineMap;
        bool[,] flag;
        int flagnum = 0;
        bool lose = false;
        
        public Map(int x = 9int y =9int num=10){
            Map.x= x;
            Map.y = y;
            mineNum = num;
            numMap = new int[y,x];
            mineMap = new bool[y,x];
            open = new bool[y,x];
            flag = new bool[y,x];
            
            Random r = new Random();
            
            for(int i = 0 ; i< y; i++){
                for(int j = 0 ;j < x; j++){
                    numMap[i,j] =0;
                    mineMap[i,j] = open[i,j] = false;
                }
            }
            
            for(int i = 0 ; i< mineNum; i++){
                int sx = r.Next(0,x);
                int sy = r.Next(0,y);
                
                if(mineMap[sy,sx] == false){
                    mineMap[sy,sx] = true;
                    numMap[sy,sx] = -1;
                    
                    for(int dx = -1; dx<=1; dx++){
                        for(int dy = -1; dy<=1; dy++){
                            if(dx ==0 && dy==0continue;
                            
                            int lx = sx+dx;
                            int ly = sy+dy;
                            if(lx >= 0 && lx < x && ly >= 0 && ly < y){
                                if(mineMap[ly,lx] == true){continue;}
                                numMap[ly,lx] += 1;
                            }
                        }
                    }
                    continue;
                }else{i--;}
            }
            
            for(int i = 0 ; i < y;i++){
                for(int j= 0 ; j< x; j++){
                    Console.Write("■");
                }
                Console.WriteLine();
            }
        }
        void flagShow(){
            for(int i =0;i < y;i++){
                for(int j = 0; j < x; j++){
                    if(flag[i,j] == true){
                        Console.SetCursorPosition(j*2,i);
                        Console.Write("♠");
                    }
                }
            }
        }
        public void show(){
            Console.SetCursorPosition(0,0);
            for(int i = 0; i< y; i++){
                for(int j =0 ; j<x;j++){
                    if(open[i,j]){
                        Console.SetCursorPosition(j*2,i);
                        Console.Write(selectShape(numMap[i,j]));
                    }else{}
                }
            }
        }
        
        void printShape(int x, int y){
            Console.SetCursorPosition(x*2, y);
            Console.Write(selectShape(numMap[y,x]));
        }
        
        string selectShape(int s){
            string[] shape = {
                "□","①","②","③","④","⑤","⑥","⑦","⑧"
            };
            switch(s){
                case -1:
                return "⊙";
                case -2:
                return "★";
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 0:
                    return shape[s];
            }
            return "■";
        }
                
        public void invest0(int sy, int sx){
                for(int dx = -1; dx<=1; dx++){
                        for(int dy = -1; dy<=1; dy++){
                            if(dx ==0 && dy==0continue;
                            
                            int lx = sx+dx;
                            int ly = sy+dy;
                            if(lx >= 0 && lx < x && ly >= 0 && ly < y){
                                if(open[ly,lx] == truecontinue;
                                if(flag[ly,lx] == true) flag[ly,lx] = false;
                                open[ly,lx] = true;
                                if(numMap[ly,lx] == 0){
                                    invest0(ly,lx);
                                    
                                }
                                printShape(lx,ly);
                            }
                        }
                }
        }
        
        public bool investFlag(Player p){
            int sum = 0;
            int opened = 0;
            for(int dx = -1; dx<=1; dx++){
                for(int dy = -1; dy<=1; dy++){
                    
                    if(dx ==0 && dy==0continue;
                    int lx = p.getx()+dx;
                    int ly = p.gety()+dy;
                    
                    if(availablePoint(lx,ly)){
                        if(flag[ly,lx] == true){
                            sum++;
                        }
                        if(open[ly,lx]) opened++;
                    }
                }
            }
            if(opened == 8-numMap[p.gety(),p.getx()]){
                    return false;
            }
            if(sum == numMap[p.gety(),p.getx()]){
                for(int dy=-1;dy<=1;dy++){
                    for(int dx =-1;dx <=1; dx++){
                        int lx = p.getx() + dx;
                        int ly = p.gety() + dy;
                        if(dx ==0 && dy==0continue;
                        
                        if(availablePoint(lx,ly)){
                            if(!flag[ly,lx] && !open[ly,lx]){
                                open[ly,lx] = true;
                                Console.SetCursorPosition(lx*2,ly);
                                Console.Write(selectShape(numMap[ly,lx]));
                            }
                            else{continue;}
                            
                            if(numMap[ly,lx] == 0){
                                invest0(ly,lx);
                            }
                            else if (mineMap[ly,lx] == true){
                                for(int i = 0 ; i< y; i++){
                                    for(int j = 0 ; j< x; j++){
                                        open[i,j] = true;
                                        if(flag[i,j] == true&& numMap[i,j] != -1){
                                            flag[i,j] = false;
                                        }
                                    }
                                }
                                lose = true;
                                return true;
                            }
                        }
                    }
                }
            }
            lose =false;
            return false;
        }
        
        public bool winCheck(){
            int sum =0;
            forint i= 0; i<Map.y;i++){
                for(int j = 0; j<Map.x;j++){
                    if(open[i,j] == false) sum++;
                }
            }
            
            if(mineNum == sum){
                return true;
            }else return false;
        }
            
            public bool availablePoint(int x, int y){
                if(x>=0 && x< Map.x && y >= 0&& y< Map.y){
                    return true;
                }
                else return false;
            }
            
            public bool receive(Player p){
                int dx = 0 , dy =0;
                bool move = false;
                
                switch(p.send()){
                    case "left":
                    dx=-1;
                    move = true;
                    break;
                    case "right":
                    dx=1;
                    move = true;
                    break;
                    case "up":
                    dy=-1;
                    move = true;
                    break;
                    case "down":
                    dy=1;
                    move = true;
                    break;
                    case "enter":
                    if(open[p.gety(),p.getx()] == true && numMap[p.gety(),p.getx()] != 0){
                        investFlag(p);
                    }else if(!flag[p.gety(),p.getx()]){
                        open[p.gety(),p.getx()] = true;
                        printShape(p.getx(),p.gety());
                    }else {return true;}
                    
                    if(numMap[p.gety(),p.getx()] == 0){
                        invest0(p.gety(),p.getx());
                    }
                    else if(numMap[p.gety(),p.getx()] == -1 || lose){
                        for(int i = 0; i< y; i++){
                            for(int j = 0 ; j< x; j++){
                                open[i,j] = true;
                                if(flag[i,j] == true && numMap[i,j] != -1){
                                    flag[i,j] = false;
                                }
                            }
                        }
                        show();
                        Console.SetCursorPosition(35,10);
                        Console.Write("Game Over");
                        Console.SetCursorPosition(35,11);
                        Console.Write("Please press Enter");
                        while(Console.ReadKey(true).KeyChar !=(char)13){}
                        return false;
                    }
                    if(winCheck()){
                        for(int i =0;i<y;i++){
                            for(int j=0;j<x; j++){
                                open[i,j] = true;
                                flag[i,j] = false;
                                if(numMap[i,j] == -1){
                                    numMap[i,j] = -2;
                                }
                            }
                        }
                        show();
                        Console.SetCursorPosition(35,10);
                        Console.Write("You Win!!");
                        Console.SetCursorPosition(35,11);
                        Console.Write("Please press Enter");
                        while(Console.ReadKey(true).KeyChar != (char13){};
                        return false;
                    }
                    
                    break;
                    
                    case "flag":
                    if(!open[p.gety(),p.getx()])
                        switch(flag[p.gety(),p.getx()]){
                            case true:
                            flag[p.gety(),p.getx()] = false;
                            flagnum--;
                            break;
                            case false:
                            flag[p.gety(),p.getx()] = true;
                            flagnum++;
                            break;
                        }
                        Console.SetCursorPosition(70,24);
                        Console.Write("     ");
                        Console.SetCursorPosition(72,24);
                        Console.Write(mineNum - flagnum);
                        break;
                    case "quit":
                    return false;
                }
                if(move){
                    Console.SetCursorPosition((p.getx()-dx)*2, (p.gety()-dy));
                    
                    if(!open[p.gety()-dy,p.getx()-dx] ){
                        if(flag[p.gety()-dy,p.getx()-dx] == false){
                            Console.Write("■");
                        }else{
                            Console.Write("♠");
                        }
                    }else Console.Write(selectShape(numMap[p.gety()-dy,p.getx()-dx]));
                    
                    p.show();
                }
                return true;
            }
        }
        
        public class Program{
            public static void copyRight(){
                Console.SetCursorPosition(0,24);
                Console.Write("Made by BSY");
            }
            public static void Main(string [] args){
                int select;
                Player p =new Player();
                Map map = new Map();
                Console.CursorVisible = false;
                int minenum =0;
                while(true){
                    Console.Clear();
                    copyRight();
                    Console.SetCursorPosition(0,0);
                    Console.WriteLine("지뢰찾기<ver 1.0>");
                    Console.WriteLine("난이도를 설정해주세요");
                    Console.WriteLine("1.쉬움(9x9) 2.보통(19x19) 3.어려움(39x24) 4.커스텀 5.설명 6.종료");
                    
                    select = Convert.ToInt32(Console.ReadLine());
                    
                    switch(select){
                        case 1:
                        minenum =10;
                        map = new Map(9,9,10);
                        break;
                        case 2:
                        minenum= 51;
                        map = new Map(19,19,51);
                        break;
                        case 3:
                        minenum =111;
                        map = new Map(39,24,111);
                        break;
                        case 4:
                        Console.WriteLine("가로(9~39): ");
                        int x = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("세로(9~24): ");
                        int y = Convert.ToInt32(Console.ReadLine());
                        minenum =x*y/7;
                        map = new Map(x,y,minenum);
                        break;
                        case 5:
                        int pos = 6;
                        Console.SetCursorPosition(0,pos++);
                        Console.Write("w,s,a,d: 방향키");
                        Console.SetCursorPosition(0,pos++);
                        Console.Write("o: 선택, p:플래그");
                        Console.SetCursorPosition(0,pos++);
                        Console.Write("q: 나가기");
                        Console.SetCursorPosition(0,pos++);
                        Console.Write("숫자를 누르면 플래그 숫자와 동일 시 주변부를 엽니다");
                        Console.SetCursorPosition(20,pos++);
                        Console.Write("Please press Enter");
                        while(Console.ReadKey(true).KeyChar != (char)13){};
                        continue;
                        case 6:
                        return;
                        
                    }
                    p.setx(Map.x/2);
                    p.sety(Map.y/2);
                    Console.Clear();
                    
                    for(int i =0;i< Map.y;i++){
                        for(int j=0;j<Map.x;j++){
                            Console.Write("■");
                        }
                        Console.WriteLine();
                    }
                    p.show();
                    
                    Console.SetCursorPosition(55,24);
                    Console.Write("남은 지뢰 갯수: {0}", minenum);
                    
                    while(true){
                        if(map.receive(p.input(Console.ReadKey(true).KeyChar)) == false)
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
 
cs

중간 중간에 코드 설명이 있긴한데 알아서 하시길...

..은 농담이고 질문이나 설명 보충이 필요하면 언제든 환영입니다.

(다만 시간이 별로 없어서 좀 답변이 느릴수 있습니다.ㅜ)

 

실행파일도 업로드합니다.

mine.exe
0.01MB

10kb 짜리

 

용량이 개발 기간에 비해서는 현저히 작다....

 

아무튼 즐겜!!

 

ps. 2024.03.05

소스코드 복사 방지로 코드가 복사가 안되더라고요..

그래서 소스코드 같이 올립니다!

mine.cs
0.03MB

반응형
Comments