〓〓 ̄ ̄扫雷 ̄ ̄★
pascal吧
全部回复
仅看楼主
level 1
肥姆斯 楼主
uses crt;label 1;varo,ido,check:array[1..16,1..30]of boolean;board:array[1..16,1..30]of char;now:1..4;x,y,i,j:word;n:integer;win:boolean;procedure checkwin;var i,j:word;beginfor i:=1 to x dofor j:=1 to y doif check[i,j]<>ido[i,j] then exit;clrscr;textcolor(yellow);textbackground(black);gotoxy(5,10);write('You win!');readln;win:=true;exit;end;procedure fail;beginclrscr;textcolor(yellow);textbackground(black);clrscr;gotoxy(5,10);write('You fail!');readln;win:=true;exit;end;procedure openit(m,n:word);var h,z:integer;begino[m,n]:=false;gotoxy(n*2-1,m+2); write(board[m,n]); o[m,n]:=false;for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in [1..x]))or(not(n+z in [1..y])) then continue;if (h=0)and(z=0) then continue;if ido[m+h,n+z] then continue;if not o[m+h,n+z] then continue;if board[m+h,n+z]=' ' then openit(m+h,n+z);gotoxy((n+z)*2-1,m+h+2); write(board[m+h,n+z]); o[m+h,n+z]:=false;end;end;procedure try(m,n:word);var h,z,k:integer;f:boolean;begink:=0; f:=true;if (board[m,n]in['1'..'9'])and(not o[m,n]) then beginfor h:=-1 to 1 dofor z:=-1 to 1 dobeginif(not(m+h in[1..x]))or(not(n+z in[1..y]))then continue;if ido[m+h,n+z] then inc(k);end;if ord(board[m,n])-48<=k then f:=false;end;if f then begintextcolor(yellow);for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;gotoxy((n+z)*2-1,m+h+2); write('*');end;delay(250); textcolor(green);for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;gotoxy((n+z)*2-1,m+h+2); write('=');end;textcolor(white);end elsefor h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;if board[m+h,n+z]=' ' then openit(m+h,n+z) else beginif board[m+h,n+z]='#' then fail;if board[m+h,n+z]in['1'..'9'] then begingotoxy((n+z)*2-1,m+h+2); write(board[m+h,n+z]); o[m+h,n+z]:=false; end;end;end;end;procedure p;var nn,h,z:integer;beginrandomize; fillchar(board,sizeof(board),' ');fillchar(check,sizeof(check),false);for i:=1 to n dobeginrepeath:=random(x)+1; z:=random(y)+1;until not check[h,z];board[h,z]:='#';check[h,z]:=true;end;for i:=1 to x dofor j:=1 to y dobeginif board[i,j]='#' then continue;nn:=0;for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(i+h in [1..x]))or(not(j+z in [1..y])) then continue;if (h=0)and(z=0) then continue;if board[i+h,j+z]='#' then inc(nn);end;if nn<>0 then board[i,j]:=chr(48+nn);end;end;procedure zuobi;var i,j:word;begintextcolor(blue);for i:=1 to x dofor j:=1 to y doif board[i,j]='#' then begin gotoxy(j*2-1,i+2); write('='); end;textcolor(white);end;begin1:now:=1; textcolor(white); win:=false;textbackground(black);clrscr;gotoxy(25,8); write('> EASY');gotoxy(27,9); write('NORMAL');gotoxy(27,10); write('HARD');gotoxy(27,11); write('DIY');gotoxy(19,14); write('Press Space to continue.');
2007年03月30日 15点03分 1
level 1
肥姆斯 楼主
repeatcase readkey of
#0:case upcase(readkey) of#
80:if now<4 then begin gotoxy(25,7+now); write(' ');inc(now); gotoxy(25,7+now); write('>'); end;#72:if now>1 then begin gotoxy(25,7+now); write(' ');dec(now); gotoxy(25,7+now); write('>'); end;end;' ':break;end;until false;clrscr;case now of1:begin x:=9; y:=9; n:=10; end;2:begin x:=16; y:=16; n:=40; end;3:begin x:=16; y:=30; n:=99; end;4:begin repeat clrscr; gotoxy(27,10); write('Length:'); readln(y); until y in[1..30];repeat clrscr; gotoxy(3,12); write('Width:'); readln(x); until x in[1..16];repeat clrscr; gotoxy(18,19); write('Number of bomb:'); readln(n); until n<=x*y;clrscr;end;end;gotoxy(1,3);textbackground(red);textcolor(green);for i:=1 to x dobeginfor j:=1 to y do write('= ');writeln;end;textcolor(white);p; i:=1; j:=1;gotoxy(1,1); write('Space for open, "b" for try, "v" for sign.');gotoxy(5,23); write(n:3,' left.');gotoxy(j*2,i+2); write('<');fillchar(ido,sizeof(ido),false);fillchar(o,sizeof(o),true);while not win dobeginwhile not keypressed do delay(100);case readkey of
#0:case upcase(readkey) of#
75:if j>1 then begin gotoxy(j*2,i+2); write(' ');dec(j); gotoxy(j*2,i+2); write('<'); end;#80:if i
1 then begin gotoxy(j*2,i+2); write(' ');dec(i); gotoxy(j*2,i+2); write('<'); end;end;'v','V':if(not o[i,j]and ido[i,j])or(not ido[i,j]and o[i,j])then beginido[i,j]:=not ido[i,j];if ido[i,j] then begin dec(n); gotoxy(5,23); write(n:3); o[i,j]:=false;textcolor(yellow); gotoxy(j*2-1,i+2); write('!'); textcolor(white); end else begininc(n); gotoxy(5,23); write(n:3); gotoxy(j*2-1,i+2); textcolor(green);write('='); textcolor(white); o[i,j]:=true; end;end;' ':if o[i,j] then if board[i,j]=' ' then openit(i,j) else beginif board[i,j]='#' then fail;if board[i,j]in ['1'..'9'] then begingotoxy(j*2-1,i+2); write(board[i,j]); o[i,j]:=false; end;end;'b','B':try(i,j);'|':zuobi;end;if n=0 then checkwin;end;textcolor(white);textbackground(black);clrscr;gotoxy(15,15); write('Play again? (Y/N)');repeatcase readkey of'Y','y':goto 1;'n','N':halt;end;until false;end.
2007年03月30日 15点03分 2
1