# Lab 2 – Layouts and Event Handlers, Pig Game v1

\$30.00

Category:

## Description

Purpose: This lab is designed to give you practice:

• Using Layouts: Relative, Vertical and Horizontal,

• Accommodating orientations: landscape and portrait
• Handling events

Part 1: Do the textbook exercises shown below. Note that for many of these, there is a starter project in the source code provided by the publisher of the textbook.

• 4-1, Test and debug the Tip Calculator app

Upload a text file to Canvas in which you will report, for each exercise above, whether you:

1. Followed all the steps shown in the book and successfully compiled and ran the program (where applicable).
2. Loaded the completed solution, experimented with the code, and ran the program (where applicable).
3. Read through the steps and inspected the relevant code listings without writing or running a program.
4. Didn’t do any of the above.

Part 2: Create an app for playing the game of “Pig”. Pig is a dice game with 2 players. Players roll one die as many times as they wish or until they roll a 1. Their score for the turn is the sum of their rolls unless they get a 1, then it’s zero. Players keep taking turns rolling until someone gets to 100. If the player who had the first roll reaches 100, the second player may still take their turn (so that both players get the same number of turns). The player with the highest score wins.

You can see an example of an online pig game here:

http://cs.gettysburg.edu/projects/pig/piggame.html

The UI for your game should be similar to the one shown below:

• Images are provided for the six sides of the die.

• Arrange the widgets using a relative layout, or a vertical linear layout with nested horizontal and vertical linear layouts. You can set the orientation to be portrait only in the manifest.

• Use the names entered in the editable text views for Player 1 and Player 2 to display the name of the player whose turn it is.
• Put the pig game logic in it’s own class.

• Optional: Use a Frame Layout to hold a background image for the app (provide your own image).

Zip the project and upload it to Canvas.

error: Content is protected !!