|
- #include<stdio.h>
! g5 R& l' ^3 q& L! Z: h - #include<windows.h>4 D0 t+ C$ ~6 U$ g& a6 u' t
- #include<stdlib.h>" y/ S1 o, z" C
- #include<time.h>0 v, p( t8 G0 c2 [+ | ~" ]
- #include<conio.h>
9 ^9 F8 }$ H/ } h* |* c" D - #include<queue>$ ]" E; z0 n% g% K# _' o
- #include<ctype.h>
1 X2 I* f. @, b8 \6 O8 \! Y9 m - #define A 17 //地图的高
) K8 V7 x( m% [- l2 N - #define B 17 //地图的宽
% K; O9 q, a4 @; l( Z( v _6 N: A - #define C 30 //雷的总数* v( l, z1 g2 h
- using namespace std;7 x9 y O6 M5 H* a& Z
- " E4 J' ^) z; A; K4 H3 `9 }
- //全局变量
8 P; J( f N4 s! K* [( D2 ` - DWORD a,b;
; b8 k* T& ~0 { ^ - char map[A][B],news,spare;6 W7 ^6 T5 O7 N3 \. d }
- int BoomTotalNum,floatx,floaty,flag[A][B],flagnum,mode,slect[A][B],game;
2 {6 k+ d+ M$ v4 N& Q1 o - ) a7 W9 Z0 g5 @) ?' u+ X
- //颜色属性
& m4 V& D) @- q. b6 s" Z# R z/ c) A - const WORD FORE_BLUE = FOREGROUND_BLUE; //蓝色文本属性5 E7 c, \: ]4 E7 e4 T
- const WORD FORE_GREEN = FOREGROUND_GREEN; //绿色文本属性
4 I" P4 f( R/ q) s# Q6 @ - const WORD FORE_RED = FOREGROUND_RED; //红色文本属性! q! H) D; h+ i6 q
-
/ I5 p) w8 O$ f3 S+ g4 u, b - //开垦地图结构体
% t* ~6 L! p; Z# y% H - struct node {+ b/ E }* U; H+ \' @
- int x;
. N% [8 g/ A1 E# Z. T - int y;
; {* H) E, t& M - };. n% A/ {$ K0 d0 ]5 e, o
- queue <node> dui;
8 E( I: U/ M r- Q2 R9 ~ -
A A" q2 a! ?" @/ { - //打印位置
, A: I, ]9 J$ f6 U1 b - void position(int x,int y) {7 C( `5 h2 _8 h; l. ?
- COORD pos={x,y};5 d7 }5 ^/ f8 S( t, O9 _
- HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
# H, J0 G# b% v0 {0 F - SetConsoleCursorPosition(Out,pos);, P) S% M8 V+ p: @3 R. g& t
- }1 ]9 q6 @# _& M, Y
- & k% A% W$ n, a! X) Y$ F) d9 J9 t! a
- //隐藏光标 # g. c$ I0 Q/ |+ A2 ?' s% c% R% B9 T& q
- void Hide() {9 n, K1 l( G/ r) G$ }
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); 3 _: Z( w8 j! t: T# ` H* f0 i
- CONSOLE_CURSOR_INFO CursorInfo;
" X$ a0 O1 N/ e7 A; [+ h& l( }0 G0 V% C - GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息 ! Z% i& g# {: D2 p
- CursorInfo.bVisible = false; //隐藏控制台光标 4 k- [9 v3 c7 y# e0 |
- SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
* e3 g7 Z$ p) s- _" @ }5 p - }
& p$ _: ?1 t+ Z- q- L' I$ q - # Q' b' v8 r# ?, s
- //初始化
) `' X/ V+ P0 {. o6 M9 ^' _ - void Beginning() {
/ l5 S" f% j8 u R% f S - while(!dui.empty()) {
* t: [' Y+ B: t; o3 g/ } - dui.pop();8 Z! f2 T8 R9 H# {
- }
. N3 H Y" H- W0 Q( ^8 v6 c - game=1;
/ Y/ D- M J$ i - //BoomTotalNum=C;+ N4 `- h3 B0 e! K- C- m' l) }
- floatx=A/2;
1 H7 X2 G6 H6 _& h! d - floaty=B/2;
3 s. t, f" c' R V1 @2 n5 H - flagnum=0;. `1 {" g$ j' O" Z' s2 F
- BoomTotalNum=C;9 s& d+ ]9 S/ g! W* Y; ]
- mode=0;
! ]5 Z# b" n( e5 k9 V& a - HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
( F+ K9 u4 p* w, D, _ - CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
" f9 {1 h% x# ^$ d - GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
& b+ X! ]2 b, c3 ^& h0 S% ?9 N5 G - int x,y;6 @. i6 r: o8 L3 |9 x
- srand((unsigned)time(0));% b, W0 o# G# N4 P7 g% w
- for(int i=0;i<A;i++) for(int j=0;j<B;j++) {
# \4 r- k) F7 q! [ - map[i][j]=' ';
8 I& F, L' ~1 ?' U9 l - flag[i][j]=0;
7 I' d0 X" W$ V% @- { - slect[i][j]=0;% n2 |2 j% m. r9 F( g
- }
. Q' x: U( o+ ~- ]& d3 v7 g - while(BoomTotalNum) {: ~4 F c* ]0 m' M) z. q6 m7 p% ?
- x=rand()%A;
' o4 x& y9 j0 a& C+ H+ f! D w5 r - y=rand()%B;2 a1 u" W( N- A1 r
- if(map[x][y]==' ') {( Q; ], q9 i0 ^
- map[x][y]='@';6 ?2 }7 @: ]7 K p5 {! N
- BoomTotalNum--;0 m& [' t Y' o, O. R# F2 _
- }& g5 d9 B0 P- z$ @2 b
- }
1 _ U" Y7 e5 J; \* m, b. W - SetConsoleTextAttribute(handle_out, FORE_GREEN);
% }- S4 l7 j `3 u. }0 G# E; k9 V6 ] - for(int i=0;i<A;i++) {
9 r0 G7 i2 l9 K) A" C - for(int j=0;j<B;j++) printf("█");- w4 w9 E9 G3 H1 C& e6 u
- printf("\n");
, ?) j2 ]6 x* ]+ W- y0 J1 C2 f& G - } e7 G& h3 x8 ^$ n& Y
- position(floaty*2,floatx);7 _/ j4 Z% E; D
- SetConsoleTextAttribute(handle_out, FORE_RED); 3 E: G; e ^0 K/ s
- printf(""); //光标位置
/ Y k8 E( @1 W4 M; \ - position(44,9);+ u d1 Y5 i7 J3 M( U8 ]
- printf("扫雷模式");% }/ d" a# F& p. W1 @9 F2 X
- position(44,5);3 g# W" G8 p: X8 g' M* J& k
- printf("剩余雷数:%d ",C-flagnum);
3 X, r9 n+ ~! }, f: f* c - SetConsoleTextAttribute(handle_out, FORE_GREEN);
+ @: u5 R' |- `& x' _5 A# w6 W - position(5,22);
1 }% b+ o5 a9 M7 D* h - printf("按“空格”切换模式");; D6 u' O* a9 U. T
- position(5,23);
9 C) W; b0 S) g" E4 {; M! T6 A - printf("按“Enter”确认");' J/ k% x* V0 A' P- p6 a) X( s
- position(5,24);& K& ~; x3 ^3 w+ C0 s
- printf("按“方向键”选择方块"); # I& O( ^+ l* f2 h
- * L: E/ _/ o8 r* m; D5 I( b
- }
' k4 ?3 ~- {# W5 E3 M: X( \ - " J- P0 g( v! m( T5 c# a5 e( T8 j
- //打印地图的一块儿 ; A4 a+ a$ z8 I0 v! b; Y# ?, d
- void Lump(int xx,int yy) {- G- S8 ~8 Z# }% j
- switch(map[xx][yy]) {( F9 T$ o6 W% ^9 q: f' k
- case '1' : printf("①");break; //周围雷的数量(下同) , k1 i0 ^. [- E" I, w$ K# v
- case '2' : printf("②");break;
' W& W! v! b' {$ \: t - case '3' : printf("③");break;( u4 V+ g7 N B+ ?6 W: C$ z
- case '4' : printf("④");break;
! F8 @+ W' v$ s8 m/ ^ @; ` - case '5' : printf("⑤");break;
+ X+ E) j6 l2 m( S, K* ] - case '6' : printf("⑥");break;, Y; r' n1 P0 W7 U
- case '7' : printf("⑦");break;
, X" B+ L3 d2 H+ i, c- p - case '8' : printf("⑧");break;$ C! _ `3 ^, j3 V1 [
- case ' ' :# }, F7 a" w6 O
- if(xx==floatx&&yy==floaty) {
) ~) T: c" r5 G/ W* H* ]- Q, ~ - if(flag[xx][yy]==0) {
: a( Z1 Z! [. E# G - if(mode%2==0) printf("");
, I0 x) t9 p% z# C4 E - else printf("");
% Z. s3 \6 L% l0 ~: t) F. W; P - }
& y3 Q" o% o/ c$ E- H/ o" _ v - else printf("");
+ G! V( Z! I1 }* U8 L: } - }
' g# m9 T/ @' l- C" H - else {0 T1 F1 Y& Y! U- ^/ D
- if(flag[xx][yy]==0) printf("█");5 d# s2 U/ A, e, t: j5 |5 I
- else printf("");
% s0 p0 g& F! B) m+ ] - }
; \! W; x6 ?4 r: M0 u% \ - break;' z$ v4 ^# [. r- U! u P
- case '@' :4 V/ J1 u$ r$ \+ C- N- h- r8 E
- if(xx==floatx&&yy==floaty) {, `0 r9 G+ p) m4 ?6 `8 P
- if(flag[xx][yy]==0) {
) e L5 `1 M$ R8 n9 n- A. n/ P* a* s - if(mode%2==0) printf("");
4 I2 b2 [# ~6 t; \6 ^ - else printf("");. A& T) r$ K! k' ?, d3 M6 r
- }
9 e4 A4 ~# w) [1 g8 v- ` - else printf("");0 N2 q" f+ i3 F+ G; b+ V" c2 _
- }
: q6 j% K3 r% a4 G) L$ ? - else {$ g* d( X# t" t3 E1 |7 J
- if(flag[xx][yy]==0) printf("█");6 i; p: D3 d: ^$ O6 o% k
- else printf("");
7 ]6 D& Z6 W& d" N' r q, `9 G - }3 E' B# ]$ q3 N1 I* x, O1 a
- break;& |8 `1 |( @2 f7 X% S, H
- case 'x' : if(floatx==xx&&floaty==yy) printf(""); else printf(" ");break; //已经挖开的空白
0 ~- E% H5 U" i8 B' V/ ` - }! f- T' t5 H3 y' p' r5 u
- }) j9 N& Q2 O$ t5 H' w l
- " H4 v; g" k) G2 ]# U
- //移动光标1 k2 H+ Q5 ` q% r
- void Move() {% j: V1 \& w* l/ m
- HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 ; r+ b/ V6 g- r4 g$ ?- a8 ~9 q
- CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体 . j4 t9 Q8 e6 A2 g
- GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
5 l9 `( X% ^5 y+ W9 J - int xxx,yyy;8 a$ N9 K; m0 j! t
- xxx=floatx;
( U- v5 T% o& H' ~, e+ ] @& m& _: ~ - yyy=floaty;
, ]# @# q2 E- P - switch(news) {
5 j3 |* [$ c o" K% O! O; Y - case 72 : floatx--;break; //上 + Q1 A7 H7 {0 F- p; u
- case 80 : floatx++;break; //下 / D7 \. x7 c/ V. K4 ^5 w f, g
- case 75 : floaty--;break; //左
7 w7 W: m- p( y @% }% U* J - case 77 : floaty++;break; //右
9 [5 c% W X7 v, P* Z - }
3 [$ X9 q% g' E6 G, Y J% ] N - if(floatx==-1) floatx=A-1; floatx%=A; //两端穿模处理 9 @: Z) G# x; G0 |7 r8 i) `
- if(floaty==-1) floaty=B-1; floaty%=B;
7 w" D# N! G- Z - % a$ x% \0 t3 ]" S* I2 H% c
- position(yyy*2,xxx);/ Q+ C3 E7 ` ^6 D, W( }. s) ]2 r! L8 {
- SetConsoleTextAttribute(handle_out, FORE_GREEN);
7 ]0 p" {) }* C- e - Lump(xxx,yyy); //删除原位置
( l! M3 c# M$ A( A# T* X - 9 W9 T. `; u# X
- if(map[floatx][floaty]=='x') {
" c3 K/ O2 d# ^' g2 N" E - position(floaty*2,floatx);
% {) W& H: n. s: G0 S3 { - printf(" ");3 g- [( G2 m! q
- }, A9 l2 V k3 w% \ m( J( \
- % y* _$ _3 {3 b# m- h( d0 P
- position(floaty*2,floatx);
8 e: o& Q7 a7 \2 z - SetConsoleTextAttribute(handle_out, FORE_BLUE); 0 U+ C* U9 t& m s/ j! E, h+ f3 k
- Lump(floatx,floaty); //更新新位置 . M7 K3 o! _1 Z- m0 ?& F3 r
- } - x. K0 S0 L$ i$ u* Y! E3 n
-
4 r ^# \# t/ k9 _% o( B4 D - //插旗和排雷模式切换
' r7 ?4 x) |* | _ - void Mode() {! z, w( N: K- X
- HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
1 }9 L4 b( h' W8 m7 Z- d4 u" z - CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
1 a! U! P2 ~7 H+ |$ }7 z& z" M5 j, V - GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息# M$ g6 f1 k2 N( e* U& X& t! H/ V
- mode++;# f. Y8 s7 i% z7 ]* E
- SetConsoleTextAttribute(handle_out, FORE_BLUE);7 s$ G! U9 d* }, E' C3 j* C
- position(floaty*2,floatx);$ I" z1 C4 J0 }* T/ z9 }
- if(mode%2==0) printf("");
1 x: f8 n- s+ _8 d - else printf("");
. P$ F; E9 X6 s5 T# F& L4 {$ b3 y -
- x% h* O9 T3 j4 O; w0 h* v - position(44,9);- c9 v8 J7 M0 ]; K8 T k
- if(mode%2==0) {
, S# L9 n0 R8 X7 P- H - SetConsoleTextAttribute(handle_out, FORE_BLUE);
6 n8 Z- b3 r) b4 b. T2 { - printf("扫雷模式");& r8 C+ |4 S$ b l" |0 ~9 Z1 W
- }! G8 O' H' o7 A3 g' L" ]9 H
- else {
, }! `2 W# r { - SetConsoleTextAttribute(handle_out, FORE_RED);
% H% o, q& Q. r; K9 n. q& A - printf("插旗模式");" y* I4 C0 ^7 e$ ], j' R
- } ^; d( _+ ]% K4 L; c6 L# x \
- }
% s7 m; K5 m# `! O) I) _ -
: j# m8 _/ X/ S" o: f - //该点周围地雷数 1 ~! j$ ? L7 Q$ u
- int Boomnum(int xx,int yy) {# q9 g. @) N% v! H7 k! ]( `; W
- int num=0;
1 \0 a1 k! ]2 B6 I3 ` - if((xx-1>=0)&&(yy-1>=0)&&(map[xx-1][yy-1]=='@')) num++;
& L( X9 }# j" K - if((xx-1>=0)&&(yy+0>=0)&&(map[xx-1][yy]=='@')) num++;
; I7 s/ @$ p2 ^7 g, ~4 ^, H8 i( Y r - if((xx-1>=0)&&(yy+1<B) &&(map[xx-1][yy+1]=='@')) num++;
, H2 H: E1 d2 v8 v - if((xx+0>=0)&&(yy-1>=0)&&(map[xx][yy-1]=='@')) num++;0 R' Q( v T. ^) x
- if((xx+0>=0)&&(yy+1<B) &&(map[xx][yy+1]=='@')) num++;% ^; b$ T: F+ k4 }& F9 A1 K
- if((xx+1<A)&&(yy-1>=0) &&(map[xx+1][yy-1]=='@')) num++;
* ^& v# I- F0 C5 X/ S - if((xx+1<A)&&(yy+0>=0) &&(map[xx+1][yy]=='@')) num++;
4 w3 G) S' Q9 k) r# h A' Z - if((xx+1<A)&&(yy+1<B) &&(map[xx+1][yy+1]=='@')) num++;! f8 T8 P9 B0 M1 X
- return num;9 N' S! E# D7 K! n n
- }4 F7 |& R/ F3 Y
- 5 |/ R4 d! u5 V1 O( n
- //更新地图 8 A7 t; E) h6 k( `/ ?
- void Open() {
1 W& Z, s* b4 j$ Q+ Q) n+ n) y - node c;, P6 |# W- ]) x. o3 N! a1 N5 Q: s
- node d;, K" V7 [! q. ~0 P* y3 U% m, E
- while(!dui.empty()) {
0 M$ J! W5 P3 ]0 _! M/ V1 j$ N - dui.pop();" q3 U$ L5 R9 L; b- T
- }6 r$ o3 b8 b- O0 H ~% Z& F
- c.x=floatx;
* C4 W' Q& s/ A9 `2 _! w1 a - c.y=floaty;
) Z5 U' a3 r" x/ H - dui.push(c);
; `* O2 W' L5 x+ E1 c - slect[c.x][c.y]=1;
7 X, a. {) \6 ^2 L4 X2 \ - while(!dui.empty()) {
! O D4 U1 o1 F; p5 ]) N - c=dui.front();0 P4 E; w& ^5 t
- dui.pop();
- C3 ^5 I- `& g) K* {+ R1 m, ?" O - if(Boomnum(c.x,c.y)!=0) {8 Z+ R; m7 r3 k
- map[c.x][c.y]=(Boomnum(c.x,c.y)+48);: {6 z' e2 i- u8 K" x4 t
- continue;8 l! c2 {* u* ~* f- y* P( I
- }
+ c* K+ d& x* f2 r# L N6 V - else {
; L) }2 _6 y8 Y2 D0 y4 Q - map[c.x][c.y]='x';
6 W; f% @, E, C3 g% H4 [9 F - if((c.x-1>=0)&&(c.y-1>=0)&&(map[c.x-1][c.y-1]==' ')&&(slect[c.x-1][c.y-1]==0)) {
0 g2 s/ B5 t8 T L - d.x=c.x-1;/ _: i0 t Q3 V5 U# A
- d.y=c.y-1;
9 N6 v8 a1 A2 s3 }% _0 R5 k - dui.push(d);
1 k9 u q) H: H5 }0 S( m/ C - slect[d.x][d.y]=1; T0 ?6 N* u( X$ d( Z! B
- }& f% v U+ [' n
- if((c.x-1>=0)&&(c.y-0>=0)&&(map[c.x-1][c.y]==' ')&&(slect[c.x-1][c.y]==0)) {( v# Y# g, w7 [2 b4 E8 u
- d.x=c.x-1;
9 d; ~/ Q( k3 G7 E- B$ H& V' L - d.y=c.y-0;
4 |9 B" y' r, \3 y - dui.push(d);
# Z0 \- I9 D& s1 \ - slect[d.x][d.y]=1;
1 i, H4 w X+ r! W$ T* } - }
. V# ?- D0 f+ ^2 j* r1 |* m - if((c.x-1>=0)&&(c.y+1<B)&&(map[c.x-1][c.y+1]==' ')&&(slect[c.x-1][c.y+1]==0)) {
' c, f0 O# @" L* T( p- ? ?5 F3 k - d.x=c.x-1;$ S1 v3 l# b# G# [# ]: W
- d.y=c.y+1;
$ g3 \! Z; {) ]' A% V& O: q - dui.push(d);$ e& M) `" q7 g0 l+ Z% i
- slect[d.x][d.y]=1;
, h ], f' E5 b5 l& d& O - }
' a, l3 h& T" L! F - if((c.x-0>=0)&&(c.y-1>=0)&&(map[c.x][c.y-1]==' ')&&(slect[c.x][c.y-1]==0)) {
, z6 x, |" s) e* \) f1 b - d.x=c.x-0;
) r; Q6 S B1 b2 [, I c& U6 h - d.y=c.y-1;! W1 Q% n7 k" l" S! Y; P: B
- dui.push(d);
! `; E' Z0 S; n - slect[d.x][d.y]=1;. N2 @3 p" s/ K* ]
- }5 H# s2 Y9 u) i& o* J
- if((c.x-0>=0)&&(c.y+1<B)&&(map[c.x][c.y+1]==' ')&&(slect[c.x][c.y+1]==0)) {
4 ]# j# `( }* O: D4 k1 [8 k8 I - d.x=c.x-0;: s+ L7 ]7 v( \% D# b* F0 d% ^, c- [
- d.y=c.y+1;, \. `) q/ G$ l* q. a( U
- dui.push(d);- @) ~/ ?' T" d6 K) v& D3 Q* g, A- O
- slect[d.x][d.y]=1;* i8 m: U4 o( I; d* b; J- s! t9 T
- }
3 U, |; o# N- T0 v& a( r - if((c.x+1<A)&&(c.y-1>=0)&&(map[c.x+1][c.y-1]==' ')&&(slect[c.x+1][c.y-1]==0)) {% U9 g& j' x5 ?
- d.x=c.x+1;* R6 ~2 Q# {8 R) F" N2 b1 t5 C
- d.y=c.y-1;( J( l* M+ @- i4 M; _: Y1 u4 b
- dui.push(d);9 I+ I+ u0 \# @7 F
- slect[d.x][d.y]=1;/ d. \5 C% P2 I; t! i M4 Z0 P: w2 U
- }
( z* K/ \) {+ D( }1 f8 |( [, | - if((c.x+1<A)&&(c.y-0>=0)&&(map[c.x+1][c.y]==' ')&&(slect[c.x+1][c.y]==0)) {
9 m( Y, i; f) ]) X5 T - d.x=c.x+1;. G& d/ D% j, G
- d.y=c.y-0;9 {$ c+ p' }8 n1 F# h6 ]2 v" [ b
- dui.push(d);
9 O+ Y# f [1 \' ^2 R - slect[d.x][d.y]=1;
: {- ] [; r. T0 m" c. i - }
* O! O9 G# c Y, o- k: q9 ] - if((c.x+1<A)&&(c.y+1<B)&&(map[c.x+1][c.y+1]==' ')&&(slect[c.x+1][c.y+1]==0)) {1 v& Y& y: i) s7 f" _
- d.x=c.x+1;9 {1 I, ?+ ]7 B4 O3 P
- d.y=c.y+1;
/ f/ ?0 K) ~; y3 }* r - dui.push(d);( V! ?- j' y3 F! l) R* s. C* c5 S
- slect[d.x][d.y]=1;8 W3 ]. y' U. ~
- }3 D9 C& S8 L% s) ^: s# A
- }
" Y* _: U& I3 Y- m* Z - }" w& h5 u: a4 g3 z$ b9 q% y, e
- }
- m$ r! g2 ?1 y1 y/ i - " B9 c, [" |8 I4 ^
- int main() {
0 @5 W# U0 f$ {- G - freopen("排名.txt","r",stdin);# |9 z0 S( z) ^, W6 c" E% j
- Relife: //重玩处$ S5 a; t3 n7 o4 J2 P6 x0 V9 H+ R
- HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 4 ?8 ^+ e5 E0 J
- CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
. b6 f# o6 ]. v' P/ l4 a - GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息0 L0 [1 ^) V% O1 e8 A
- ) T1 H6 y% p8 V, `
- Hide(); - A* q1 J! H! `8 p ]% c
- Beginning();8 B2 t, Z, f- U: Y" E3 s0 V A9 ^
- a=GetTickCount();4 f6 j5 Z+ a# L- } {/ y
- while(1) {
; E8 G! X# T. Q9 B - if(kbhit()!=0) {
) N* Z/ j' C1 ~0 P' ]6 a# D - spare=getch();7 v( C; _# J4 x
- $ F8 G+ z( J4 q; Y* P
- 5 Q, l- B* J8 E s# w) D
- if((spare!=(-32))&&(spare!=13)&&(spare!=' ')) continue; y5 i( ]- w. E/ c0 u9 c" x3 `& o
-
) \$ H7 G* k& [& _; Y - ) B6 \* w) E& C# E. J0 c( D
- if(spare==13) {;
* u) q/ w( z( Z3 Y% e - 1 o' z+ i( E" {2 `1 E+ t8 X
- if(mode%2==0) {
4 P+ S- d7 f+ Z/ P - if(map[floatx][floaty]=='@'&&flag[floatx][floaty]==0) {/ m) }3 r- [8 V+ H
- break; 7 _/ R$ R% c5 I- p
- game=0;
- M" k* y) R' m# C. S - }
$ ?' n% j$ x/ @8 F$ m3 T& W% B - / T# Q( n* o; F, T
- if(flag[floatx][floaty]==1) continue;
5 f7 y4 X [* b& j - Open();
/ T$ S+ r$ k6 B6 A' N; V7 W& i5 H - position(0,0);
( ^2 D& w7 C, X - SetConsoleTextAttribute(handle_out, FORE_GREEN);$ ~+ `" C1 H# e' H( l M. T- e
- for(int i=0;i<A;i++) {
7 S3 o' I3 R7 y8 }+ c+ [ - for(int j=0;j<B;j++) Lump(i,j);1 f7 w; _; [& H: \! S
- printf("\n");+ R( S! X# U8 i, X
- }
, k& K1 F" J: k) ?- _ - position(floaty*2,floatx);
; p" y8 h% N M3 P, I8 y% t: ^ - SetConsoleTextAttribute(handle_out, FORE_BLUE);3 B$ d E) m: j
- Lump(floatx,floaty);
7 H! R: S% R( v, W( n) \, y - }& \* n4 w f, [$ ?
- + }+ j3 c9 G. C/ z" z+ a! ]
- 1 p6 {2 R' I# `7 i. U
- else {/ `4 Q2 w, Y8 s5 ]% l# N6 L1 B
-
# n5 j/ b4 Y2 E/ W) W6 l/ U - 5 F9 [( c8 R$ t9 O- g# J4 c
- if(map[floatx][floaty]=='x'||(map[floatx][floaty]>'0'&&map[floatx][floaty]<'9'))
; u2 v6 O* v6 U9 g5 R - continue;
8 J* ?! S7 v- j3 N - + ~0 v0 v& ~% \8 e) R4 q& e
-
4 w! m: [. \5 ^3 I' E: b- O - if(flag[floatx][floaty]==0) {
) M% l8 ~$ ]1 J `% r% c& y - flagnum++;
! r- N- j; y+ L9 F! W8 }: I Y - flag[floatx][floaty]=1;3 j4 D0 \7 Q; t+ z& |! l9 w
- position(floaty*2,floatx);$ v, K( k5 A$ J @3 ]2 s- W( @/ O
- SetConsoleTextAttribute(handle_out, FORE_BLUE);" n+ b p# g& N
- Lump(floatx,floaty);
$ c7 q- n8 M+ v/ s - }
7 |1 n; z+ {' I- t1 ~" v5 F -
" m! ^# r! b9 I L' H -
6 k; F, c9 {3 E l* L8 F0 H - else {
( \& }' V: T" A8 @( b5 h - flagnum--;
; y/ _4 }6 f: S( f2 p - flag[floatx][floaty]=0;
/ V3 y2 t* v# u5 r. d9 X - position(floaty*2,floatx);
% ~6 ^ @ O+ h+ ?- L7 @' V) K/ F - SetConsoleTextAttribute(handle_out, FORE_BLUE); a4 ~$ {8 c, L
- Lump(floatx,floaty);7 J3 F0 w5 B* n
- }
9 B9 C4 E5 @% z- D& O, m6 Z7 A - }4 `* X/ [1 ^9 g4 @6 `
- }
( G: Q& f+ E' t7 W - : J( {8 B! q! T- h9 c
- 5 c0 o* C; u. c. ^* q. J
- if(spare==' ') Mode();
7 _! s0 @7 Z4 `. E5 K -
6 n. w4 k) p! F2 u& Y - //按方向键
% _. @+ i% R" i - if(spare==-32) {
1 j$ i5 C7 h1 `) ~8 ^ - news=getch();
7 l% x( \3 l- s0 q. d - Move();
) o4 A+ ]4 ~0 L9 _" E0 f+ A' } - }
/ X: [& p4 N# l' H0 G - for(int i=0;i<A;i++) for(int j=0;j<B;j++) if(map[i][j]=='x'||(map[i][j]>'0'&&map[i][j]<'9')) game++;
# Z+ p) T0 c1 ~# y: h( r% k - if(game==A*B-C+1) break;" t+ x3 j3 ~9 p' Y4 z- A t' I
- else game=1;
; ]. n$ W2 k4 p5 Y - SetConsoleTextAttribute(handle_out, FORE_RED);
+ Z; S% E. g+ f - position(44,5);
2 C5 h- r6 S" T/ [" ^1 u - printf("剩余雷数:%d ",C-flagnum);2 `! b1 s! w9 J5 m; x+ t' {
- }
% x! a m J1 [8 V& G+ a* O - else Sleep(10); ^* g1 @4 ^ x# y* }
- b=GetTickCount();
2 n: w. r! d8 ]' f- U4 }# E- l& ~6 l - SetConsoleTextAttribute(handle_out, FORE_RED);
3 `$ f4 J7 ?! }( b* L9 e7 l' t* J - position(44,7);
9 }5 X' ~; K* O( I# i9 ` - printf("用时:");
$ P" X$ i$ ^* R: W: X - if((b-a)/60000<10) printf("0");8 c! c/ M5 q8 t7 J' g9 P- F
- printf("%d:",(b-a)/60000);* Y' X. n0 I" O- x- T! S
- if(((b-a)/1000)%60<10) printf("0");
- P4 [5 h$ R, N5 B k) w3 A( R - printf("%d:",((b-a)/1000)%60);9 F% |1 I) a' _ r1 T ^
- if(((b-a)/10)%100<10) printf("0");; Z5 ?* H. ]6 w$ Q4 a: e3 f
- printf("%d",((b-a)/10)%100);
% V, e" U) K4 D0 L! x6 e! R0 L - }" ?1 Q- G6 o4 P* L7 U4 v4 s/ [
- SetConsoleTextAttribute(handle_out, FORE_RED);
% [: v0 u$ ^2 G$ \* y) w8 ~2 i' E: P - position(5,5);
0 N5 V0 c, |! E( B. R X: [$ M - if(game==1) printf("游戏结束!");5 d6 E, N: a A) Z
- else printf("恭喜通关!");4 F @0 {3 v7 e. f/ L
- position(5,8);
, B ]8 [' p2 j) `9 V: H4 t - printf("任意键重玩");( r& T1 ?& }( X& @0 L' v8 _6 y* @
- scanf("%c%c",&spare,&spare);
7 ?$ Z1 e/ w4 L5 C$ R: m. u - system("cls");
9 Z2 u' q3 c( L, f% p/ |1 u6 V" c - position(0,0);
: } g5 U8 G+ J - goto Relife;0 H' n- w; M! w! t; ?; x
- }
复制代码
6 v' z9 G% t( v' p
+ `" X( E& L t+ i% E1 ~, c$ k" D) T8 }; ?
|
|