1 of 10

Lesson 14 Debate Keyboard or Mouse?

Coding concept: OnKey, onMouse, and onClick

Coding Adventure Part III

Key stage II

Class VI

2 of 10

Lesson Objectives

  • review what they learned about events.
  • create their own Coding Adventure challenges about events.
  • solve challenges created by their classmates.

Coding Adventure Part III

Key stage II

Class VI

3 of 10

Activity 1 Recap

  • In your notebook, write your understanding of following different events learned about in the challenges 176 - 210:
    1. Keyboard event
    2. Mousemove event
    3. Mouse click event

Coding Adventure Part III

Key stage II

Class VI

4 of 10

Activity 1 Solution

  1. Keyboard event - Click on the keyboard to trigger an action
    • The onKey function is called when we press on the keyboard.
    • The argument of the onKey function is the key we pressed.
    • Optional: Refer to challenge 184 to demonstrate
  2. Mousemove event - Move your mouse cursor to move a character.
    • The onMouseMove function is called when we move the mouse
    • The argument of the onMouseMove function is the position of the cursor
    • The position consists of two coordinates:
      • pos.x - the x position of the cursor
      • pos.y - the y position of the cursor
    • Optional: Refer to challenge 193 to demonstrate

Coding Adventure Part III

Key stage II

Class VI

5 of 10

Activity 1 Solution Cont.

  • Mouse click event – Click on the mouse to trigger an action.
    • The onClick function is called when we click on the mouse
    • There are no arguments for the onClick function
    • The onClick function is defined for each object we want to click on separately
    • Optional: Refer to challenge 203 to demonstrate

Coding Adventure Part III

Key stage II

Class VI

6 of 10

Opening Challenge Builder

  • Challenge Builder allows you to create your own Coding Adventure challenges.
  • Complete the following steps to open Challenge Builder:
  • Log into your CodeMonkey account and click on My Creations (or click on https://app.codemonkey.com/creations).
  • Scroll down to “My Challenges” and click on “CREATE NEW”
  • A pop-up message will appear with Gordo. This is where you will write the instructions for your challenge. You can also edit this later on by clicking on Gordo. Click “OK”.
  • Similarly, in Challenge Builder too, the left-side is the stage and the right-side is the editor (where we write the code).

Coding Adventure Part III

Key stage II

Class VI

7 of 10

Using Challenge Builder

Now, let’s practice all you have learned through building your own Coding Adventure challenges. With Challenge Builder, you can show your peers just how much you know as you send them your own take on the classic challenges.

Coding Adventure Part III

Key stage II

Class VI

8 of 10

Activity 2 Building Challenge for your friends

  • Build one challenge each based on the following topics using Challenge Builder of CodeMonkey platform.
    1. Create a challenge that demonstrates the use of onKey and onMouseMove events.
      • For example: use the keyboard to step and mouse-move toturnTo
    2. Create a challenge that can be solved in two ways: either using only the keyboard event or only using the mouse click event. Then solve it in both ways.
    3. Create a challenge with animals and objects from previous challenges but incorporate events in the solution.
      • For example: use the goat and frozen bananas.

Coding Adventure Part III

Key stage II

Class VI

9 of 10

Activity 3 Solving friends Challenges

  • Once you finish building, you can share your challenge with your friends in the classroom.
  • Solve at least three challenges shared.

Coding Adventure Part III

Key stage II

Class VI

10 of 10

Key Points

  • The Keyboard and Mouse Event Challenge necessitates the combined use of `onKey` events for movement control and `onMouseMove` events for altering direction.
  • 2. The Two-Way Challenge with Keyboard and Mouse Click Event offers a puzzle or game scenario solvable exclusively through keyboard inputs or mouse click interactions.
  • 3. In the Event-Driven Challenge with Animals and Objects, participants engage with familiar elements such as animals and objects from previous challenges, utilizing events like `onCollision` to trigger actions like thawing frozen bananas.

Coding Adventure Part III

Key stage II

Class VI