CPSC 110-08: Computing on Mobile Phones
Spring 2012

Simple Memory Game

CS Principles

This activity addresses the ideas of creativity, algorithms, and programming. It focuses, in part, on the following learning objective:

Introduction

This is a follow-up to the homework assignment in which you created and displayed a list of random numbers between 0 and 9. Let's now turn it into a game that works as follows:

User Interface

Let's open the project that we developed for homework and save it as a new app called MemoryGame. In addition to the user interface elements used there, we'll need to add the following components:

Add these components to the user interface, which should now look like this (click to enlarge):

Blocks Editor

Because we are going to be keeping track of the user's list, we will need a second list variable.

We will input data to this list from the user interface, whenever the user clicks the CheckMyList button. However, we need to convert the data that the user typed (which is text) to an App Inventor list (which is not text). Fortunately, App Inventor provides the built-in list from csv row function (in the Lists drawer) to perform this conversion for us. A CSV is a comma-separated-value, a common way of representing spread sheet data:

The algorithm for comparing the player's list with the list generated by the computer is straightforward: we can just check whether the two lists are equal, as in if/else block in the following code segment (click to enlarge):

For this version of the app we simply use a Notifier component to report whether the player remembered the list correctly or not.

Important Points

  1. A List is an important type of data used in most programming environments.
  2. A loop is a control structure that enables us to repeat statements 0 or more times.
  3. Loops are useful for processing lists in App Inventor.

In-class Exercises

As time permits, and working in your project teams, add the following enhancements to the memory app:

Update your portfolio page for this assignment with a screenshot of this version of the app and a brief summary of the enhancements you made to the app during this class.