Turn off Lights - B

12

This lesson suggests several small programming projects for enhancing the TurnOffLights app.

Hints and suggestions are provided.

Objectives

  • better navigate the App Inventor online programming platform

  • deepen your understanding of event-driven programming

  • develop your understanding of how variables are incremented

  • develop a better understanding of conditional if blocks and apps that make decisions

Getting Ready

  • For this lesson you can use the project you created in the previous lesson. Start up App Inventor and after opening your TurnOffLights project, rename it TurnOffLightsV2, for Version 2 , or something similar to that. Then complete the programming exercises described below.

Enhancement Ideas and Hints

Here are some creative project ideas. Complete all of them, you may work getting help from others, but should have your own personal app. You are encouraged to discuss your ideas for how to solve these problems with the instructor and with other students.

1. Personalize the app by changing its theme to one that you like. This will require you to add your own images for the Canvas background and the ImageSprite.


2. To make this more like a real game, add a scoring feature to the app, modifying the UI so it can display changes to the user's score as it changes.

    • Hint: Use what you learned in the Paint Pot app about incrementing a variable to implement the score feature.


3. If/else algorithm: Add a winning score feature that stops the game and congratulates the user when they reach a certain score. Stopping the game should include stopping the ImageSprite from jumping around.

    • Possible enhancement: Use a TextToSpeech component and have it say something when the player reaches a certain score. Or use a Notifier component to pop up and congratulate the player.


4. Procedural abstraction: Add a Reset button to the app that allows the player to restart the game after it's been stopped. Define a resetGame procedure to encapsulate the tasks involved in resetting the game. These would typically include setting the score back to 0 and getting the ImageSprite to start moving again. In addition to calling the procedure from the reset button event handler, it should be called from the Screen1.Initialize handler. Make sure you use good naming conventions when you add a button to the app.


OPTIONAL: Create one or more of your own enhancements or variations for this app. Here are some ideas:

    • You could also implement keeping track of the number of misses: i.e., the number of times the player failed to touch the ImageSprite, and factor this into your scoring algorithm. (see code below on how to start)

    • Challenging. Add a second image to the app to turn the game into one that forces the player to distinguish between "good" and "bad" choices. For example, if your app had a nutrition theme, perhaps one image could be picture of a healthy food item and the other a not-so-healthy item. Perhaps the player's score decreases if they touch the "bad" choice.

    • Challenging: Change the speed of the mole when the player reaches a certain score.

      • Hint: Recall that in this app, the Mole's speed is controlled by the Clock timer.