Module 3 - The “Cat in a Maze” Project

Z Wiki Mistrzowie Kodowania
Skocz do: nawigacji, wyszukiwania
Logo Mistrzowie.png


These materials have been developed by Ośrodek Edukacji Informatycznej i Zastosowań Komputerów (Centre for Information Technology Education and Application of Computers) in Warsaw as part of the “Mistrzowie Kodowania” (“Coding Masters”) Programme funded by Samsung Electronics Polska, licensed under CC-BY-SA “Attribution – Share Alike 3.0 Poland”

Information

Objectives

General objectives:

  • Review and revision of previously presented Scratch commands and language structures.
  • Development of a simple maze game project.
  • Implementation of the game in the Scratch environment.

Specific objectives:

  • The student will learn to construct simple scripts that respond to pressing a key.
  • The student will understand and know how to use the conditional instruction and the loop instruction.
  • The student will be able to control the behaviour of a sprite based on its location.
  • The student will be able to change and edit the stage background.
  • The student will be able to implement a sprite’s behaviour on a project basis.

Preparation before the class:

Before the class the students receive a file with a background (a ready maze board) for the Cat in a Maze game. Before the lesson we load it to computers in the students’ stations.

Stages

Discussion of solutions to selected module II additional tasks

Time to complete this part: about 15 minutes
At the beginning of the lesson we remind students what they were supposed to prepare between classes. We invite a volunteer to present his/her solution. We discuss with the students if anyone solved the task in a different way. We discuss the solutions (we praise each correct solution to a task).

If there was no homework, we start by reviewing key issues from the previous module. We also ask if students have any doubts about their own projects. If any students want to, we let them present something they are proud of.

Designing a game involving going through a maze

Time to complete this part: about 20 minutes
We suggest the development of a new game during the lesson. This time the purpose of the game will be for our character to successfully get through a maze. We will begin by planning how the game should run.

Together with the students on the board we draw a rectangle, inside there is a simple maze with only one exit. We fill in anything that is not the path inside the maze with a specified colour (e.g. red). We use another colour (e.g. blue) to mark the exit. We colour in the maze path e.g. with green. We put our character in a place (square) opposite the exit (marked with a different colour – blue in our example). The sketch of the maze should be similar to the picture below.

Maze1.JPG

Maze2.JPG

We begin the discussion of how we should describe the behaviour of the character (sprite), and how we are going to control it:
Question: With what should the game start after it is initiated?
There may be various suggestions. We should prompt the students that our character should be placed in the middle of the starting square. It should be noted that the sprite character should entirely fit in a single maze square, so as not to touch its walls.

Question: How will we control the character?
What button are we going to use to make our character go forward? Should it move forever?
– We guide the students to find the answer “No,” because it will collide with a maze wall.

How many steps should it now take?
– Enough to move from one square to the next, adjacent one. We discuss what this means, pointing to the maze drawing on the board. Together we reach the conclusion that the character should move forward a number of steps that is equal to the length of the side of a single field in our maze.

In this case, should we choose to control the character with the computer mouse or the keyboard?
– In this game it will be easier to control the character using the keyboard.

After discussing which key should make the character move by one square, we write on the board what we have agreed on, for example:
* When the up arrow key is pressed, go forward by “one square.

Question: How should the computer react if the character collides with a maze wall?
There will be various answers, such as: the character dies, the game starts from the beginning, etc. We hint that if we do not want the game to end too quickly, it will be enough for the character to bounce off the wall and return to its previous place. Additionally, it can emit a sound, e.g. meow.

We add the following to the previous record, e.g.
* If the character collides with a wall, go back to where it was previously located, and then:
* Play a meow sound.

Question: How can we rotate the character, so that it walks in a different direction?
There will be various suggestions. We write down one of them on the board. NOTE: At this point we discuss how the character is to move (up, down, left, right). We explain how it can rotate. We remind the students of how we drew a square in the first module and rotated the sprite by 90 degrees to the left or right. We guide the students towards a solution where the character is rotated left or right.

After discussing which key should control the character, we write on the board what we have agreed on, for example:
* When the right arrow key has been pressed, rotate the character by 90 degrees to the right.
* When the left arrow key has been pressed, rotate the character by 90 degrees to the left.

Question: What should happen when the character reaches the exit?
We discuss how the game is to end. Let our hero make a sound and display the word “Exit!” in a speech bubble. This is the end of the game, so we should stop all scripts.


After discussing how the game is to end, we write on the board what we have agreed on, for example:
* When the character has reached the exit, play a sound signal and display the word “Exit!,” and then:
* Stop everything.

We recap that we have just created the first version of the rule (algorithm) of our game – that is, how the computer is to react when a player presses certain keys (controls the character in the game), and how it is to react to specific events (e.g. reaching the exit or making an attempt to go through a wall).

We ask the following question: Which of the above tasks can we already accomplish?
– Move the character (we do not yet know how far the character is to be moved)
– Rotate the character 90 degrees to the left or right by pressing a given key
– Change the stage background.

We ask the following question: What do we have to learn?
– How to recognise that the character has walked into a wall, i.e. a prohibited stage area, or reached the exit
– How to move the character backwards, i.e. reverse it
– How to play sounds (unless we have introduced this command earlier in class or as homework / an additional task).