9.5. Magic 8 Ball Tutorial and Projects (Optional)

This lesson includes both a tutorial that leads the student through the creation of a mobile version of the classic "Magic 8 Ball" game and several programming challenges that students will work in pairs to solve. The Magic 8 Ball app simulates the Magic 8 Ball game: when the user asks a question and shakes the device the app will respond with a random prediciton. The tutorial shows how to use App Inventor's Accelerometer to detect the device's motion and its Text to Speech component to convert text to speech. Two of the programming tasks involve the use of App Inventor's Clock component and can be quite challenging. A solution to those is provided in the lesson plan. In addition to promoting the enduring understanding about the importance of collaboration in designing and writing programs, this lesson also introduces an important new programming abstraction, a list, which is used to store a collection of items in the computer's memory. It thus also reinforces the enduring understanding that programming is facilitated by appropriate abstractions.

Professional Development

The Student Lesson: Complete the activities for Mobile CSP Lesson 9.5: Magic 8 Ball Tutorial and Projects.

Materials

9.5.1. Learning Activities

Estimated Length: 90 minutes

Day 1 - Magic 8 Ball Tutorial (45 minutes)

  • Hook/Motivation (10 minutes): "What is a Magic 8-Ball?" Have they ever used one? What does it do? Is it possible to make a virtual Magic 8-Ball? A Magic 8-Ball is a fortune-telling toy. Ask it a Yes or No question, shake it, and it will make a prediction.
    • Wikipedia has a nice explanation of a Magic 8-Ball.
    • The Three Stooges used a Magic 8-Ball in their "You Nazty Spy" series from the 1940s. See at the 1:00 minute mark of this video clip. (Can't find a free online version in English.)
    • Play with Ask 8 Ball, a free online version of the game.
  • Experiences and Explorations (25 minutes): Describe the student objectives for today’s lesson. In today's lesson another abstraction concept, the concept of defining a list, will be introduced. Lead the students through the Magic 8-Ball tutorial. Allow faster students to follow the tutorial on their own. If using the Magic 8-Ball Template identify new components used in this app as you discuss the design of the UI with the students and walk students through the coding of the app. You can also choose to use the Magic 8-Ball Media Only Template and create the UI from scratch with the students.
    Be sure to discuss the Accelerometer component; creating a list and how a random item from a list can be chosen. This includes identifying an empty list, a list index, and the length of list; and the Text-to-Speech component.
  • Rethink, Reflect and/or Revise (10 minutes): Have the students try to complete the interactive exercises and complete a reflection in their portfolio.

Day 2 - Magic 8 Ball Projects (45 minutes)

  • Hook/Motivation (10 minutes): Discuss possible enhancements to the Magic 8-Ball app using the Think-Pair-Share technique.
  • Experiences and Explorations (25 minutes): Students work in pairs on enhancements to Magic 8-Ball; teacher answers questions.
  • Rethink, Reflect and/or Revise (10 minutes): Students make a new entry in their portfolios. Have the students describe the modifications and enhancements that they made to the Magic 8-Ball app. Also ask the students to reflect on their programming experience. See the Magic 8-Ball mini projects solutions. Discuss what issues the students encountered while modifying the Magic 8-Ball app. Check students understanding using the interactive exercises.

AP Classroom

The College Board's AP Classroom provides a question bank and Topic Questions. You may create a formative assessment quiz in AP Classroom, assign the quiz (a set of questions), and then review the results in class to identify and address any student misunderstandings.The following are suggested topic questions that you could assign once students have completed this lesson.

Suggested Topic Questions:

Assessment Opportunities

You can examine students’ work on the interactive exercise and their reflection portfolio entries to assess their progress on the following learning objectives. If students are able to do what is listed there, they are ready to move on to the next lesson.

  • Interactive Exercises:
  • Portfolio Reflections:
    LO X.X.X - Students should be able to ...
  • In the Magic 8 Ball App, look for:

Solution to the Challenges: Here is one solution to the two challenge problems given in this lesson. It involves using both the Clock and the SpeechRecognizer. The logic behind this algorithm can be a bit tricky. It involves coordinating the behavior of three separate blocks.
First, when the device is shaken, the Sound is played and the SpeechRecognizer is started. Notice also that the label that displays the answer is blanked out. When the SpeechRecognizer is started, it will prompt the user, which will stop any further blocks from firing.

When the user stops speaking, the SpeechRecognizer's AfterGettingText block will fire automatically. This is where you would repeat what the user said (optional) and enable the Timer. This will start the Timer ticking. To provide a sufficient delay, the Timer interval is set to 2000 milliseconds.

Finally, when the Clock.Timer block fires, you want to get and speak the prediction and stop the Timer.

Of course, this is only one possible solution to the problem. There are others.

Differentiation: More Practice

Differentiation: Enrichment

ListPicker components can be initialized from a list variable using the Elements property (instead of ElementsFromString). Have students change their code to make use of a list for the Speak, Sound, Silent options.

Background Knowledge: Lists and ListPicker

Lists are frequently used to store multiple pieces of similar data, instead of multiple variables. AppInventor.org has a number of How Do You? mini-lessons on lists that will provide more background on how lists are used, as well as a chapter in the AppInventor 2 book. We will be using lists more throughout the course and learn some of those concepts in upcoming lessons.

ListPickers are a common and useful UI component in mobile apps as they save space on smaller, mobile screens. Key events and properties are summarized in the table below.

Event or Property Description
Event: BeforePicking Triggered when the ListPicker is clicked, use to set the list dynamically
Event: AfterPicking Triggered after the user makes a choice, use to respond to a choice
Property: Elements A list of choices
Property: ElementsFromString A comma-separated string of choices (EX: choice1, choice2, choice3)
Property: Selection The user's choice
Property: SelectionIndex The position of the user's choice (first item in the list is 1)

9.5.2. Professional Development Reflection

Discuss the following questions with other teachers in your professional development program.

  • How does this lesson help students toward the enduring understanding that programming is facilitated by appropriate abstractions, in this case a list?
    [EU 5.3]
    ?

You have attempted of activities on this page