复习:我们学到哪里了 5 分钟
reset timer让时钟开始。(round ((60) - (timer)))显示还剩多少时间。repeat until <<(timer) > (60)> or <(lives) = (0)>>让这一轮自己结束。- 时钟有自己的脚本。所以你输入的时候,它也在走。
快问快答
现在每答对一题得 1 分。连续答对十题就是 10 分。这对一题都没答错的人公平吗?
看答案
很多游戏都说不公平。它们会给连对更多的分。连对就是一题接一题地答对。这就是今天的第一个想法。
今天的主题 3 分钟
- 一个
streak(连对)变量,还有change [score v] by (streak) - 先选好难度,存在
min和max里 - 用
<(pick random (1) to (2)) = [1]>抛硬币,选 × 还是 + broadcast [new question v] and wait:由一个脚本来出题
学习目标
上完这节课,你能够:
- 记录一个会变大的连对数,答错时变回 0。
- 先问难度,再在每道题里用它。
- 把两种题混在一起。正确答案只放在一个地方。
学一学:连对、难度、混合 28 分钟
1 · 连对
连对数的是一题接一题答对了几次。答错一题,它就回到 0。
现在每答对一题,得的分就等于连对数。看分数怎么变多:
| 答案 | streak | 加分 | score |
|---|---|---|---|
| 对 | 1 | +1 | 1 |
| 对 | 2 | +2 | 3 |
| 对 | 3 | +3 | 6 |
| 错 | 0 | +0 | 6 |
| 对 | 1 | +1 | 7 |
用积木来写,就是四行。它们放进你已经有的 if / else 里:
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by (streak)
else
set [streak v] to (0)
change [lives v] by (-1)
end
(streak) 放进 change 积木的圆形空格里。得分会加上连对的数。用一个练习机器人来演示最清楚。它会自己答题。大约四次里有三次答对:
when flag clicked
set [score v] to (0)
set [streak v] to (0)
repeat (12)
if <(pick random (1) to (4)) > (1)> then
say [Right!] for (1) seconds
change [streak v] by (1)
change [score v] by (streak)
else
say [Wrong!] for (1) seconds
set [streak v] to (0)
end
end
怎么用: 点绿旗开始。不用再按别的,看它运行完,然后点 ↺ Reset 再运行一次。
三种变量
| 变量 | 什么时候设回开始的值…… |
|---|---|
score、lives | 每一轮开始时设一次 |
streak | 每一轮开始时,“还有”每次答错时 |
a、b | 每道题都设 |
2 · 先选难度
六岁的孩子和十二岁的孩子不应该做一样的题。所以先问一下。把答案存成两个数:允许的最小数和最大数。
- 新建两个变量:
min和max。 - 在绿旗脚本的最上面,加上
ask [Easy or hard?] and wait。 - 加一个 if / else,里面放
<(answer) = [hard]>。 - hard 把 min 设成 2,max 设成 12。easy 设成 1 和 5。
- 在 a 和 b 的两块 set 积木里,把
(min)和(max)放进 pick random。
when flag clicked
ask [Easy or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
set [min v] to (1)
set [max v] to (5)
end
repeat (3)
set [a v] to (pick random (min) to (max))
set [b v] to (pick random (min) to (max))
say (join (a) (join [ × ] (b))) for (2) seconds
end
怎么用: 点绿旗,然后在框里输入 easy 或 hard,按 Enter。
3 · × 和 + 混在一起
让程序抛硬币。(pick random (1) to (2)) 会给出 1 或 2,就像硬币的正面或反面。1 表示乘法题,2 表示加法题。
聪明的地方在这里:在出题的同一个地方,把正确答案也算好。把它存在一个叫 correct 的变量里。
when I receive [new question v]
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
if <(pick random (1) to (2)) = [1]> then
set [question v] to (join (a) (join [ × ] (b)))
set [correct v] to ((a) * (b))
else
set [question v] to (join (a) (join [ + ] (b)))
set [correct v] to ((a) + (b))
end
现在这一轮只需要一个检查,不管是什么符号都能用:
broadcast [new question v] and wait
ask (question) and wait
if <(answer) = (correct)> then
end
broadcast [new question v] and wait 会一直等到题目准备好。普通的广播会在题目还没出好时就提问。
when flag clicked
repeat (6)
broadcast [new question v] and wait
say (join (question) (join [ = ] (correct))) for (2) seconds
end
怎么用: 点绿旗开始。不用再按别的,看它运行完,然后点 ↺ Reset 再运行一次。
基础任务:把连对、难度和混合题加进你的游戏 25 分钟
打开你的六十秒游戏。做完以后,巫师身上会有四个脚本。
第 1 步:五个新变量
- 新建
streak、min、max、question和correct。 - streak 保持勾选。其他的都取消勾选。
第 2 步:出题器
- 照着“学一学”第 3 部分,搭好
when I receive [new question v]脚本。 - 在两块 pick random 积木里都用
(min)和(max)。
第 3 步:把绿旗脚本分开
- 把绿旗脚本里从
reset timer开始往下的所有积木拉下来。 - 在它上面放
when I receive [play v]。 - 现在绿旗脚本负责问难度。它设好 score、streak 和 lives,然后广播
play。
第 4 步:新的一轮
- 在循环里面,把两块 set 积木换成
broadcast [new question v] and wait。 - 问
(question)。用(correct)来检查。 - 在 if / else 的两半都加上连对的积木。
第 5 步:用三种方式玩
- 用 easy 玩。连续答对五题。看 score 往上跳。
- 用 hard 玩。检查没有数小于 2 或大于 12。
- 故意答错一题。检查 streak 变回 0。
when flag clicked
ask [Easy or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
set [min v] to (1)
set [max v] to (5)
end
set [score v] to (0)
set [streak v] to (0)
set [lives v] to (3)
broadcast [play v]
when I receive [play v]
reset timer
broadcast [clock v]
repeat until <<(timer) > (60)> or <(lives) = (0)>>
broadcast [new question v] and wait
ask (question) and wait
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by (streak)
else
set [streak v] to (0)
change [lives v] by (-1)
say (join [It is ] (correct)) for (1) seconds
end
end
say (join [Round over! Score: ] (score)) for (4) seconds
出题器就是“学一学”第 3 部分里的那个。它的 pick random 积木里放的是 (min) 和 (max)。时钟和上节课一样。
怎么用: 点绿旗,输入 easy 或 hard,按 Enter。然后每道题都在框里输入你的答案,按 Enter。
选了 hard,数字还是很小。
你的 pick random 积木里还是 1 和 10。把 (min) 和 (max) 放进去。
巫师问了一道空白的题。
你用的是 broadcast [new question v],没有 “and wait”。所以题目还没出好,这一轮就先提问了。
streak 从来不回到 0。
else 那一半需要 set [streak v] to (0)。
每答对一题都只值 1 分。
检查 change 积木里放的是 (streak),不是 1。然后检查连对数是不是在得分之前变大。
为连对欢呼
连对开始的时候,让巫师欢呼。
- 连对 3 题时,他说“3 in a row!”(连对 3 题!)。
- 连对 5 题时,他说“5 in a row! On fire!”(连对 5 题!太厉害了!)。
- 其他答对的题不欢呼。
Teacher reveal
change [streak v] by (1)
change [score v] by (streak)
if <(streak) = (3)> then
say [3 in a row!] for (1) seconds
end
if <(streak) = (5)> then
say [5 in a row! On fire!] for (1) seconds
end
Both ifs go in the top half, after the streak has grown.
中等难度
在 easy 和 hard 中间加一个难度。
- 问题变成“Easy, medium or hard?”(简单、中等还是困难?)。
- medium 用 2 到 9 的数。
- easy 和 hard 还是和以前一样。
Teacher reveal — an if inside the else
ask [Easy, medium or hard?] and wait
if <(answer) = [hard]> then
set [min v] to (2)
set [max v] to (12)
else
if <(answer) = [medium]> then
set [min v] to (2)
set [max v] to (9)
else
set [min v] to (1)
set [max v] to (5)
end
end
Easy stays in the last else, so anything unexpected still lands somewhere safe.
减法,永远不小于零
加上第三种题:减法。答案永远不能小于零。
- 大约每三道题里有一道是减法。
- 大的数总是放在前面。
- 检查还是用 correct。所以这一轮不用改。
怎么用: 点绿旗开始。不用再按别的,看它运行完,然后点 ↺ Reset 再运行一次。
Teacher reveal — build it backwards
Pick the answer and the small number first. Add them to make the big number. Then ask big − small, and the answer is always the one you picked.
when flag clicked
repeat (6)
set [a v] to (pick random (1) to (10))
set [b v] to (pick random (1) to (10))
set [big v] to ((a) + (b))
say (join (big) (join [ - ] (join (b) (join [ = ] (a))))) for (2) seconds
end
That is the demo. In the question maker it becomes:
set [big v] to ((a) + (b))
set [question v] to (join (big) (join [ - ] (b)))
set [correct v] to (a)
The coin becomes (pick random (1) to (3)), with an if inside the else for the third kind. Some pupils swap a and b with an if instead. That works too, and needs a spare variable — let them find out why.
hard 难度分数翻倍
在 hard 难度下连对,应该比在 easy 下更值钱。
- 在 hard 下,每答对一题,得分是连对数乘以 2。
- 在 easy 下,得分就是连对数,和现在一样。
- 一轮结束时,还要说出你最长的连对。
Teacher reveal
if <(answer) = (correct)> then
change [streak v] by (1)
change [score v] by ((streak) * (bonus))
if <(streak) > (best streak)> then
set [best streak v] to (streak)
end
else
set [streak v] to (0)
change [lives v] by (-1)
end
bonus is set beside min and max: 2 for hard, 1 for easy. best streak is set to 0 at the start of each round. It is a round best, not an all-time best — that is next lesson.
总结 4 分钟
今天这一轮做的事更多了,但它并没有变长。
- 答对时,
streak变大。答错时,它变回 0。 change [score v] by (streak)让连对很久的人得到更多分。- 你先选难度。它为每道题设好
min和max。 - 出题器同时做好题目和
correct。所以这一轮只要一个检查。
- 连对(streak)
- 从上次答错以后,一题接一题答对了几题。
- 难度(level)
- 游戏有多难。在这里,就是数字有多大。
- 抛硬币
- 在 1 和 2 之间 pick random。两个数的机会一样大。
- and wait(并等待)
- 让广播一直等,直到它启动的所有脚本都运行完。
下一课:乘法表挑战的最后一课。有按钮的菜单、一个永远不会被清掉的最高分,还有一张用文字写的成绩卡。