Lab 4 - Counting Rooms (continued)

This lab is not for marks. However, you are strongly encouraged to complete this lab as it provides you with an opportunity to develop your skills. You do not submit your solution, but teaching assistants can provide feedback during the lab.

For this lab you will be programming a mobile app that controls a robot that has been dropped into a grid of square rooms. Each wall of each room has been painted a different colour: the North wall is Neon, the East wall is Eggplant, the South wall is Sandy, and the West wall is Wallnut. The robot uses these colours to orient itself. Walls between rooms have doors in them, but walls on the edge do not. The goal of the robot is to determine how many rooms are in the grid.

Iteration 3

View

At the top, add a label (TextView) with the text "Number of rooms", a box to enter a number (TextEdit) and a button (Button) with the text "submit".

Controller

Add a method to the controller which is linked to the submit button (hint: onclick). This method should extract the value entered into the box (see Lab 1 how this can be done). It should also check whether the number of rooms entered in the box is correct. You may assume that you will always find a number in the box. If the number is correct, then the colour of the counter should be changed to green. Otherwise, the colour of the counter should be changed to red.

Test

Deploy your app on a tablet and test it. Only once it produces the desired behaviour, move on to the next iteration.

Iteration 4

Model

Attributes

Change the attributes WIDTH and HEIGHT to the attributes width and height.

Constructor

Initialize the new attributes width and height each to a random number in the interval [1, 10]. To do this create a Random object (the Random API can be found here) and use the nextInt(int) method. Initialize the initial position of the robot to a random room in the grid. Use the Random object you created earlier.

Test

Deploy your app on a tablet and test it.

Iteration 5

Controller

Remove the colours of the buttons North, South, West and East. Whenever the robot hits a wall (for example, the North button is pressed but the robot cannot go North) make the tablet vibrate.

Test

Deploy your app on a tablet and test it.

Iteration 6

Keep track of the number of times that the robot has run into a wall. Use this number to produce a score once the number of rooms has been entered and the submit button has been pressed.

Iteration 7

Instead of random rectangular grids of rooms, randomly generate other shapes (for example, an L shape).

Iteration 8

Add to the view a graphical representation of the rooms that the robot has visited. You may colour the room in which the robot currently resides a different colour. You may also want to use colours to show into which walls the robot has run.

Credits

This lab is based on the nifty assignment designed by Luther A. Tychonievich, Mark S. Sherriff, and Ryan M. Layer which can be found here.