修改:代码:http://pastebin.com/cGAxmNVC
如果你看管道部件,"如果pxcor = 14 [set num num + 1]"这是得分。但是,它有缺陷。当管道向鸟类移动时,补丁num属性设置为0.因为pxcor不再是14.但这意味着得分将始终为0.所以我需要得分方面的帮助。看看" Pipe"。
我想找到最大数量(num是补丁属性),并添加1.如何找到最大数量?
答案 0 :(得分:1)
鉴于严格的截止日期,我猜这是一个功课,所以我已经做了一些基本的帮助,让你去。我已将两段代码合并为一个文件。我做了一个语法修正,以便代码编译(添加`ask turtles'去)。
我没有尝试修复你的逻辑。您需要考虑在游戏开始之前发生的事情(例如绘制游戏领域)并在设置过程中进行(或调用)。你还需要考虑每次滴答过程中发生的事情(可能会移动鸟,更新分数等),并将其与“tick”命令一起放入(或调用)过程。
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