CIT020 Index > Objects

Text

In this assignment, you will add text to the game from a previous assignment that lets the player “pop” balloons by moving the mouse over them. This sketch will be named textgame.

The Changes

Suggestions

Formatting the Time

You can’t just say something like this:

int minutes = some calculation;
int seconds = some calculation;
String elapsedTime = minutes + ":" + seconds;

because, if the seconds is less than 10, you would end up with a string like 2:5 instead of 2:05. Here is a function named twoDigits() which takes an integer as a parameter and returns a two-digit string (as a String), and how you might use it in your program.

String twoDigits(int n)
{
  String result = "" + n; // converts integer to String
  if (n < 10)
  {
    result = "0" + result;
  }
  return result;
}
// how you use it:
int minutes = some calculation;
int seconds = some calculation;
String elapsedTime = minutes + ":"
  + twoDigits(seconds);

When You Finish

Zip up the sketch into a zip file named textgame.zip and upload it.

See what the result should look like.