SIGCSE 2010 Kid's Camp
Alice session on Event Handling
In the previous session the children learned to write a program to make a Kangaroo jump up and down. But what if we want to control the Kangaroo and make it jump only when we want it to? In that case we need to create an event and program it into the Alice world, so that we can trigger the Kangaroo into jumping by either pressing a key or clicking the mouse button. We discussed the following example to understand how a computer program handles such interactivity with events.
- Event trigger: The cell phone rings
- Event listener: The ear hears the ring
- Event handler: We answer the phone
The analogy in an Alice world:
- Event trigger: A key is pressed or mouse is clicked
- Event listener: In-built program in Alice
- Event handler: Your program to make your Alice object do whatever you want
The children were asked to create an Alice world with a penguin that would jump up or flap its wings only when the space bar was pressed.
Since the penguin already knew how to jump, flap wings etc. the children were asked to write a new method for the penguin to laugh. The steps in the process were to make the penguin's head turn upwards, make it say "Ha ha ha", play a laughter sound (imported from an external file) and make its head turn back to normal.
The following Alice worlds can be opened and viewed in Alice 2.2 (Freely Available)