复习:我们学到哪里了 5 分钟
- 就算宝箱藏起来了,
(distance to [Treasure v])也能用。 <() < ()>和<() > ()>是在问一个问题。答案是 true 或 false。- 那一串 if / else 先问“小于 60 吗?”,再问“小于 150 吗?”。
快问快答
宝箱在 100 步远的地方。那一串会说哪个词?
看答案
Warm。“小于 60 吗?”的答案是不是,所以运行 else。然后“小于 150 吗?”的答案是是。
只有 Hot! 的问题回答“不是”,才会问 Warm 的问题。记住这一点。
今天的主题 3 分钟
<<> and <>>:两个问题都必须回答“是”- 范围:Warm 是“大于 60 并且小于 150”
<() = ()>:完全一样- 挖五次,每挖一次留下一个坑
- 第一种输掉游戏的方式
学习目标
上完这节课,你能够:
- 用 and 把两个问题连起来。
- 检查一个数字是不是在一个范围里面。
- 倒数到 0,并在 0 的时候结束游戏。
学一学:一个范围,一个限制 28 分钟
1 · Warm 只有在那一串里才对
上节课,Warm 是第二个问的。试试把它单独放在自己的 if / then 里:
if <(distance to [Treasure v]) < (150)> then
say [Warm]
end
Warm 不是“小于 150”。Warm 是大于 60,并且小于 150。这是两个问题,两个都必须回答“是”。
2 · and:两个都必须回答“是”
<<> and <>> 是一块绿色的 Operators(运算)积木。它有两个尖头的空格。
| 左边的问题 | 右边的问题 | and 的答案 |
|---|---|---|
| 是 | 是 | 是 |
| 是 | 不是 | 不是 |
| 不是 | 是 | 不是 |
| 不是 | 不是 | 不是 |
- 打开 Operators。拖出
<<> and <>>。 - 把
<() > (50)>放进左边的空格。输入 60。 - 把
<() < (50)>放进右边的空格。输入 150。 - 在两个空着的地方都放上
(distance to [Treasure v])。
<<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>>
3 · 三个 if,顺序随便
现在每个词都有自己完整的问题,不再需要那一串了。三块普通的 if / then 就够了。
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
end
怎么用: 点绿旗,然后把鼠标移向宝箱,再移开。看探测器说 Hot!、Warm 或 Cold。不用再按别的。
4 · 挖五次,正好是 0
新建一个叫 digs left 的变量。点绿旗时把它设成 5。每挖一次就减一。
游戏什么时候结束?当 digs left 正好是 0 的时候。这就是第三块比较积木,<() = ()>。
change [digs left v] by (-1)
if <(digs left) = (0)> then
broadcast [lost v]
end
5 · 每挖一次留下一个坑
挖过的地方应该留下记号。每个坑都是一个克隆体,就像以前的僵尸一样。
- 画一个叫
Hole的角色:一个深色的椭圆。 - 给它
when flag clicked和hide。原来的角色永远不会被看见。 - 加上
when I start as a clone、go to [Detector v]、show。 - 在 Detector 上,挖一次就运行
create clone of [Hole v]。
when flag clicked
set [digs left v] to (5)
forever
if <mouse down?> then
change [digs left v] by (-1)
create clone of [Hole v]
if <(digs left) = (0)> then
broadcast [lost v]
end
wait until <not <mouse down?>>
end
end
when flag clicked
hide
when I start as a clone
go to [Detector v]
show
怎么用: 点绿旗,然后在沙子上移动鼠标。在不同的地方按五次鼠标键。每按一次就挖一个坑,并用掉一次挖的机会。
6 · 赢,还是输
把它们合在一起。现在挖的时候先问一个问题:
- 是 Hot! 吗?那就
broadcast [found v],和上节课一样。 - 如果不是,就用掉一次挖的机会,留下一个坑。
次数变成 0 时,broadcast [lost v]。有两个角色在听:
when I receive [lost v]
stop [other scripts in sprite v]
say [Out of digs!]
when I receive [lost v]
show
基础任务:挖五次找到宝箱 24 分钟
打开你上节课的寻宝游戏。一次只改一样东西,每改完一样就玩一玩。
怎么用: 点绿旗,然后在沙子上移动鼠标。按下鼠标键来挖。你可以挖五次;在它说 Hot! 的时候挖,就能找到宝箱。
第 1 步:用三个 if 代替那一串
- 把整串 if / else 从 forever 循环里拖出来。
- 拼三块
if / then:Hot!、Warm、Cold。 - Warm 用
<<> and <>>的范围。 - 让宝箱显示出来,玩一玩。三个词都检查一下。
第 2 步:变量
- 新建一个变量
digs left,选适用于所有角色。勾上它,让它显示出来。
第 3 步:挖的脚本
- 在 Detector 上开始第二个脚本:
when flag clicked、set [digs left v] to (5)、forever。 - 里面:一个放了
<mouse down?>的if / then。 - 再里面:一个
if / else。Hot! 就broadcast [found v]。 - Else:
change [digs left v] by (-1)。 - 在
if / else后面加上wait until <not <mouse down?>>。 - 把第一个脚本里旧的按鼠标检查删掉。
第 4 步:坑
- 画好 Hole 角色,给它两组积木。
- 在 else 里加上
create clone of [Hole v]。 - 玩一玩。每次没挖到都会留下一个坑。
第 5 步:输掉游戏
- 在克隆积木后面加一个
if / then,问<(digs left) = (0)>。在里面放broadcast [lost v]。 - 给 Detector 和 Treasure 加上它们收到 lost 时的脚本。
- 故意输一次。五次没挖到,然后宝箱出现。
完整的 Detector
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
end
when flag clicked
set [digs left v] to (5)
forever
if <mouse down?> then
if <(distance to [Treasure v]) < (60)> then
broadcast [found v]
else
change [digs left v] by (-1)
create clone of [Hole v]
if <(digs left) = (0)> then
broadcast [lost v]
end
end
wait until <not <mouse down?>>
end
end
when I receive [found v]
stop [other scripts in sprite v]
say [You found it!]
when I receive [lost v]
stop [other scripts in sprite v]
say [Out of digs!]
when I receive [lost v] 和 show。点一次就把五次机会全用完了。
少了 wait until <not <mouse down?>>,或者它放在了 else 里面。它必须放在 if / else 后面,这样每次挖都会运行它。
就在宝箱旁边,它却说 Cold。
看看 Warm 的范围。两个符号里有一个方向反了。应该是“大于 60”和“小于 150”。
坑出现在舞台中间。
克隆体脚本里写的是 go to [random position v],或者少了 go to。在下拉菜单里选 Detector。
游戏一开始我就输了。
少了 set [digs left v] to (5),所以计数从 0 开始。
Very warm(很暖)
把 Warm 分成两个词。
- 60 到 100 步说 Very warm。
- 100 到 150 步说 Warm。
- Hot! 和 Cold 不变。
- 四个 if 不管什么顺序都还能用。
Teacher reveal — two ranges
if <(distance to [Treasure v]) < (60)> then
say [Hot!]
end
if <<(distance to [Treasure v]) > (60)> and <(distance to [Treasure v]) < (100)>> then
say [Very warm]
end
if <<(distance to [Treasure v]) > (100)> and <(distance to [Treasure v]) < (150)>> then
say [Warm]
end
if <(distance to [Treasure v]) > (150)> then
say [Cold]
end
The shuffle test is the point. A pupil who kept the old chain will find their words break when reordered. That is the lesson landing.
只落在沙子上
用新的方法藏宝箱:go to [random position v]。这块积木可能落在任何地方,连天上都可能。
- 宝箱必须总是落在沙子上。
- 沙地在 y = -150 和 y = -40 之间。
- 如果它落错了地方,就再试一次,直到落对为止。
怎么用: 点绿旗开始。不用再按别的,看宝箱一次又一次地落在沙子上。
Teacher reveal — a range on y
What your pupil builds, on the Treasure:
when flag clicked
hide
switch costume to [chest v]
go to [random position v]
repeat until <<(y position) > (-150)> and <(y position) < (-40)>>
go to [random position v]
end
What the embed above runs — the same search in a loop, so you can watch it land again and again:
when flag clicked
switch costume to [chest v]
forever
hide
go to [random position v]
repeat until <<(y position) > (-150)> and <(y position) < (-40)>>
go to [random position v]
end
show
wait (1) seconds
end
The same and as Warm, on a different number. A range is a range. Ask why the chest must hide while it searches: otherwise the misses flash across the sky.
你挖过的地方的地图
挖五次并不多。让每次没挖到都告诉你一点东西。
- 在 Warm 的地方挖的坑,有一圈橙色的边。
- 在 Cold 的地方挖的坑,有一圈蓝色的边。
- 这些边会留着,所以这些坑就变成了一张地图。
怎么用: 点绿旗,然后在沙子上移动鼠标。按下鼠标键来挖。每个坑都会是橙色或蓝色。挖五次要找到宝箱。
Teacher reveal — the hole asks for itself
when I start as a clone
go to [Detector v]
if <(distance to [Treasure v]) < (150)> then
switch costume to [warm v]
else
switch costume to [cold v]
end
show
The Hole gets two more costumes, warm and cold. The clone measures its own distance to the chest. Nobody has to tell it — which is the idea worth naming.
Only Warm and Cold are needed. A Hot! dig finds the chest, so it never makes a hole.
更近还是更远?
真正的寻宝人会比较。这一次挖的地方,比上一次更近吗?
- 每个新坑都会说 Warmer!(更近了!)或 Colder!(更远了!),说两秒。
- Warmer! 的意思是比上一个坑更近。
- 每局的第一个坑总是说 Warmer!。
怎么用: 点绿旗,然后在沙子上移动鼠标。按下鼠标键来挖。每个新坑都会说 Warmer! 或 Colder!。
Teacher reveal — last dig
when flag clicked
hide
set [last dig v] to (999)
when I start as a clone
go to [Detector v]
show
if <(distance to [Treasure v]) < (last dig)> then
set [last dig v] to (distance to [Treasure v])
say [Warmer!] for (2) seconds
else
set [last dig v] to (distance to [Treasure v])
say [Colder!] for (2) seconds
end
999 is bigger than any distance on the Stage. So the first dig is always closer. Why is the set before the say? A quick second dig would otherwise compare against the wrong number.
总结 5 分钟
- 只有两边都回答“是”,
<<> and <>>才是“是”。 - 范围就是用 and 连起来的两个比较:大于一个数字,又小于另一个数字。
- 问题完整的话,三个 if 不管什么顺序都能用。一串 if / else 不行。
<() = ()>问两样东西是不是完全一样。- 一个移到 Detector 那里的克隆体,能标出你挖过的地方。
- and
- 把两个问题连起来。两个都必须是 true。
- 范围
- 一个小数字和一个大数字之间的所有数。
- 等于
- 完全一样的数字,不多也不少。
- 输的条件
- 让游戏以失败结束的规则。在这里就是挖的次数用完了。
交作业
保存你的寻宝游戏。下节课,蛇来了,探测器也开始哔哔响。