赞 | 42 |
VIP | 91 |
好人卡 | 5 |
积分 | 110 |
经验 | 80759 |
最后登录 | 2024-11-16 |
在线时间 | 4430 小时 |
Lv4.逐梦者
- 梦石
- 1
- 星屑
- 10049
- 在线时间
- 4430 小时
- 注册时间
- 2005-10-22
- 帖子
- 6953
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
#################################################################
#作者:orochi2k
#请保留此段说明信息
#直接插入是不能用的,因为MAIN下面的某一行还需要你用一个你的图片文件做背景图
#使用前提:必须先有这么个鼠标脚本↓
# http://rpg.blue/web/htm/news8.htm
#调用方法:$scene = Scene_Mine.new(长,宽,雷数)
#使用后如果成功过关,2号全局变量值将变成2,以便嵌入游戏进行后续处理
##################################################################
class Scene_Mine
def initialize(wx = 12 ,mn = 12,minenumber = 10)
#此处有三个参数表示,长,宽,雷数
@WX = wx
@MN = mn
@minenumber = minenumber
@Board = []
@result = 0
for a in 0..@WX
@Board[a] = []
end
@Set = []
for a in 0..@WX
@Set[a] = []
end
@BoardShow = []
for a in 0..@WX
@BoardShow[a] = []
end
cleanborad()
setmine()
setnumber()
showgood()
#debugshowboard()
end
#########初始用函数########################
def cleanborad()
for a in 0..@MN #列
for b in 0..@WX #行
@Board[a] = 0
@Set[a] = 0
end
end
end
def setmine()
tt = 0
while tt < @minenumber
tmp1 = 1+rand(@MN-2)
tmp2 = 1+rand(@WX-2)
if @Board[tmp2][tmp1] != -1
@Board[tmp2][tmp1] = -1
tt += 1
end
end
end
def setnumber()
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
unless @Board[a] == -1
tmp = 0
if(@Board[b-1][a] == -1)
tmp += 1
end
if(@Board[a-1] == -1)
tmp += 1
end
if(@Board[b-1][a-1] == -1)
tmp += 1
end
if(@Board[b+1][a] == -1)
tmp += 1
end
if(@Board[a+1] == -1)
tmp += 1
end
if(@Board[b+1][a+1] == -1)
tmp += 1
end
if(@Board[b-1][a+1] == -1)
tmp += 1
end
if(@Board[b+1][a-1] == -1)
tmp += 1
end
@Board[a] = tmp
end
end
end
end
#这是个DEBUG用的东东......
def debugshowboard()
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
@BoardShow[a] = Sprite.new
if @Board[a]== -1
@BoardShow[a].bitmap = Small_Block.new(1,"雷").block
else
@BoardShow[a].bitmap = Small_Block.new(1,@Board[a].to_s).block
end
@BoardShow[a].x = b*20
@BoardShow[a].y = a*20
end
end
end
def showgood()
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
if @BoardShow[a]!= nil
@BoardShow[a].dispose
end
@BoardShow[a] = Sprite.new
if @Set[a] == 1
if @Board[a]== -1
@BoardShow[a].bitmap = Small_Block.new(1,"雷").block
else
@BoardShow[a].bitmap = Small_Block.new(0,@Board[a].to_s).block
end
end
if @Set[a] == 0
@BoardShow[a].bitmap = Small_Block.new(3," ").block
end
if @Set[a] == 2
@BoardShow[a].bitmap = Small_Block.new(1,"!").block
end
if @Set[a] == 3
@BoardShow[a].bitmap = Small_Block.new(6,"赢").block
end
@BoardShow[a].x = b*20
@BoardShow[a].y = a*20
end
end
end
def updatablock(b,a)
if a < 1 or a > @MN -2
return
end
if b < 1 or b > @WX- 2
return
end
if @BoardShow[a]!= nil
@BoardShow[a].dispose
end
@BoardShow[a] = Sprite.new
if @Set[a] == 1
if @Board[a]== -1
@BoardShow[a].bitmap = Small_Block.new(1,"雷").block
else
@BoardShow[a].bitmap = Small_Block.new(0,@Board[a].to_s).block
end
end
if @Set[a] == 0
@BoardShow[a].bitmap = Small_Block.new(3," ").block
end
if @Set[a] == 2
@BoardShow[a].bitmap = Small_Block.new(1,"!").block
end
if @Set[a] == 3
@BoardShow[a].bitmap = Small_Block.new(6,"赢").block
end
@BoardShow[a].x = b*20
@BoardShow[a].y = a*20
end
#########初始用函数########################
def main
@backgound = Sprite.new
@backgound.bitmap = RPG::Cache.picture("这里写你的背景图名称")
@backgound.z = -1
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果切换画面就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放窗口
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
@BoardShow[a].dispose
end
end
@backgound.dispose
end
def update
case @result
when 0
mouse_x, mouse_y = Mouse.get_mouse_pos
#左键
if Mouse.trigger?(Mouse::LEFT)
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
if mouse_y < (a+1)*20 and mouse_y >(a)*20 and mouse_x < (b+1)*20 and mouse_x > (b)*20
if @Set[a] != 2
$game_system.se_play($data_system.decision_se)
@Set[a] = 1
updatablock(b,a)
if @Board[a]== -1
gameover()
showgood()
return
end
if @Board[a]== 0
clickzero(b,a)
end
else
$game_system.se_play($data_system.cancel_se)
end
end
end
end
checkwin()
#showgood()
end
#以上左键
if Mouse.trigger?(Mouse::RIGHT)
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
if mouse_y < (a+1)*20 and mouse_y >(a)*20 and mouse_x < (b+1)*20 and mouse_x > (b)*20
if @Set[a] == 2
$game_system.se_play($data_system.decision_se)
@Set[a] = 0
updatablock(b,a)
#showgood()
return
end
if @Set[a] == 1
$game_system.se_play($data_system.cancel_se)
#showgood()
return
end
if @Set[a] == 0
@Set[a] = 2
$game_system.se_play($data_system.decision_se)
updatablock(b,a)
#showgood()
return
end
end
end
end
end
#以上右键
when 1 #负
@backgound.update
if Input.trigger?(Input::B) or Input.trigger?(Input::C)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 切换的地图画面
$game_variables[2] = @result
$scene = Scene_Map.new
return
end
when 2 #胜
if Input.trigger?(Input::B) or Input.trigger?(Input::C)
$game_system.se_play($data_system.cancel_se)
# 切换的地图画面
$game_variables[2] = @result
$scene = Scene_Map.new
return
end
end
end
def gameover()
@result = 1
Audio.se_play("Audio/SE/051-Explosion04.ogg")
@backgound.flash(Color.new(244,2,2), 80)
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
if @Board[a]== -1
@Set[a] = 1
end
end
end
end
def clickzero(x,y)
if x == 0 or y==0 or x >= @WX-1 or y >= @MN-1
return
end
for b in x-1..x+1
for a in y-1..y+1
@Set[a] = 1
updatablock(b,a)
end
end
end
def checkwin()
tmp = 0
max = (@MN-2) * (@WX-2)
for a in 1..@MN-2 #列
for b in 1..@WX-2 #行
if @Set[a] == 1
tmp +=1
end
end
end
if tmp == max - @minenumber
@result = 2
for b in 1..@MN-2 #列
for a in 1..@WX-2 #行
@Set[a] = 3
updatablock(b,a)
end
end
end
end
end
#############################################################
#下面这一段改自灼眼的夏娜的俄罗斯方块里的一个基础类
#主要是偶比较懒,直接拖来改了下用-_-0
#复用性应该很强的样子....
##############################################################
class Small_Block
attr_accessor :block
def initialize(color,text = "")
case color
when 0
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(240,200,64))
@block.fill_rect(20-1,0, 1, 20, Color.new(240,200,64))
@block.fill_rect(0, 0, 20, 1, Color.new(240,200,64))
@block.fill_rect(0,20-1, 20, 1, Color.new(240,200,64))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(250,161,7))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 1
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(231,81,81))
@block.fill_rect(20-1,0, 1, 20, Color.new(231,81,81))
@block.fill_rect(0, 0, 20, 1, Color.new(231,81,81))
@block.fill_rect(0,20-1, 20, 1, Color.new(231,81,81))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(211,35,35))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 2
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(209,28,242))
@block.fill_rect(20-1,0, 1, 20, Color.new(209,28,242))
@block.fill_rect(0, 0, 20, 1, Color.new(209,28,242))
@block.fill_rect(0,20-1, 20, 1, Color.new(209,28,242))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(189,28,242))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 3
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(202,241,44))
@block.fill_rect(20-1,0, 1, 20, Color.new(202,241,44))
@block.fill_rect(0, 0, 20, 1, Color.new(202,241,44))
@block.fill_rect(0,20-1, 20, 1, Color.new(202,241,44))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(163,203,5))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 4
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(81,201,231))
@block.fill_rect(20-1,0, 1, 20, Color.new(81,201,231))
@block.fill_rect(0, 0, 20, 1, Color.new(81,201,231))
@block.fill_rect(0,20-1, 20, 1, Color.new(81,201,231))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(81,180,231))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 5
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(73,188,46))
@block.fill_rect(20-1,0, 1, 20, Color.new(73,188,46))
@block.fill_rect(0, 0, 20, 1, Color.new(73,188,46))
@block.fill_rect(0,20-1, 20, 1, Color.new(73,188,46))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(33,156,4))
@block.draw_text( 0 , 0 , 20 , 20 , text )
when 6
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(84,121,241))
@block.fill_rect(20-1,0, 1, 20, Color.new(84,121,241))
@block.fill_rect(0, 0, 20, 1, Color.new(84,121,241))
@block.fill_rect(0,20-1, 20, 1, Color.new(84,121,241))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(44,91,241))
@block.draw_text( 0 , 0 , 20 , 20 , text )
end
end
def dispose
@block.dispose
end
end |
|