Year 7 Edexcel Computing: Case Study Practical Exercise – Catch the Fruit Game | 英国七年级爱德思计算机:案例分析实战演练——接水果游戏

📚 Year 7 Edexcel Computing: Case Study Practical Exercise – Catch the Fruit Game | 英国七年级爱德思计算机:案例分析实战演练——接水果游戏

In this article, we will walk through a complete case study where we design and build a simple ‘Catch the Fruit’ game using computational thinking and Scratch. This practical exercise helps Year 7 students understand the full development process, from problem analysis and decomposition to algorithm design, coding, testing, and evaluation.

在本文中,我们将完成一个完整的案例研究,运用计算思维和 Scratch 来设计和制作一个简单的 ‘接水果’ 游戏。这个实战练习帮助七年级学生理解从问题分析、分解、算法设计到编码、测试和评估的整个开发过程。

1. Introduction to the Case Study | 案例介绍

A case study is a detailed investigation of a real-world scenario that allows students to apply their computing knowledge in a practical way. In this activity, you will act as a junior programmer tasked with creating an interactive game. The game has a bowl at the bottom of the screen and fruits that fall from the top. The player must move the bowl to catch the fruits and earn points. This project covers the key pillars of computational thinking: decomposition, pattern recognition, abstraction, and algorithm design.

案例研究是对一个真实场景的详细探究,让学生以实践的方式应用计算机知识。在这个活动中,你将扮演一名初级程序员,负责制作一个互动游戏。游戏在屏幕底部有一个碗,水果从顶部掉落。玩家必须移动碗接住水果来得分。这个项目涵盖了计算思维的关键支柱:分解、模式识别、抽象和算法设计。

2. Understanding the Problem | 理解问题

Before writing any code, it is essential to clearly define what the game should do. The requirements for the ‘Catch the Fruit’ game are: a bowl sprite can be moved left and right using the arrow keys; fruits of various types (apple, orange, banana) spawn at random x-positions at the top and fall downwards; when a fruit touches the bowl, the score increases by 1; if a fruit reaches the bottom without being caught, the player loses a life; the game ends when all lives are lost. The goal is to create a fun and functional game that keeps a running score and gives visual feedback.

在编写任何代码之前,必须清楚地定义游戏应该做什么。’接水果’ 游戏的需求是:一个碗角色可以通过方向键左右移动;不同类型的水果(苹果、橙子、香蕉)在屏幕顶部随机 x 坐标生成,并向下掉落;当水果碰到碗时,分数加 1;如果水果到达底部而没有被接住,玩家失去一条命;当所有生命耗尽时游戏结束。目标是制作一个有趣且功能齐全的游戏,能够持续计分并给出视觉反馈。

3. Decomposition: Breaking Down the Task | 分解:拆分任务

Decomposition means breaking a large problem into smaller, manageable parts. For our game, we can identify the following sub-tasks:

分解意味着把一个大问题拆分成更小、更易处理的部分。对于我们的游戏,我们可以识别出以下子任务:

Sub-task English Description 中文描述
1 Move the bowl sprite left and right 使碗角色左右移动
2 Create falling fruits from random positions 在随机位置生成下落的水果
3 Detect collision between fruit and bowl 检测水果与碗的碰撞
4 Update and display the score 更新并显示分数
5 Manage lives and end the game 管理生命值并结束游戏

By splitting the project into these smaller pieces, we can focus on solving one part at a time, which makes coding much less overwhelming.

通过将项目拆分成这些较小的部分,我们可以一次专注于解决一个部分,这使得编码变得不那么困难。


4. Identifying Patterns | 识别模式

Pattern recognition involves spotting similarities or repeating structures within a problem. In our game, we can observe several key patterns. First, fruits are created repeatedly, one after another, which suggests using a loop or cloning. Second, checking whether the fruit touches the bowl is a condition that is evaluated every frame; this points to a repeating ‘if’ check inside a forever loop. Third, the bowl movement is triggered by the same type of event (key press) for both left and right directions. Recognising these patterns helps us choose the right programming constructs and avoid writing redundant code.

模式识别涉及发现问题中的相似性或重复结构。在我们的游戏中,我们可以观察到几个关键模式。第一,水果一个接一个反复生成,这提示我们可以使用循环或克隆。第二,检查水果是否碰到碗是一个每一帧都需要判断的条件,指向在一个无限循环中反复执行的 ‘如果’ 检查。第三,碗的左右移动是由相同类型的事件(按键)触发的。识别这些模式有助于我们选择合适的编程结构,避免编写冗余的代码。

5. Abstraction: Filtering Unnecessary Details | 抽象:过滤不必要细节

Abstraction means focusing on the important information and ignoring irrelevant details. When modelling our game, we don’t need to worry about the exact shade of red on an apple, the texture of the bowl, or complex physics like air resistance. The essential features we must capture are: position (x and y coordinates), movement (change in x for the bowl, change in y for the fruit), collision (using overlap detection), and variables (score and lives). By filtering out the non-essential details, we create a simplified model that is easier to implement and understand.

抽象意味着关注重要信息,忽略无关细节。在为游戏建模时,我们不需要担心苹果的确切红色阴影、碗的纹理或空气阻力等复杂物理现象。我们必须捕捉的核心特征是:位置(x 和 y 坐标)、移动(碗的 x 变化,水果的 y 变化)、碰撞(使用重叠检测)和变量(分数和生命)。通过过滤掉非必要细节,我们创建了一个更易于实现和理解的简化模型。

6. Designing the Algorithm – Pseudocode | 设计算法——伪代码

An algorithm is a step-by-step set of instructions to solve a problem. Before coding, we can write pseudocode to plan the logic. Below is the pseudocode for the main game loop, shown in English with its Chinese translation.

算法是解决问题的分步指令集。在编码之前,我们可以编写伪代码来规划逻辑。下面是主游戏循环的伪代码,以英文展示并附中文翻译。

Step English Pseudocode 中文伪代码
1 Set score ← 0, lives ← 3 设置 分数 ← 0, 生命 ← 3
2 Repeat forever: 无限重复:
3 If left arrow key pressed, move bowl left 如果按下左箭头键,碗向左移动
4 If right arrow key pressed, move bowl right 如果按下右箭头键,碗向右移动
5 Every 2 seconds: create a clone of a fruit at random x, y=180 每 2 秒:在随机 x 位置,y=180 处创建一个水果克隆体
6 For each clone: change y by -4 until y < -170, then delete clone 每个克隆体:y 坐标增加 -4,直到 y < -170,然后删除克隆体
7 If touching bowl: increase score by 1, delete clone 如果碰到碗:分数增加 1,删除克隆体
8 Else if y < -170 and not caught: decrease lives by 1, delete clone 否则如果 y < -170 且未被接住:生命减少 1,删除克隆体
9 If lives ≤ 0: stop all and display ‘Game Over’ 如果生命 ≤ 0:停止全部并显示 ‘游戏结束’

7. Key Programming Concepts | 关键编程概念

Several fundamental programming concepts are used in this project. Understanding them helps you not only in Scratch but also in text-based languages later. The table below lists the concepts with explanations in both languages.

这个项目使用了一些基本的编程概念。理解它们不仅有助于你在 Scratch 中编程,也有助于将来学习基于文本的语言。下表列出了这些概念及双语的解释。

Concept English Explanation 中文解释
Event A trigger that starts a script, e.g., when green flag clicked, when a key is pressed. 启动脚本的触发器,例如:当绿旗被点击、当按键被按下。
Loop A block that repeats actions, like ‘forever’ or ‘repeat 10’. Used for continuous movement and checking. 重复执行动作的积木块,如 ‘无限循环’ 或 ‘重复 10 次’。用于连续移动和检查。
Conditional statement An ‘if-then-else’ block that runs code only when a condition is true. Used for collision detection and game-over check. ‘如果-那么-否则’ 积木块,仅在条件为真时运行代码。用于碰撞检测和游戏结束检查。
Variable A named storage location for data that can change, such as ‘score’ and ‘lives’. 一个命名的数据存储位置,其值可以改变,如 ‘分数’ 和 ‘生命’。
Cloning Creating a copy of a sprite that runs its own scripts. Used to generate multiple fruits. 创建角色的副本,该副本运行自己的脚本。用于生成多个水果。

8. Variables and Data Types | 变量与数据类型

Variables are essential for keeping track of the game state. We need to decide on appropriate variable names and data types. In Scratch, variables can hold numbers (integers or decimals) or Boolean values. The following table summarises the variables required for our game.

变量对于跟踪游戏状态至关重要。我们需要确定合适的变量名和数据类型。在 Scratch 中,变量可以保存数字(整数或小数)或布尔值。下表总结了我们游戏所需的变量。

Variable Name Data Type & Purpose (English) 数据类型及用途(中文)
score Integer; stores the number of fruits caught. 整数;存储接住的水果数量。
lives Integer; starts at 3, decreases when a fruit is missed. 整数;初始值为 3,漏接水果时减少。
speed Number (decimal); controls how fast the fruit falls, e.g., set to -4. 数字(小数);控制水果下落的速度,例如设置为 -4。
game_over Boolean; becomes true when lives reach 0, used to stop spawning. 布尔值;当生命值降为 0 时变为真,用于停止生成水果。

9. Implementing the Code in Scratch | 用 Scratch 实现代码

Now we can translate our pseudocode into Scratch blocks. The bowl sprite needs two event-driven scripts: one for moving left and one for moving right. Both use the ‘when [key] pressed’ hat block and a ‘change x by’ block (e.g., change x by -10 for left). To keep the movement smooth even when the key is held, we can place the block inside a ‘repeat until ‘ loop, or simply rely on the keyboard’s built-in repeat – but a simple ‘when key pressed’ block works for basic functionality.

现在我们可以将伪代码转化为 Scratch 积木块。碗角色需要两个事件驱动的脚本:一个向左移动,一个向右移动。两者都使用 ‘当按下 [按键]’ 启动块和 ‘将 x 坐标增加’ 块(例如,左移时将 x 增加 -10)。为了让持续按键时移动更流畅,可以将积木块放在 ‘重复执行直到 <按键不按下>‘ 循环中,或者直接使用 ‘当按键被按下’ 积木块的简单功能。

For the fruit, we use cloning. A ‘master’ fruit sprite hidden off-screen can repeatedly create clones. The script for the master: ‘when green flag clicked’, ‘hide’, ‘forever { wait

Published by TutorHao | Year 7 Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading