感谢格致杭业晟同学改进完善

uses crt;
var
  i,j,k,ls,x,y:byte;
  b:array[0..11,0..11] of shortint;
  f:array[0..11,0..11] of boolean;
  c:char;
procedure a;  //光标往左
begin
  gotoxy((x+2)*2,y+3);  //恢复上一个位置
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  if x=0 then x:=9
         else x:=x-1;
  textbackground(white);  //更新新位置
  textcolor(black);
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  textbackground(black);
  textcolor(white);
end;
procedure w;
begin
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  if y=0 then y:=9
         else y:=y-1;
  textbackground(white);
  textcolor(black);
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  textbackground(black);
  textcolor(white);
end;
procedure d;
begin
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  if x=9 then x:=0
         else x:=x+1;
  textbackground(white);
  textcolor(black);
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  textbackground(black);
  textcolor(white);
end;
procedure s;
begin
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  if y=9 then y:=0
         else y:=y+1;
  textbackground(white);
  textcolor(black);
  gotoxy((x+2)*2,y+3);
  if f[y+1,x+1] then write(b[y+1,x+1])
                else write('?');
  textbackground(black);
  textcolor(white);
end;
begin
  clrscr;
  cursoroff;
  fillchar(f,sizeof(f),false);
  randomize;
  for i:=1 to 10 do  //随机生成地雷(10%,-1表示地雷格),并统计地雷个数
    for j:=1 to 10 do begin
      k:=random(10);
      if k=0 then b[i,j]:=-1
             else b[i,j]:=0;
      if b[i,j]=-1 then inc(ls);
    end;

for i:=1 to 10 do  //计算非地雷格周边的地雷数
    for j:=1 to 10 do
      if b[i,j]=0 then begin
        if b[i-1,j-1]=-1 then inc(b[i,j]);
        if b[i-1,j]=-1 then inc(b[i,j]);
        if b[i-1,j+1]=-1 then inc(b[i,j]);
        if b[i,j-1]=-1 then inc(b[i,j]);
        if b[i,j+1]=-1 then inc(b[i,j]);
        if b[i+1,j-1]=-1 then inc(b[i,j]);
        if b[i+1,j]=-1 then inc(b[i,j]);
        if b[i+1,j+1]=-1 then inc(b[i,j]);
      end;
  writeln('   0 1 2 3 4 5 6 7 8 9');  //输出初始界面
  writeln(' .--------------------.');
  for i:=1 to 10 do begin
    write(i-1,'|');
    for j:=1 to 10 do write(' ?');
    write('|');
    writeln;
  end;
  writeln(' .-------------------.');

x:=0;  //光标定位到左上角
  y:=0;
  textbackground(white);
  textcolor(black);
  gotoxy((x+2)*2,y+3);
  write('?');
  textbackground(black);
  textcolor(white);
  while (100-ls)>0 do  //扫雷开始
    if keypressed then begin
      c:=readkey;
      if c='w' then w;
      if c='a' then a;
      if c='s' then s;
      if c='d' then d;
      if c=' ' then  //如果按空格
        if b[y+1,x+1]=-1 then begin  //如果这格是地雷
          clrscr;
          textcolor(lightred);
          writeln('Bomb! You Lose!');
          writeln('Press Enter to Exit');
          readln;
          exit;
        end
        else begin  //如果这格不是地雷
          textbackground(white);
          textcolor(black);
          gotoxy((x+2)*2,y+3);
          write(b[y+1,x+1]);
          textbackground(black);
          textcolor(white);
          f[y+1,x+1]:=true;
          inc(ls);
        end;
  end;
  clrscr;
  textcolor(yellow);
  writeln('You Win!');
  writeln('Press Enter to Exit');
  readln;
end.

扫地雷II的更多相关文章

  1. Pascal语言(存档)

    数据类型 标准函数 运算符和表达式 输入语句 输出语句 if语句 case语句 for语句 while语句 repeat语句 函数与过程 形参与实参 全局变量与局部变量 数组 字符串 枚举 子界 集合 ...

  2. [SDFZOJ]1069:树上统计

    神题...std丑的不行. 我们可以发现i->i+1的边被覆盖过i×(n-i)次. 因为以1->i为左端点,以i+1->n的为右端点,i->i+1都将被覆盖这么多次. 然后从1 ...

  3. 洛谷P1372 又是毕业季I&&P1414 又是毕业季II[最大公约数]

    P1372 又是毕业季I 题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚 ...

  4. Android安全开发之WebView中的地雷

    Android安全开发之WebView中的地雷 0X01 About WebView 在Android开发中,经常会使用WebView来实现WEB页面的展示,在Activiry中启动自己的浏览器,或者 ...

  5. [LeetCode] Palindrome Partitioning II 解题笔记

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  6. LeetCode :Word Ladder II My Solution

    Word Ladder II Total Accepted: 11755 Total Submissions: 102776My Submissions Given two words (start  ...

  7. 2020: [Usaco2010 Jan]Buying Feed, II

    2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 220  Solved: 162[ ...

  8. [leetcode]Weekly Contest 68 (767. Reorganize String&&769. Max Chunks To Make Sorted&&768. Max Chunks To Make Sorted II)

    766. Toeplitz Matrix 第一题不说,贼麻瓜,好久没以比赛的状态写题,这个题浪费了快40分钟,我真是...... 767. Reorganize String 就是给你一个字符串,能不 ...

  9. LeetCode: Jump Game II 解题报告

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

随机推荐

  1. c# mvc使用 npoi下载 excel

    IWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); //添加一个sheet ISheet sheet1 = book.CreateShee ...

  2. 更换内核后重编virtualbox内核模块

    这些天编译了一个4.1.15内核,因此vb原来的模块就不能用了,因此要重新编译(当然,reinstall也可以,觉得大动干戈,不符合个人做事风格) 如果不重编运行会有如下错误提示: # virtual ...

  3. android studio 开启genymotion 出现"failed to create framebuffer image"

    出现错误 Unable to start the virtul device To start virtual devices, make sure that your video card supp ...

  4. Oracle Metadata Management (OMM)元数据管理 12.2.1发布

    元数据管理元数据管理是解决大量关键业务和技术挑战的基础,这些挑战包括元数据实体有多少,上游数据变化的影响,在浏览器中提供友好的分析展现界面,或提供企业范围内的元数据现状分析和改进视图.OMM是一款基于 ...

  5. hive的基本操作

    1.创建表 First, create a table with tab-delimited text file format: (1)CREATE TABLE u_data ( userid INT ...

  6. UE4 - C++ 射线捕捉

    #include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h" //省略大部分代码 void AMyFPS_Charact ...

  7. 大数据批量插入数据库使用(SqlBulkCopy )效率更高

    SqlBulkCopy类是System.Data.SqlClient下的类,我们开发中不常用,甚至不知道有这么一个类的存在,但确实比sql插入,事务批量插入,sql批量拼接插入快很多,比调用存储过程插 ...

  8. Python 基礎 - 認識模塊

    什麼是模塊?簡單說就是別人寫好了一堆功能,封裝在一起. 模塊有分二種,一個是之前有提到的 標準庫,就是不需要透過額外的安裝就有的模塊 ,另一個叫 第三方庫,需要另外安裝才能使用的模塊 #!/usr/b ...

  9. ios项目接入sdk事项

    使用cocos2d-x引擎创建的项目在xcode里可以看到都带有一个ios目录,把要接入的sdk的包含.framework库文件和.bundle的资源文件的父目录拖入到xcode项目里的这个ios目录 ...

  10. Python 利用pytesser模块识别图像文字

    使用的是python的pytesser模块,原先想做的是图片中文识别,搞了一段时间了,在中文的识别上还是有很多问题,这里做记录分享. pytesser,OCR in Python using the ...