编辑:代码: http: //pastebin.com/cGAxmNVC
如果您查看管道部分,“如果 pxcor = 14 [set num num + 1]”这就是评分。然而,它是有缺陷的。当管道向鸟移动时,patch num 属性设置为 0。因为 pxcor 不再是 14。但这意味着分数将始终为 0。所以我需要评分方面的帮助。看“管”。
我正在考虑找到最大 num(num 是补丁属性),然后加 1。我怎样才能找到最大 num?
编辑:代码: http: //pastebin.com/cGAxmNVC
如果您查看管道部分,“如果 pxcor = 14 [set num num + 1]”这就是评分。然而,它是有缺陷的。当管道向鸟移动时,patch num 属性设置为 0。因为 pxcor 不再是 14。但这意味着分数将始终为 0。所以我需要评分方面的帮助。看“管”。
我正在考虑找到最大 num(num 是补丁属性),然后加 1。我怎样才能找到最大 num?
鉴于严格的截止日期,我猜这是一些家庭作业,所以我做了一些基本的帮助来帮助你前进。我已将两段代码合并到一个文件中。我进行了一次语法更正,以便代码能够编译(添加“问海龟”)。
我没有尝试修复您的逻辑。您需要考虑在比赛开始之前会发生什么(例如绘制比赛场地)并将其包含在(或由其调用)设置过程中。您还需要考虑在每个滴答声中发生了什么(可能移动小鸟,更新分数等)并将其与“滴答声”命令一起放入(或由其调用) go 过程。
globals [jump? score]
patches-own [num oldcolor]
to setup
clear-all
create-ordered-turtles 1 ; not sure why ordered since only 1 of them
ask turtles [ ; don't need separate ask, create runs anything in [ ]
setxy -10 0
set size 5
set shape "bird-norm"
]
ask patches [
set num 0
if pycor = -16 [set pcolor green]
]
end
to go ; this should have the tick or it will only run once
ask turtles [
set shape "bird-fall"
set heading 180
fd 1
wait 0.1
if mouse-down? and not jump? [flap]
set jump? mouse-down?
if (pycor = -14) or (pcolor = white) [
ask patch 0 0 [
set plabel "Game Over"
]
stop
]
]
end
to move ; this has the tick command
reset-ticks
wait 0.1
ask patches [
set oldcolor pcolor
]
ask patches with [pxcor < max-pxcor] [
set pcolor [oldcolor] of patch (pxcor + 1) pycor
]
tick
end
to line
reset-ticks
let x (random 20 - 6)
ask patches [
if ((pxcor > 10) and (pxcor < 15)) and ((pycor > -16) and ((pycor < x) and (pycor > (x - 5)))) [
set pcolor white
]
if pxcor = 14 [
set num num + 1
]
]
end
to pipe
repeat 10 [move]
line
end
to flap
set heading 0
set shape "bird-norm"
repeat 5 [
fd 1
wait 0.01]
end