扫地雷II
感谢格致杭业晟同学改进完善
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的更多相关文章
- Pascal语言(存档)
数据类型 标准函数 运算符和表达式 输入语句 输出语句 if语句 case语句 for语句 while语句 repeat语句 函数与过程 形参与实参 全局变量与局部变量 数组 字符串 枚举 子界 集合 ...
- [SDFZOJ]1069:树上统计
神题...std丑的不行. 我们可以发现i->i+1的边被覆盖过i×(n-i)次. 因为以1->i为左端点,以i+1->n的为右端点,i->i+1都将被覆盖这么多次. 然后从1 ...
- 洛谷P1372 又是毕业季I&&P1414 又是毕业季II[最大公约数]
P1372 又是毕业季I 题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚 ...
- Android安全开发之WebView中的地雷
Android安全开发之WebView中的地雷 0X01 About WebView 在Android开发中,经常会使用WebView来实现WEB页面的展示,在Activiry中启动自己的浏览器,或者 ...
- [LeetCode] Palindrome Partitioning II 解题笔记
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- LeetCode :Word Ladder II My Solution
Word Ladder II Total Accepted: 11755 Total Submissions: 102776My Submissions Given two words (start ...
- 2020: [Usaco2010 Jan]Buying Feed, II
2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 220 Solved: 162[ ...
- [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 就是给你一个字符串,能不 ...
- LeetCode: Jump Game II 解题报告
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
随机推荐
- iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期
iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期 一.基本过程 新建一个项目,系统默认的主控制器继承自UIViewController,把主控制器两个文件删掉. 在stor ...
- [转]HttpURLConnection的使用
/* * URL请求的类别分为二类,GET与POST请求.二者的区别在于: * a:) get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet, * b:) post与get ...
- 最大流 总结&&做题记录
最近一直很忙,为了节省时间,从今以后的题解会 一个专题 写一篇. 刷了一些题后,有了以下总结: 模型要点: 1.构造流量平衡,在满足流量平衡的情况下,找到要让什么最大. 2.一般用于判断性问题,即所有 ...
- enmo_day_05
大文件表空间 小文件表空间 临时表空间 :不需自己删除,session断了之后自动删除 永久表空间 : 本地管理表空间 :使用位图表示表空间,0表示没有数据,1表示有数据, 数据字典管理表空间 eg ...
- C++ explicit关键字应用方法详解
C++编程语言中有很多比较重要的关键字在实际编程中起着非常重要的作用.我们今天为大家介绍的C++ explicit关键字就是其中一个应用比较频繁的关键字.下面就让我们一起来看看这方面的知识吧. C++ ...
- 关于jquery中的事件绑定bind()和live()
live可以说是bind是方法的变种. 二者的主要区别就是live方法的作用机理是事件委托,live方法的作用机理是将事件绑定DOM的根节点上. live方法的处理机制就是把事件绑定在DOM树的根节点 ...
- Padding Oracle Attack的一些细节与实现
Padding Oracle Attack还是颇具威力的,ASP.NET的Padding Oracle Attack被Pwnie评为2010年最佳服务端漏洞之一.还是看 Juliano Rizzo a ...
- Windows Server 2008(R2)配置apache+php+mysql环境问题事项
服务器环境:Windows 2008 R2 64位.apache,mysql,php都是32位. 1. 80端口的外网访问问题 表现:80端口本地可以访问,外网不能访问,换了8080端口也是一样,检查 ...
- Warning: Attempt to dismiss from view controller <UIViewController: 0x17d71c10> while a presentation or dismiss is in progress!
昨天 调试程序 已经快要上线了 突然有个BUG 找了半天 才找到是因为这个警告 但是 解决这个警告又花了一天的时间 试了各种消除控制器的方法 都不可用 其中 并且 有这个bug 手机真机测试完全没问 ...
- [转]一个简单的Linux多线程例子 带你洞悉互斥量 信号量 条件变量编程
一个简单的Linux多线程例子 带你洞悉互斥量 信号量 条件变量编程 希望此文能给初学多线程编程的朋友带来帮助,也希望牛人多多指出错误. 另外感谢以下链接的作者给予,给我的学习带来了很大帮助 http ...