复习 — 我们学到哪里了 5 分钟
你有了一个两人比赛,有石头,还有倒数。今天你用的都是已经认识的积木。这是你到现在为止最大的作品。
- 问答秀里的广播链:一个脚本做完,就叫下一个脚本。
- 两节课以前的
race on开关。 - 奖牌卡里的 else 里面套 if。
快问快答
你赢了你的朋友一次。他说那是运气。怎样才能知道谁更厉害?你的作品要改什么?
看答案
多比几场。所以作品要知道三件新的事:已经比了几场?每场是谁赢?什么时候应该停?
今天的主题 3 分钟
- 一个
round计数器,还有一个知道整场什么时候结束的裁判。 - 两个赢的次数计数器,每个玩家一个。
- 三种结局:蓝色赢、红色赢和平局。
- 用广播代替
stop [all v],这样游戏能继续下去。
学习目标
这节课结束时,你能够:
- 一轮接一轮,比完规定的轮数。
- 同时给两个玩家记分。
- 说出谁是冠军,或者说是平局。
学一学 — 几轮比赛、得分、冠军 28 分钟
1 · 赢的人不再把一切都停掉
问题就是 stop [all v]。用了它以后,什么都不在运行了。所以没有东西能开始第二场比赛。改用一个消息。
when I receive [new round v]
go to x: (-200) y: (70)
wait until <touching [Finish v]?>
change [blue wins v] by (1)
say [Blue takes it!] for (2) seconds
broadcast [round over v]
裁判收到 round over,就决定接下来做什么。它用一个 if / else。这个脚本管着整场比赛。
when I receive [round over v]
set [race on v] to (0)
wait (3) seconds
if <(round) > (2)> then
broadcast [match over v]
else
broadcast [new round v]
end
3 > 2 是“是”。2 · 两个得分
两个玩家需要两个计数器。重要的是你在哪里设定它们。这和问答秀的最高分是同一个规则。
| 在绿旗时设定 | 在每一轮开始时设定 |
|---|---|
blue wins | race on |
red wins | 两个火箭的位置 |
round | — |
如果你把赢的次数计数器放在右边那一列,会怎样?每一轮都会把它设回 0。整场比分永远是 1–0,最后一轮谁赢就是谁领先。
when I receive [new round v]
set [race on v] to (0)
change [round v] by (1)
say [3] for (1) seconds
say [2] for (1) seconds
say [1] for (1) seconds
set [race on v] to (1)
say [GO!] for (1) seconds
怎么用: 点绿旗开始。不用按别的东西,看完就好。想再看一次,就点 ↺ Reset。
3 · 三种结局
蓝色可能赢,红色也可能赢。有时候比分一样。轮数是双数,或者有一轮没有人跑完,就可能这样。每场比赛都需要这三种结局。
when I receive [match over v]
start sound [Triumph v]
if <(blue wins) > (red wins)> then
say [Blue is the champion!] for (4) seconds
else
if <(red wins) > (blue wins)> then
say [Red is the champion!] for (4) seconds
else
say [A draw! Race again.] for (4) seconds
end
end
怎么用: 点绿旗开始。不用按别的东西,看完就好。想再看一次,就点 ↺ Reset。
怎么用: 点绿旗,在舞台上点一下,然后一只手按 D,另一只手按 → 来比赛。三场比赛决定整场的输赢。
基础任务 — 把你的比赛变成一整场对决 25 分钟
你需要的积木,你几乎都已经有了。你要改的是每个脚本用哪块帽子积木开始。
第 1 步 — 三个变量
- 做
blue wins、red wins和round。 - 让三个都显示出来。
- 在裁判的绿旗积木里,把三个都设成 0。
- 在那组积木的最后放
broadcast [new round v]。
第 2 步 — 移动倒数
- 把裁判倒数的帽子积木从
when flag clicked换成when I receive [new round v]。 - 在它上面靠近顶部的地方加
change [round v] by (1)。 - 按绿旗。应该运行一次倒数。
第 3 步 — 赢的脚本来报告
- 把每个火箭赢的脚本的帽子积木换成
when I receive [new round v]。 - 把
go to x: (-200) y: (70)积木放在它的最上面。 - 把
stop [all v]换成broadcast [round over v]。 - 在发消息之前加上
change [blue wins v] by (1)。
第 4 步 — 裁判来决定
- 在裁判上做 round over 的脚本。
- 试一试。应该一个接一个运行三次倒数。
- 检查 round 计数器到 3 就停。
第 5 步 — 冠军
- 做 match over 的脚本。把 if 放在 else 里面。
- 玩一整场比赛。两个火箭都自己开。
- 再玩一整场。检查所有东西都从 0 重新开始。
倒数一直停不下来。
round 计数器没有增加,所以 round > 2 永远不是“是”。change 积木要放在 new round 的脚本里,不是 round over 的脚本里。
第 2 轮一开始就有人赢了。
有一个火箭没有回到起跑线。所以它还碰着终点线。go to x: (-200) y: (70) 要放在赢的脚本的第一块。
比分总是 1-0。
new round 的脚本把赢的次数计数器设成了 0。它们应该放在绿旗那里。
同一轮里两个玩家都得分了。
有人赢的时候,比赛没有关掉。输的人在等三秒的时候碰到了终点线。
一边飞一边能看的记分板
玩家正在比赛。他们不应该要眯着眼睛看角落,才看得到比分。
- 比赛进行中也能看到比分,不只是在两轮之间。
- 屏幕上有现在是第几轮。
- 没有东西挡住跑道或火箭。
五局三胜,提前结束
改成五局三胜。只要有一个玩家赢了三场,就马上停。改变不了结果的比赛,就不要再比。
- 最多五轮。
- 一个玩家赢了三场,整场比赛就马上结束。
- 3–0 的比赛只比三场,不是五场。
- 3–2 的比赛五场都要比。
Teacher note — three questions, not one
The round-over script now asks three things: has blue won three, has red won three, or have we run out of rounds? Any of them ends the match. The tidy way is three ifs before the else, and the interesting mistake is checking the round count FIRST, which plays race four before noticing the match was already over.
交给两个不认识的人玩
这是第 1 级的最后一个挑战。两个从来没看过你游戏的人,玩一整场比赛。你一句话都不说。
- 他们自己弄明白哪个火箭是自己的。
- 他们自己弄明白哪些键是自己的。
- 他们比完三场,没有问你任何问题。
- 他们知道谁赢了。
Teacher note — the keys have to be on the screen
This is the one thing almost every project fails on, and it is invisible to the author because they know their own keys. A line on the title screen, or a label under each rocket, is all it takes. It is the same lesson as the Quiz Show’s stranger test and the Pet Pal’s: whatever you wanted to say out loud belonged on the screen.
给赢的人加一点难度
一个快的玩家和一个慢的玩家比,第一轮以后整场就没悬念了。让每一轮赢的人,下一轮从稍微后面一点的地方出发。
怎么用: 点绿旗开始。不用按别的东西,看完就好。想再看一次,就点 ↺ Reset。
- 如果你赢了一轮,下一轮你的起跑线会往后移。
- 输了就不会。
- 谁都不会从舞台左边外面出发。
- 新的一整场比赛开始时,加的难度回到 0。
Teacher notes — a start position that is a variable
when I receive [new round v]
go to x: (blue start) y: (70)
wait until <touching [Finish v]?>
change [blue wins v] by (1)
change [blue start v] by (-15)
broadcast [round over v]
The move worth naming: go to x: (blue start) y: (70) has a variable where every other one in the course has had a number. The rocket’s starting place is now something the game decides.
Keeping it on the Stage needs a floor. The honest Level 1 answer is a guard, added straight after the change block:
if <(blue start) < (-215)> then
set [blue start v] to (-215)
end
A pupil who asks whether there is a neater way has found the reason other languages have a block for “whichever of these two is bigger”. Scratch does not, so the guard is the answer here.
Going further: Level 2 opens with clones that each carry their own numbers, and a whack-a-mole game built on the mouse rather than the keyboard.
总结 5 分钟
三十六节课以前,小猫走了十步。今天,两个人玩一场三轮的比赛。
stop [all v]结束整个作品。广播结束的是一轮。- 裁判管着计数器。它决定整场比赛什么时候结束。
- 整场的得分在绿旗时设定。每一轮的东西在每一轮开始时设定。
- 三种结局,按顺序检查。其中一种是平局。
这六个单元学了什么
- 移动、转身、滑行,还有舞台上的 x 和 y。
- 造型、背景、说话、声音,还有同时做两件事。
- 事件、循环、if、if / else,还有 Sensing(侦测)能问的问题。
- 变量:当作得分、倒数、心情和开关。
- 克隆体、广播,还有一个有开始画面和结局的游戏。
- 一轮
- 一场比赛。一整场对决由好几轮组成。
- 一整场对决
- 一组比赛。最后才决定谁赢。
- 平局
- 没有人赢。就算看起来永远不会发生,它也要有自己的结局。
- 裁判
- 管着规则的角色。没有人玩它。
下一课:一个新游戏。一个键,跳一下,而且你永远不能停下来。