与众不同的扫雷之三

[size=medium]
革命尚未成功!同志仍需努力! :D

有了各个海域的精确位置以及分布情况,就可以根据经纬度在大海上定位了 :D
[/size]


function make_ocean_chart(origin_map, current_map, width, position)
local ocean = classfy_sea_area(origin_map, current_map, width)
local ocean_index = 0
for i1, v1 in ipairs(ocean) do
for i2, v2 in ipairs(v1) do
if (position >= v2[1]) and (position <= v2[2]) then
ocean_index = i1
break
end
end
end
if ocean_index ~= 0 then
local t = current_map
for i, v in ipairs(ocean[ocean_index]) do
t = make_coastline(origin_map, t, width, v)
end
return t, compare_map(current_map, t)
end
return current_map, ""
end


[size=medium]
描绘大海的同时还要记得把海岸线也画出来。
[/size]


function make_coastline(origin_map, current_map, width, sea_area)
local sea_area_west = sea_area[1]
local sea_area_east = sea_area[2]
if sea_area[1] % width ~= 1 then
sea_area_west = sea_area_west - 1
end
if sea_area[2] % width ~= 0 then
sea_area_east = sea_area_east + 1
end

if sea_area_west - width >= 1 then
current_map = string.sub(current_map, 1, sea_area_west - width - 1) ..
string.sub(origin_map, sea_area_west - width, sea_area_east - width) ..
string.sub(current_map, sea_area_east - width + 1, -1)
end
current_map = string.sub(current_map, 1, sea_area_west - 1) ..
string.sub(origin_map, sea_area_west, sea_area_east) ..
string.sub(current_map, sea_area_east + 1, -1)
if sea_area_east + width <= #current_map then
current_map = string.sub(current_map, 1, sea_area_west + width -1) ..
string.sub(origin_map, sea_area_west + width, sea_area_east + width) ..
string.sub(current_map, sea_area_east + width + 1, -1)
end
return current_map
end


[size=medium]
至此,扫雷游戏的算法全部描述完毕 :D
[/size]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值