Project1
标题:
请问,脚本如何判定奖励
[打印本页]
作者:
guoyq1988
时间:
2014-3-14 12:58
标题:
请问,脚本如何判定奖励
请问,该脚本的胜负判定后,怎么判定胜利的变量?
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#==============================================================================
# 五子棋
#------------------------------------------------------------------------------
#使用$scene = Scene_Fir.new(true)呼出
#==============================================================================
class Scene_Fir
def initialize(first)
@s_value = 0 ; @value = 0
@full = 0
@first = first
end
def main
@fir_window = Window_Fir.new
Graphics.transition(40,"Graphics/Transitions/004-Blind04")
unless @first
m = (rand(15) + 1)
n = (rand(15) + 1)
@fir_window.world[m,n]=2
@fir_window.pawn_move(144 + 32*(m-1),32*(n-1),"white")
@full = 1
@fir_window.refresh
end
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@fir_window.cursor.dispose
@fir_window.dispose
end
def update
case @fir_window.states
when 1
position
when 2
position_c
when 3
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
end
end
def position
if Input.repeat?(Input::LEFT) or Input.repeat?(Input::RIGHT) or Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN) or Input.trigger?(Input::C)
if Input.trigger?(Input::C)
x = @fir_window.st_x ; y = @fir_window.st_y
if @fir_window.world[x,y] != 0
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.cursor_se)
@fir_window.pawn_move(144 + 32*(x-1),32*(y-1),"black")
@fir_window.world[x,y]=1
@full += 1
if win(x,y,"black")
@fir_window.win_states="black"
@fir_window.states = 3
@fir_window.refresh
return
end
if @full >= 255
@fir_window.states = 3
@fir_window.win_states="full"
@fir_window.refresh
return
end
@fir_window.refresh
@fir_window.states = 2
return
end
$game_system.se_play($data_system.cursor_se)
if Input.repeat?(Input::LEFT)
@fir_window.st_x == 1 ? @fir_window.st_x = 15 : @fir_window.st_x-=1
end
if Input.repeat?(Input::RIGHT)
@fir_window.st_x == 15 ? @fir_window.st_x = 1 : @fir_window.st_x+=1
end
if Input.repeat?(Input::UP)
@fir_window.st_y == 1 ? @fir_window.st_y = 15 : @fir_window.st_y-=1
end
if Input.repeat?(Input::DOWN)
@fir_window.st_y == 15 ? @fir_window.st_y = 1 : @fir_window.st_y+=1
end
@fir_window.refresh
return
end
end
def position_c
Graphics.update
#白方价值
@fir_window.white_p = [nil]
for i in 1..255
@fir_window.white_p.push(0)
end
for j in 1..15
for i in 1..15
if @fir_window.world[i,j] == 0
integral_calculus(i,j,1)
@fir_window.white_p[i+(j-1)*15] = @s_value
end
end
end
max = @fir_window.white_p.max
index = @fir_window.white_p.index(max)
x1 = index%15 ; y1 = index/15+1
if x1==0
x1 = 15
y1 = y1-1
end
@fir_window.world[x1,y1]=2
Graphics.update
#黑方价值
@fir_window.black_p = [nil]
for i in 1..255
@fir_window.black_p.push(0)
end
for j in 1..15
for i in 1..15
if @fir_window.world[i,j] == 0
integral_calculus(i,j,2)
@fir_window.black_p[i+(j-1)*15] = @s_value
end
end
end
may = @fir_window.black_p.max
if may>=max and max<100001
indey = @fir_window.black_p.index(may)
x2 = indey%15 ; y2 = indey/15+1
if x2 == 0
x2 = 15
y2 = y2-1
end
@fir_window.world[x1,y1]=0
@fir_window.world[x2,y2]=2
@fir_window.pawn_move(144 + 32*(x2-1),32*(y2-1),"white")
@full += 1
if win(x2,y2,"white")
@fir_window.win_states="white"
@fir_window.states = 3
@fir_window.refresh
return
end
else
@fir_window.pawn_move(144 + 32*(x1-1),32*(y1-1),"white")
@full += 1
if win(x1,y1,"white")
@fir_window.win_states="white"
@fir_window.states = 3
@fir_window.refresh
return
end
end
if @full >= 255
@fir_window.states = 3
@fir_window.win_states="full"
@fir_window.refresh
return
end
@fir_window.refresh
@fir_window.states = 1
return
end
def win(x,y,str) #胜负判定
word = @fir_window.world
a=x ; sum = 1
str=="black" ? win=1 : win=2
loop do #水平左
a-=1
if (word[a,y] != win) or (a<1)
break
else
sum+=1
return true if sum>=5
end
end
a=x
loop do #水平右
a+=1
if (word[a,y] != win) or (a>15)
break
else
sum+=1
return true if sum>=5
end
end
a=y ; sum = 1
loop do #垂直上
a-=1
if (word[x,a] != win) or (a<1)
break
else
sum+=1
return true if sum>=5
end
end
a=y
loop do #垂直下
a+=1
if (word[x,a] != win) or (a>15)
break
else
sum+=1
return true if sum>=5
end
end
a = x ; b = y ; sum = 1
loop do #左上
a-=1 ; b-=1
if (word[a,b] != win) or (a<1) or (b<0)
break
else
sum+=1
return true if sum>=5
end
end
a = x ; b = y ;
loop do #右下
a+=1 ; b+=1
if (word[a,b] != win) or (a>15) or (b>15)
break
else
sum+=1
return true if sum>=5
end
end
a = x ; b = y ; sum = 1
loop do #右上
a+=1 ; b-=1
if (word[a,b] != win) or (a>15) or (b<1)
break
else
sum+=1
return true if sum>=5
end
end
a = x ; b = y ;
loop do #左下
a-=1 ; b+=1
if (word[a,b] != win) or (a<1) or (b>15)
break
else
sum+=1
return true if sum>=5
end
end
return false
end
=begin
胜:100000
活四:10000
活三:2000
活二:500
冲四:5000
冲三:1000
冲二:100
=end
def chess_model(sum,die) #棋型
@value = 0
if sum >= 5
@value = 100000
return
end
if die == 0
case sum
when 4
@value = 10000
return
when 3
@value = 2000
return
when 2
@value = 500
return
end
elsif die == 1
case sum
when 4
@value = 5000
return
when 3
@value = 1000
return
when 2
@value = 100
return
else
@value = 1
return
end
else
@value = 0
return
end
end
def integral_calculus(x,y,w_b)
word = @fir_window.world
@s_value = 0
die = 0
a=x ; sum = 1
for i in 1..5 #水平左
a=x-i
if (word[a,y] == 0)
break
elsif (word[a,y] == w_b) or (a<1)
die += 1
break
else
sum += 1
end
end
for i in 1..5 #水平右
a=x+i
if (word[a,y] == 0)
break
elsif (word[a,y] == w_b) or (a>15)
die += 1
break
else
sum += 1
end
end
chess_model(sum,die) #水平核分
@s_value += @value
sum = 1 ; die = 0
for i in 1..5 #垂直上
b=y-i
if (word[x,b] == 0)
break
elsif (word[x,b] == w_b) or (b<1)
die += 1
break
else
sum += 1
end
end
for i in 1..5 #垂直下
b=y+i
if (word[x,b] == 0)
break
elsif (word[x,b] == w_b) or (b>15)
die += 1
break
else
sum += 1
end
end
chess_model(sum,die) #垂直核分
@s_value += @value
sum = 1 ; die = 0
for i in 1..5 #左上
a=x-i ; b=y-i
if (word[a,b] == 0)
break
elsif (word[a,b] == w_b) or (a<1) or (b<1)
die += 1
break
else
sum += 1
end
end
for i in 1..5 #右下
a=x+i ; b=y+i
if (word[a,b] == 0)
break
elsif (word[a,b] == w_b) or (a>15) or (b>15)
die += 1
break
else
sum += 1
end
end
chess_model(sum,die) #左斜核分
@s_value += @value
sum = 1 ; die = 0
for i in 1..5 #右上
a=x+i ; b=y-i
if (word[a,b] == 0)
break
elsif (word[a,b] == w_b) or (a>15) or (b<1)
die += 1
break
else
sum += 1
end
end
for i in 1..5 #左下
a=x-i ; b=y+i
if (word[a,b] == 0)
break
elsif (word[a,b] == w_b) or (a<1) or (b>15)
die += 1
break
else
sum += 1
end
end
chess_model(sum,die) #右斜核分
@s_value += @value
return
end
end
class Window_Fir < Window_Base
attr_accessor :states # 状态
attr_accessor :st_x # X
attr_accessor :st_y # Y
attr_accessor :world # 棋盘
attr_accessor :white_p # 白棋盘
attr_accessor :black_p # 黑棋盘
attr_accessor :win_states # 胜利状态
attr_accessor :cursor # 光标
def initialize
super(-16, -16, 672, 512)
self.contents = Bitmap.new(width - 32, height - 32)
# $game_system.bgm_play($data_system.equip_se)
@fir_home=Bitmap.new('Graphics/Pictures/五子棋/world')
self.contents.blt(0,0,@fir_home,@fir_home.rect)
@cursor=Bitmap.new('Graphics/Pictures/五子棋/world')
@cursor = Sprite.new
@cursor.bitmap = RPG::Cache.picture('五子棋/cursor')
@cursor.z = self.z+10
@black=Bitmap.new('Graphics/Pictures/五子棋/black')
@white=Bitmap.new('Graphics/Pictures/五子棋/white')
@win_states=""
######################变量###########################
@states = 1 #执行状态
@st_x = 8 ; @st_y = 8 #位置
[url=home.php?mod=space&uid=37789]@world[/url] = Table.new(16, 16) #棋盘
for i in 1..15
for j in 1..15
@world[i,j]=0
end
end
@white_p = [nil] #白棋表
for i in 1..255
@white_p.push(0)
end
@black_p = [nil] #黑棋表
for i in 1..255
@black_p.push(0)
end
######################变量###########################
position(@st_x,@st_y)
end
def refresh
case @states
when 1
position(@st_x,@st_y)
when 2
position(@st_x,@st_y)
when 3
win_states(@win_states)
end
end
def position(x,y)
@cursor.x = 144 + 32*(x-1)
@cursor.y = 32*(y-1)
end
def pawn_move(x,y,str)
if str == "black"
self.contents.blt(x,y,@black,@black.rect)
elsif str == "white"
self.contents.blt(x,y,@white,@white.rect)
end
end
def win_states(states)
self.contents.font.size = 50
self.contents.font.name = Font.default_name
case states
when "black"
self.contents.draw_text(50, 30, 320, 240, "你赢了")
$game_system.se_play($data_system.equip_se)
$game_system.se_play($data_system.equip_se)
$game_switches[101] = true
for i in 1..5
Graphics.update
end
when "white"
self.contents.draw_text(50, 30, 320, 240, "你输了")
$game_system.se_play($data_system.equip_se)
for i in 1..5
Graphics.update
end
when "full"
self.contents.draw_text(50, 30, 320, 240, "和局")
$game_system.se_play($data_system.equip_se)
$game_switches[102] = true
for i in 1..5
Graphics.update
end
end
end
end
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
复制代码
作者:
guoyq1988
时间:
2014-3-15 12:50
@天地有正气
@恋′挂机
@芯☆淡茹水
@紫英晓狼1130
作者:
天地有正气
时间:
2014-3-15 13:43
有一个很经典的游戏叫梦大陆物语,里面用到了,可以参考一下?
作者:
弗雷德
时间:
2014-3-15 14:04
497行有一句写到$game_switches[101] = true
表示当胜利的时候会打开101号开关,LZ可以做个公共事件自动运行,当101号开关打开时,就运行事件,给个奖励。
另外这个电脑五子棋的算法太简单,很容易就会被玩家找到规律 100%稳胜刷奖励。
作者:
guoyq1988
时间:
2014-3-15 19:11
弗雷德 发表于 2014-3-15 14:04
497行有一句写到$game_switches[101] = true
表示当胜利的时候会打开101号开关,LZ可以做个公共事件自动运 ...
谢谢熊淑的指点,脚本盲很无奈。。。。
{:7_292:}
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1