ILMS v2 LEARNER
ILMS v2 LEARNER
Smartphone
Acknowledgements
This resource was partially funded by a grant from Education Scotland. We are also grateful for
the help and support provided by the following contributors:
Special thanks go to Ian King who assisted with updating these materials for App Inventor 2.
The contribution of the following individuals who served on the RSE/BCS Project Advisory Group
is also gratefully acknowledged: Professor Sally Brown (chair), Mr David Bethune, Professor Alan
Bundy, Professor Quintin Cutts, Ms Kate Farrell, Mr William Hardie, Dr Fiona McNeill, Professor
Greg Michaelson, Dr Bill Mitchell and Professor Judy Robertson.
Some of the lessons within this resource are based on existing work by Professor David Wolber of
the University of San Francisco and the App Inventor EDU site, reproduced and adapted under
Creative Commons licence. The author thanks those concerned for permission to use and adapt
their materials.
Page i
I ♥ My Smartphone Acknowledgements
For Sarah, who loves her smartphone, and Anna, who loves her smartphone too.
Page ii
I ♥ My Smartphone Contents
Contents
A Brief History of the Telephone ...................................................................... 1
Mr Watson, come here – I want to see you! ................................................. 1
Going mobile .................................................................................................. 2
When mobile phones became smart phones ................................................ 3
Convergence: Bringing it all together ............................................................ 4
Telephone…or computer? ............................................................................. 6
Smartphone Software ..................................................................................... 9
Operating system ........................................................................................... 9
Apps ............................................................................................................. 10
The mobile app industry .............................................................................. 11
Mobile App Development.............................................................................. 13
Lesson 1: Virtual Pet ...................................................................................... 15
Virtual Machines .......................................................................................... 17
Lesson 2: Finger Painting ............................................................................... 19
The Importance of Design ............................................................................ 19
Bugs .............................................................................................................. 21
Variables....................................................................................................... 22
Lesson 3: Mole Masher Game ........................................................................ 27
Procedures ................................................................................................... 28
Comments .................................................................................................... 29
Lesson 4: Times Table Helper ......................................................................... 33
Validating Input ............................................................................................ 39
Lesson 5: Virtual Map Tour ............................................................................ 41
Lists (Arrays) ................................................................................................. 43
Lesson 6: Heads I Win .................................................................................... 45
Lesson 7: Wiff-Waff Game ............................................................................. 49
Summary ...................................................................................................... 55
Mobile App Project ....................................................................................... 57
Congratulations ............................................................................................ 65
Page iii
I ♥ My Smartphone Contents
Page iv
I ♥ My Smartphone A Brief History of the Telephone
In the 1940s and 1950s, radio telephones in cars became available, but these were
expensive, bulky and plagued with poor reception.
Page 1
I ♥ My Smartphone A Brief History of the Telephone
Going mobile
The first experimental hand-held mobile telephone was
demonstrated in 1973 by Motorola and weighed around 1kg,
but it was not until 1983 that the first devices went on sale.
These early devices were large and heavy, had a short battery
life and were capable only of making telephone calls.
Investigate the products below. Complete the table by writing down what you think
are the two most important features of each device.
Page 2
I ♥ My Smartphone A Brief History of the Telephone
Page 3
I ♥ My Smartphone A Brief History of the Telephone
This is an example of convergence – that is, integrating technologies which were once
separate into a single device.
Investigate the following technologies. Beside each one, write down its function (what
it does) and an example of a portable device (other than a smartphone) which uses it.
a microphone translates sound vibrations in the air into
electric signals and scribes them to a recording medium
Microphone Function or over a loud speaker
___________________________________________
hyperx quadcast
Example device ______________________________________
Page 4
I ♥ My Smartphone A Brief History of the Telephone
Discuss with your neighbour what you think will be the next big advances in
smartphone technology. Using either a graphics package or pencil & paper, draw a
labelled design for a smartphone 10 years from now.
Page 5
I ♥ My Smartphone A Brief History of the Telephone
Telephone…or computer?
Whilst we use the term “smartphone” to describe a modern multi-function mobile
telephone, it is probably better to think of it as a pocket computer which also happens
to make phone calls.
Discuss with your neighbour what each of these could be within a smartphone.
Write down your answers.
CPU, GPU
Processing
Page 6
I ♥ My Smartphone A Brief History of the Telephone
Did you know…? For many users, phoning is one of the tasks they perform the least on their smartphone.
In a 2013 survey, 26% of respondents said they chat for less than half an hour each
month on their handset. 23% said they surf the web on their phone for more than five
hours a month, while just 9% made voice calls for the same amount of time.1 A more
recent survey2 showed that a quarter of smartphone users would typically not even
make one voice call per week.
A 20163 report from network company Cisco stated that mobile data traffic had grown
4,000-fold over the previous 10 years and almost 400-million-fold over the previous 15
years. In 2015 alone, there was a 75% increase in mobile data traffic.
mobile data traffic will increase another eight-fold, with approximately three
quarters of that data being video;
there will be around 1.5 Internet-connected mobile devices for every person on
the planet, with smartphones accounting for nearly 50% of all devices.
Finally, a 2014 study4 revealed that the average person spends 90 mins a day on their
phone – meaning that nearly 4 years of the average person's life is spent staring at their
phone screen!
1
Source https://gigaom.com/2013/07/19/data-is-now-a-higher-priority-than-voice-uk-mobile-
users-say/
2
Source https://www.theguardian.com/news/datablog/2015/sep/08/one-in-four-uk-
smartphone-weekly-phone-calls
3
Source http://www.cisco.com/c/en/us/solutions/collateral/service-provider/visual-networking-
index-vni/mobile-white-paper-c11-520862.html
4
Source http://www.mobilestatistics.com/mobile-news/23-days-a-year-spent-on-your-
phone.aspx
Page 7
I ♥ My Smartphone A Brief History of the Telephone
Page 8
I ♥ My Smartphone Smartphone Software
Smartphone Software
All of these technologies would be useless without software to bring them together.
Software is the name for computer programs – list of instructions – which tell the
computer hardware how to perform a task. On mobile devices, there are two main
pieces of software:
Operating system
An operating system (OS) is a set of programs that a computer runs all the time it is
switched on.
The OS sits between apps and the computer’s hardware, letting apps
access the hardware. This is why it is possible to run software OS
written for an OS such as Microsoft Windows on a wide variety of
different computers.
Write down the names of some mobile device operating systems. Beside each one,
give the name of an actual device that it runs on.
If you or someone you know has a smartphone, write down what it is and the name of
the operating system it runs.
Page 9
I ♥ My Smartphone Smartphone Software
Apps
Once your computer or smartphone has started up, you will want to do some tasks with
it. Don’t worry – no matter what you want to do, there’s almost certainly an app for it!
The word “app” is short for application. An application is a computer program that
enables the computer to do a useful job.
Now investigate a mobile app store such as Apple’s App Store or Google Play. Write
down the names of three mobile apps and their cost.
Instagram: Free
____________________________________________________________________
Facebook: Free
____________________________________________________________________
Twitter: Free
____________________________________________________________________
In most cases, you will see that a mobile device app has fewer features than a desktop
application. This is usually reflected in the price, with many apps being free, or costing
less than a pound.
Page 10
I ♥ My Smartphone Smartphone Software
A 2015 report stated that the “app economy” supports 1.8 million jobs across the entire
EU, and this is predicted to rise to 5 million by 2018 5. The same report said that the
European app economy is predicted to rise to €63 billion by 2018. A separate 2016 study
reported that there are 1.66 million app economy jobs in the USA alone6.
Worldwide, the app economy is predicted to be worth over $100 billion by 2020 on the
back of nearly 300 billion downloads per year. At the time of writing, 85% of all
smartphone app sales were for games7.
Whilst many mobile apps are created by professional software development companies,
there are also many “bedroom developers”8 – people who create mobile apps in their
spare time, either as a hobby or a sideline to their main job. There are over 35,000 such
people in the UK alone. It is also an industry dominated by young developers.
5
http://eurapp.eu/2014/02/13/study-finds-total-18-million-jobs-eu-app-economy-
%E2%82%AC175-billion-revenues-taken-eu-app
6
http://www.progressivepolicy.org/slider/app-economy-jobs-part-1/
7
https://www.appannie.com/landing/forecast
8
http://www.visionmobile.com/product/uk-app-economy-2014/
Page 11
I ♥ My Smartphone Smartphone Software
Page 12
I ♥ My Smartphone Mobile App Development
App Inventor is a powerful software development environment that lets you create apps
for Android smartphones. We will be learning how to use App Inventor through a series
of lessons.
At the end of each task, there will be some questions which will assess your
understanding of what you have learned.
Page 13
I ♥ My Smartphone Mobile App Development
Page 14
I ♥ My Smartphone Lesson 1: Virtual Pet
Mobile features
Touch interface
Working with sound
Introduction
Your teacher will demonstrate a simple mobile app to you. This is the app that you are
going to create – an on-screen virtual pet which you have to “care” for.
Once you have done this, try creating a similar screen for your own VirtualPet app. Feel
free to experiment with the different properties of each component!
Watch screencast VirtualPet2, then try to create your own version of the app. If you get
stuck, go back in the screencast or ask your partner.
Page 15
I ♥ My Smartphone Lesson 1: Virtual Pet
Did it work as intended? If not, go back and check your code for any mistakes. If that
doesn’t work, check the properties of your app’s components too.
Page 16
I ♥ My Smartphone Lesson 1: Virtual Pet
Virtual Machines
The Android emulator is a recreation of a complete Android mobile phone
on your computer.
It is obviously not a real phone – it can’t make calls or receive texts, for
example. However, App Inventor sees it as one, and sends the same
commands to the emulator during testing as those sent to a phone.
The Computing Science term for this is a virtual machine.9
Extension Task 1
This virtual pet reacts to being touched, rather than being stroked. Your teacher will
now demonstrate how to replace the Button component with a Canvas component,
which can detect a drag event.
Now alter your app so that the cat meows only when it’s being stroked.
Extension Task 2
In the Designer, add an image sprite (Animation→ImageSprite) under the cat’s chin.
Make it big enough to detect a touch. Just leave it blank, with no image file.
In the Blocks Editor, use a Sound.Vibrate block from your sound component’s drawer,
make your cat purr (i.e. make the phone vibrate) when you stroke under its chin!
9
Strictly speaking, a virtual machine is a computer running in software that, like a physical
computer, has an operating system and can run applications.
Page 17
I ♥ My Smartphone Lesson 1: Virtual Pet
Unfortunately, there is a
bug in the app – a problem
that stops the app working
as expected.
__________________________________________________________________
__________________________________________________________________
1.2 What change would you have to make to the code to correct it?
__________________________________________________________________
__________________________________________________________________
1.3 Now make your change. Did it fix the problem? Did you have any problems doing
this?
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Page 18
I ♥ My Smartphone Lesson 2: Finger Painting
Mobile features
Touch interface
Graphics
Camera
Accelerometer
Introduction
Your teacher will demonstrate a touch-driven finger painting app.
Page 19
I ♥ My Smartphone Lesson 2: Finger Painting
Watch screencast FingerPaint2 to see how to build the code (shown above).
Page 20
I ♥ My Smartphone Lesson 2: Finger Painting
Bugs
A bug is an error which stops your code working as expected. There are two main types
of bug which can occur in a program:
● Syntax error
This happens when the rules of the language have been broken e.g. by mis-
spelling a command. Syntax errors usually stop the code from running.
Languages like App Inventor provide code in ready-written blocks, so you won’t
make many syntax errors.
● Logic error
This means your code runs, but doesn’t do what you expect.
Unfortunately, it’s still possible to make logic errors in App Inventor!
A third kind of error is also possible:
● Execution/run-time error
This means your program crashes (stops running) when it is run (executed).
This may be the result of performing an operation such as division by zero, for
example.
Finding and fixing these errors in a program is known as debugging.
a) The starting colour of the “paint” is black. Once you select another colour, there
is no way to get back to black.
b) The starting colour of the line is 1 pixel wide. Once you select the big or small
brushes (5 or 15 pixels), there is no way to get back to 1 pixel.
2.1 Discuss with your partner what features your app would need to solve each of
these problems. Write your suggestions below:
_____________________________________________________________
_____________________________________________________________
Page 21
I ♥ My Smartphone Lesson 2: Finger Painting
2.2 Discuss what you could do to reduce the chance of logic errors appearing in your
apps. Write your suggestions below.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Did you know…? It is often said that the word “bug” dates back to 1947 when an early computer at
Harvard University broke down because of a moth stuck in a switch!
Whilst this did happen, the use of the word “bug” to mean an error or problem with a
machine was used as far back as the 1800s.
Variables
A variable is a space in a computer’s memory where we can hold information used by
our program. It’s just like storing something in a box.
We should always give a variable a sensible name that indicates the kind of information
that’s been stored there…just like putting a label on the box to tell us what’s inside.
To create (or define) a variable in App Inventor, we use the built-in initialize block and
then plug in a value to tell the computer what type of
data it will contain such as text or a number. Remember
to give the variable a sensible name, too.
Once a variable is defined, the information stored inside it can be changed (or varied) –
hence the word “variable”.
Page 22
I ♥ My Smartphone Lesson 2: Finger Painting
Now alter your app so that every time the user clicks on ButtonBigBrush or
ButtonSmallBrush, the size of the brush is increased or decreased by 1 pixel.
So, if brushSize was previously 5, it would now be equal to 6. Another click would make
it 7, and so on. Once it has been set, we set the canvas line width to this value.
Once you have done this, create the code for ButtonSmallBrush.
This will take the user to the camera app on the phone. After taking a photo, it will
become the background of the drawing canvas. The user can then paint on the photo!
Hint: Add a camera button to the bottom row on the screen (a camera icon is provided
with this lesson’s graphics). You will also need a camera component (Media→Camera).
/…
Page 23
I ♥ My Smartphone Lesson 2: Finger Painting
Let’s consider how we can make this happen and the code we’d use:
Algorithm
when camera button is clicked
take a picture
Code
This will let users save their masterpieces to the image gallery on their phone!
Hint: add a save button to the bottom row on the screen (provided with this lesson’s
graphics – see down arrow icon opposite). You will also need a TinyDB component –
this is used to store data permanently on the phone (Storage→TinyDB).
Note that this feature only works when the app is downloaded to the phone.
It will not work under live testing or on an emulator.
Algorithm
when Save button is clicked
store drawing canvas image as file
Page 24
I ♥ My Smartphone Lesson 2: Finger Painting
2.3 What type of variable – text or number – should be used to store the following
values:
a) 23 ______________________________________________________________
b) Alice ____________________________________________________________
c) 3.14 ____________________________________________________________
e) Fourteen ________________________________________________________
2.4 Using short variable names like a, b or c seems like it could save a programmer
time and effort in typing. Why would this be a bad idea?
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
2.5 A variable name should always be as meaningful as possible – that is, the name
should suggest the value that’s being stored. However, we shouldn’t make it
longer than necessary.
Write down suitable variable names for the names and scores for two players in a
game (four variables in all)
__________________________________________________________________
__________________________________________________________________
2.6 /…
Page 25
I ♥ My Smartphone Lesson 2: Finger Painting
2.6 Think of some non-Computing examples of “variables” and their possible values.
An example is shown below:
Variable: __________________________________________________________
Variable: __________________________________________________________
2.7 A user starts up a FingerPaint app and immediately clicks ButtonBigBrush (code
shown below).
However, when the user tries to paint, nothing appears on the canvas until they
click ButtonBigBrush a second time.
Discuss with your partner why this happens and what change(s) should be made
to the code to fix this bug.
Reason ____________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Page 26
I ♥ My Smartphone Lesson 3: Mole Masher Game
Mobile features
Touch interface
Working with graphics
Using timers in games
Introduction
Your teacher will demonstrate a simple mobile version of a popular fairground game
(commonly known as Whack-a-Mole). In this game a mole appears and you have to tap
it quickly before it disappears again. This is the app that you are about to create.
We’ll now design our code by creating an algorithm for each stage.
Page 27
I ♥ My Smartphone Lesson 3: Mole Masher Game
Algorithm
To Update Score Display (procedure)
set the text of the score label to “Score: “ + the score
Watch screencast MoleMasher2 to see how to build the code from the algorithm above.
Procedures
In this lesson, we saw how lines of code can be grouped together into a procedure.
Creating a procedure is like creating a new command in your programming language.
Procedures let us:
● break down a problem into smaller problems and solve each of those separately.
We can then concentrate on just one small “sub-program” at a time.
● create a single piece of code that we can use (or call) as often as we need to
within a program. This saves us “reinventing the wheel” by entering the same
code lots of times.
As a general rule, whenever you have a clear “sub-task” in your program, you should
create a procedure to do this. It will make your life easier!
Page 28
I ♥ My Smartphone Lesson 3: Mole Masher Game
Extension 1
Adapt your program to display the number of misses as well as the number of hits.
Extension 2
Display a “GAME OVER” sprite on the canvas when the misses reach a certain number.
Hint: Create a GameOver procedure for this.
Comments
You may have noticed that some code is shown with small comments
beside it in speech bubbles.
Comments are used to explain what code is doing. This is useful if you’re working as
part of a team, so that other programmers can understand your code – or even for
yourself, when you try to update your app this time next year!
All good programmers use comments to explain key stages in a program.
Remember: comments are there to help you and can save hours of frustration when
you’re trying to understand another programmer’s (or even you own) code!
Extension 3
Go back to your code and add comments to it.
Note that you would normally add comments as you create your code, not afterwards.
Page 29
I ♥ My Smartphone Lesson 3: Mole Masher Game
3.1 How could you make the game more difficult for users?
__________________________________________________________________
__________________________________________________________________
3.2 Discuss the following examples from real life. What “procedures” could they be
broken down into?
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
3.3 Discuss with your partner some examples of sub-tasks within a simple “space
invader”-type game that could be coded as procedures.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Page 30
I ♥ My Smartphone Lesson 3: Mole Masher Game
3.4 A user scores 10 hits and 5 misses in a MoleMasher app, then clicks a Reset
button (code shown below).
LabelHitsNumber: ___________________________________________________
LabelMissesNumber: ________________________________________________
Write down any changes you would make to the code for the Reset button below:
when ButtonReset.Click do
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Page 31
I ♥ My Smartphone Lesson 3: Mole Masher Game
Page 32
I ♥ My Smartphone Lesson 4: Times Table Helper
Mobile features
Touch interface
Using the keypad
Introduction
Know your times tables? All of them…? How’s your 47 times table?!
In this lesson, we’re going to create a handy times table reminder that goes way beyond
the 1 to 12 times tables.
Page 33
I ♥ My Smartphone Lesson 4: Times Table Helper
Getting the times table number from the user via the text box
Creating the times table header e.g. The 12 Times Table
Creating the times table itself
Page 34
I ♥ My Smartphone Lesson 4: Times Table Helper
Algorithm
When button “Display table” clicked
set a variable <table> to the number entered in the text box
call Create Table Header procedure
call Create Table procedure
clear the text box
To create a new line in the table we create the following block of text:
So, if the user enters 5 for the table number, it will create the text:
1 x 5 = 5
2 x 5 = 10
3 x 5 = 15
…and so on.
Now watch screencast TimesTable. This will take you through creating the code that
implements the algorithm above.
Page 35
I ♥ My Smartphone Lesson 4: Times Table Helper
a) 1 to 10
…etc.
NB There is no input from the user in this app. It should just work when you click a
“Display conversion table” button
Choose suitable start and end points for the amounts, as well as an interval (step) for
your table. Use a search engine to find out the current exchange rate when testing your
app.
Page 36
I ♥ My Smartphone Lesson 4: Times Table Helper
4.1 From a programming point of view, why is it a good idea to let the user enter the
table via an input box and store this in a variable?
__________________________________________________________________
__________________________________________________________________
After creating the first times table, it keeps adding new tables on to the end of
the previous one every time the display table button is clicked, instead of
replacing the current times table.
If you haven’t already noticed this, try out the app again. You may have to scroll down
on the phone/emulator to see this, so make sure the Scrollable property is ticked in
your Screen1 component.
4.2 Discuss why you think this happens. Write your reason below.
__________________________________________________________________
__________________________________________________________________
4.3 Discuss what change you would need to make to the code to prevent this from
happening. Describe it below.
__________________________________________________________________
__________________________________________________________________
4.4 After discussing your answer to 4.3 (above) with your teacher, make the change
to your code.
__________________________________________________________________
__________________________________________________________________
Page 37
I ♥ My Smartphone Lesson 4: Times Table Helper
Try clicking the Display Table button without entering a number. Your app will
display an error message then quit. This is known as a program crash.
__________________________________________________________________
4.6 Discuss why you think the app crashed. Write your reason below.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
4.7 Discuss what could be done to prevent the app from crashing. Write down your
suggestion below.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Page 38
I ♥ My Smartphone Lesson 4: Times Table Helper
Validating Input
Whenever we get input in a program we should always check that it is valid – allowable
or reasonable – before we process it.
If an input is invalid, we should:
● tell the user they have entered an invalid value
● tell them what the valid values are
● ask them to re-enter their input
The program should not progress until the user enters a valid value.
Now let’s amend the app so that if the text box is empty, the user receives an error
message. Our app will only create the times table if a number is entered.
Algorithm
if text box is empty
display error message
else
display table
A Notifier is useful because it stops the user performing any other function in the app
until they have dealt with the notification. This way, we can be sure the user has seen
and (hopefully) read the message.
Page 39
I ♥ My Smartphone Lesson 4: Times Table Helper
4.7 Write down a range of valid values for the following inputs:
4.8 Write down an invalid value for a number that an app will divide another number
with.
__________________________________________________________________
4.9 In this app, we saw the use of an if…else statement to tell whether or not the user
had entered a value into the text box.
Now consider an app which decides whether students’ test scores resulted in a
pass or a fail (assume a pass mark of 50).
Which of the following if…else statements would produce the correct results?
Write the letters of the correct statements below the table.
Page 40
I ♥ My Smartphone Lesson 5: Virtual Map Tour
Mobile features
Touch interface
Working with lists
Linking to external services
Introduction
In this example, we’re going to create a guided tour that
links in to Google Maps.
When the user clicks the “Explore Edinburgh” button, they will be presented with a list
of popular sightseeing destinations within the city, each of which will bring up that
location in the phone’s Maps app. The user will then tap the phone’s Back button to
return to the Tour app.
/…
Page 41
I ♥ My Smartphone Lesson 5: Virtual Map Tour
Note that you must enter the properties for the ActivityStarter exactly as shown
(including upper/lower case letters).
Page 42
I ♥ My Smartphone Lesson 5: Virtual Map Tour
Algorithm
Set up the lists
create variable containing a list of place names
create variable containing a list of map references
Watch screencast MapTour to learn how to create the code needed for the app.
Extension 1
Alter your app to create a similar map tour for your own local area. Remember – you can
use Google’s Street View to get up close!
Lists (Arrays)
Lists (also called arrays by Computing Scientists) are ideal for storing items of data that
are related, rather than having separate variables for each item. For example, we could
store the name of everyone in a class in a single list instead of having separate variables
for Student1, Student2, Student3, etc.
In this example, we worked with two lists:
● one that held the place names the user sees in the list picker
● one that held the corresponding Google Maps locations (URIs)
By keeping the two pieces of information in the corresponding position in each list, we
could tie them together – that is place name #1 corresponded to map location #1, etc.
This is a common way of tying two or more pieces of information together in Computing
Science.
Page 43
I ♥ My Smartphone Lesson 5: Virtual Map Tour
Your app should now provide a live readout of your current location!
Page 44
I ♥ My Smartphone Lesson 6: Heads I Win
Mobile features
Touch interface
Introduction
In Lesson 4: Times Table Helper, we used a FOR loop to repeat
a piece of code a fixed number of times. For this reason, a FOR
loop is sometimes called a fixed loop.
It is also possible to repeat code while a condition is true, ending only when something
has happened e.g. the user has entered the correct password. This is called a
conditional loop.
In this lesson, we are going to create an app which simulates the toss of a coin and
displays the output. The simulation will continue until Heads appears six times.
Page 45
I ♥ My Smartphone Lesson 6: Heads I Win
We will have two variables: one for the side (1 or 2, chosen at random to represent
Heads or Tails) and one to count the number of heads. The app will continue tossing the
coin until it has counted a total of six heads, then display the total number of tosses.
Algorithm
To Initialise (procedure)
set side to 0
set headsCounter to 0
set output label to <empty text>
Page 46
I ♥ My Smartphone Lesson 6: Heads I Win
Extension 1
Discuss with your partner how you would change this app so that it displays the number
of times the coin was tossed. Write down your ideas below.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Discuss this with your teacher, then make the change to your app.
Extension 2
Discuss with your partner how you would change this app so that it continues until 6
heads in a row are produced. Write down your ideas below.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Discuss this with your teacher, then make the change to your app.
Extension 3
Discuss with your partner how you would change this app so that it continues until
either 6 heads in a row or 6 tails in a row are produced. Write down your ideas below.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Discuss this with your teacher, then make the change to your app.
Page 47
I ♥ My Smartphone Lesson 6: Heads I Win
Let’s add a great feature to this app – shake the phone to toss the coin!
However, instead of copying and pasting your code all over again from the
ButtonTossCoin.Click block, can you think of a better way to do it?
Discuss this with your partner and write down your idea below.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Now discuss this with your teacher, then make the change to your app.
NB All that you need to do is give the phone a gentle flick. If you shake it too much,
the app will detect lots of Accelerometer shaking events and may crash!
Page 48
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
Mobile features
Working with graphics
Using timers in games
Plus, as an extension
Introduction
Your teacher will demonstrate a classic bat & ball game. This is the app that you are
about to create.
In this game, the bat will move continuously and the user will change its direction by
clicking the arrow buttons at the bottom of the screen. This makes the game quite
challenging, but more fun to play!
Did you know…? Wiff-Waff (also Whiff-Whaff) is the original name for table tennis and was a popular
“parlour game” in Victorian times. After dinner, wealthy Victorians would use boxes to
hit a golf ball back and forth across the dining table! The “net” was made by placing
books on their ends.
Table Tennis is now a popular game enjoyed by millions and has been an Olympic sport
since 1988.
Page 49
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
Hint: Set the Screen component’s background colour to Black at the very end.
It is easier to work with a white background as you assemble the components.
Label + properties…
Name LabelScore
Text [Blank]
Font 18, Bold, white text
Size Width: Fill parent
Height: Automatic
Canvas + properties…
Name CanvasGameArea
BkgdColor None
Size Width: Fill parent
Height: 315 pixels
Ball + properties…
Name Ball
Interval 10
PaintColor Red
Radius 15
Speed 7
ImageSprite (NOT Image)
Name ImageSpriteBat
Interval 10
Picture Bat.png
Speed 7
HorizontalArrangement with…
Button + properties…
Name ButtonLeft
Image ArrowLeft.gif
Text [Blank]
Button + properties…
Name ButtonStart
Font Bold, 16
Text Start!
Size Width: Fill parent
Height: Automatic
Button + properties…
Name ButtonRight
Image ArrowRight.gif
Text [Blank]
Sound + properties…
Name SoundLose
Source BeepLose.wav
Sound + properties…
Name SoundBeep
Source Beep.wav
Page 50
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
Algorithm
to Set Up Game (procedure)
set the score to 0
set the ball enabled to true (lets it move)
set the ball colour to green
set the ball’s coordinates to 150, 150
set the ball’s heading to a random number between 45 and 135 degrees
disable the start button
1
when ball reaches an edge (use Ball.EdgeReached block)
if edge = -1 (bottom of screen)
call Lose Game procedure Screen
3 -3
else sides
bounce ball off edge
play beep sound
-1
Contd/…
Page 51
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
7.1 a) The algorithm above has a bug which shows itself when you lose. What is
it?
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
7.2 Why do we test for a collision at the bottom of the screen in the if…else, rather
than the other sides?
__________________________________________________________________
__________________________________________________________________
Page 52
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
Algorithm
Moving bat (using Orientation Sensor)
if orientation sensor roll > 0 then (phone is tilted to the right)
set the bat heading to the right (0)
else (phone is tilted to the left)
set the bat heading to the left (180)
7.3 In what direction will the bat move if the phone’s tilt is zero (completely level)?
__________________________________________________________________
__________________________________________________________________
Why?
__________________________________________________________________
__________________________________________________________________
Page 53
I ♥ My Smartphone Lesson 7: Wiff-Waff Game
Page 54
I ♥ My Smartphone Summary
Summary
Computing Science concepts
In this course you have learned about some important ideas within Computing Science:
Computer software
o Operating system
o Apps
Event-driven programming
Algorithms
Variables
Procedures
Input validation
Virtual machines
Programming structures/commands
You have also used the following programming structures:
There are, of course, many more, but you now have the necessary tools to go on to the
next stage
Page 55
I ♥ My Smartphone Summary
You now have all the skills you need to create some really amazing mobile apps.
Page 56
I ♥ My Smartphone Mobile App Project
You may have some ideas already, but software is normally designed by going through a
series of stages:
1. Analyse
2. Design
3. Implement
4. Test
5. Document
6. Evaluate
7. Maintain
Let’s consider what each of these stages means within mobile app development.
Analyse
Identify a problem or need your app is going to address. Think about its possible users.
It’s often best to choose something that interests you or you care about.
Design
Design your app in two stages:
Implement
Create your app’s screen and components, then create the code that corresponds to
your algorithms.
Remember to comment your code so that it makes sense to other developers – and
you, when you come back to fix bugs or add new features next year!
10
Think about it!
Page 57
I ♥ My Smartphone Mobile App Project
Test
Test your app to make sure it works then give it to other users and note their comments.
Fix any bugs that are discovered.
Document
A desktop application comes with documentation – instructions on how to install and
use it.
However, a mobile app should need little or no documentation. Often the only
documentation is some simple instructions in the app itself or on its page on an app
store. You must therefore make your app as intuitive (obvious how to use) as possible.
An important part of documentation is ensuring that comments are included with code,
although this should be done during coding.
Evaluate
When you’ve finished the task, make an honest assessment of how you did. Some
questions that you might ask include:
This is a vital stage in development because it is only by answering these questions that
developers can improve their skills – and future apps.
Maintain
Maintenance is the process of updating your app. There are three main types of
maintenance:
Now let’s go through these stages to create your own mobile app!
Page 58
I ♥ My Smartphone Mobile App Project
Analyse
Working in pairs or small groups, brainstorm three ideas for your app.
As you do so, think about each app’s possible users and the need it’s going to fulfil.
Think of how it might also link in with other subject areas you’re studying.
1. __________________________________________________________________
__________________________________________________________________
__________________________________________________________________
2. __________________________________________________________________
__________________________________________________________________
__________________________________________________________________
3. __________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Once you have agreed on the app you are going to develop, write down a fuller
description of what it will do below. Include any mobile features it will use.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Page 59
I ♥ My Smartphone Mobile App Project
Design (Interface)
Make a sketch of your app’s interface.
Your sketch should be labelled to show what each component does.
Four screen layouts are provided to allow you to experiment (use in either portrait or
landscape).
Page 60
I ♥ My Smartphone Mobile App Project
Design (Code)
Design the algorithms for your code:
Think about the steps each component from your screen design will have to
perform. Write them in English.
Use procedures where appropriate.
Remember, whenever you have a clear “sub-task” in your app, you should create a
procedure to do this. This is especially true if you will use it more than once!
Page 61
I ♥ My Smartphone Mobile App Project
Implement
Now create your app!
Test
Test your app to make sure it works.
Let your classmates test it too and note their comments below:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Describe bugs that were found (by you or by testers) and how you fixed them:
Bug: ___________________________________________________________________
Solution: ________________________________________________________________
_______________________________________________________________________
Bug: ___________________________________________________________________
Solution: ________________________________________________________________
_______________________________________________________________________
Bug: ___________________________________________________________________
Solution: ________________________________________________________________
_______________________________________________________________________
Page 62
I ♥ My Smartphone Mobile App Project
Document
Let’s imagine that you’re going to sell your app on an app store.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Page 63
I ♥ My Smartphone Mobile App Project
Evaluate
How did the app turn out compared to how you originally planned it?
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
If you were to start again from the beginning, what would you do differently?
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Page 64
I ♥ My Smartphone Mobile App Project
Maintain
Now imagine that you have to adapt your app to make it work on a tablet computer.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Congratulations
You have now completed this Computing Science course in mobile app development!
Remember that you can use App Inventor at home, so there’s no need for this to be the
end of your time as a mobile app developer.
http://appinventor.mit.edu
Page 65