Instructor:
Nelly Fazio
Back to class webpage
[ Introduction | Design Guidelines | Collaboration Policy | Hand-in Procedure]
In the Count MIDlet that is bundled in
the EmulatorDemo, the switches are programmed to light up the
LEDs in a binary pattern and/or change their color. In this lab, you
will program the right switch SW2 to cycle through the three
possible selections (Rock, Paper, or Scissors), and the left
switch SW1 to confirm the selection and reveal the SPOT's own
move.
More specifically, the three rightmost LEDs (L5, L6
and L7) shall display the user selection, while the three
leftmost LEDs (L0, L1 and L2) shall display the
computer selection. The two central LEDs (L3 and L4)
will be used to display the winner.
We will use different colors to display the user's and the SPOT's
selections: green for the user LEDs and
red for the SPOT's.
Here is a pictorial representation of how to light the LEDs to display
the computer and the user selection.
The two central LEDs shall be solid blue while the user makes his/her choice, and turn to flushing green, red, or blue depending on whether the user won, lost, or tied the game. The initial LEDs configuration is depicted below:
The user goes first, and uses switch SW2 to make his/her choice: one click for Rock, two clicks for Paper, and three clicks for Scissors. Further clicks shall cycle back through Rock, Paper, etc. When the user confirms his/her selection by pressing the SW1 switch, the SPOT reveals its own choice in its LEDs (more details on this below). Next, the Rock-Paper-Scissors rules are applied to declare the winner. Here is a pictorial representation of the rules of the game:

The two middle switches (L3 and L4) will then blink for five times, in green if the user won; in red if the user lost, and in blue if there is no winner (the SPOT and the user made the same selection):
After blinking five times, the LEDs return to their initial configuration, ready for a new game:
How to implement the SPOT's selection
When the user confirms his/her choice by pressing the
switch SW1, it's time for the SPOT to make its own
selection. You should implement a random strategy, that returns a
number between 0 and 2 chosen uniformly at random (Rock=0,
Paper=1 and Scissors=2). To this aim, you can use the
random()
method of the
Math
class of the Java platform.
The random() method returns a double value with a
positive sign, greater than or equal to 0.0 and less than
1.0. Returned values are chosen pseudorandomly with (approximately)
uniform distribution from that range. A way to turn the result
of random() into an integer between 0 and 2 is:
(int) (Math.random() * 3)
You must write all the code you hand in for the programming
assignments, except for code that is part of
the EmulatorDemo. You are not allowed to look at anyone
else's solution. You may discuss the assignments with other students,
but you may not look at or copy each others' code.
To turn in your lab, e-mail your Rock-Paper-Scissors MIDLet
application as a .zip file (your.name-lab1.zip) at
Copyright © Nelly Fazio