Domino Game.

Summary
Domino Game.
 Write a version of the Domino game.
Reflection.
 Write up your reflections on this assignment.
Overview
For this assignment, you will be completing a solitaire Dominoes game involving collections of dominoes.
There is one exercise to give you practice with arrays; the other exercise is closely related to the main program that you will write.Make sure that you do at least the second exercise before starting the domino game program.
To Submit:
You should submit your best version of DominoGame.java, using the Web-based submission system. Don't forget to complete the final step of the submission process after you have uploaded the files.
You may work in pairs for the Core and Completion parts, but if you do you must include a comment at the top of your program saying who you worked with. You must do the Challenge part on your own.
You are reminded of the School's policy on plagiarism - see the COMP102 Web site for details.
Preparation
Download the zip file for assignment 8 and extract it to your home folder. It should contain templates for the Java programs you are to complete. Read through the whole assignment to see what you need to do. You can run the demo programs on the ECS lab computers.
Domino Game
Dominoes are rectangular tiles that have two numbers on them, usually represented by patterns of dots (no dots represents 0). There are many games using dominoes, many of which involve a player pickup up a "hand" of dominoes, and then placing them on the "table" according to some rules.
The DominoGame program allows a player to play one of these games. The program displays the set of six dominoes in their hand, and the dominoes on the table. It allows the user to
Pick up a new domino to fill an empty space in the hand;
Select a domino in the hand (with the mouse)
"Flip" the selected domino
Place the selected domino on the table.
Rearrange the order of the dominoes on their hand;
The program has six buttons and also responds to the mouse.
The overall design of the DominoGame program is provided, along with declarations of all the fields and constants you need, and some of the code to respond to the buttons and mouse. You have to complete the definitions of the methods that do all the work!
A Domino class is also provided. It contains
a constructor for creating a new Domino,
a draw(double left, double top) method for drawing a Domino at a specified position, and
constants specifying the size of the dominoes.
getTop() and getBottom() methods for returning the top and bottom number of the domino
a flip() method to turn the domino over
Read through the provided code to make sure you know what it does.
Program Design
The program has two fields to keep track of the dominoes:
hand : an array that can hold up to 6 Dominoes. It will contain null in any position that does not have a Domino.
table : an ArrayList of the Dominoes that have been placed on the table.
The hand should be displayed with a rectangular border and each domino drawn in its place. Empty spaces (containing null) should be displayed as empty.
The user can select a position on the hand using the mouse. The selected position (domino or empty space) should be highlighted in some way, eg by drawing a border around it, or by drawing some marker underneath it. The index of the selected position is stored in theselectedPos field.
The user can use the Left or Right button to move the contents of the selected position one place to the left or the right (by swapping with the contents of the adjacent position).
If there are any empty positions on the hand, the user can use thePickup button to get a new (random) domino which will be added to the hand at the leftmost empty position. If there are no empty positions,Pickup should do nothing.
If the selected position contains a domino, the user can use the Placebutton to move the selected domino to the table.
The table is represented by an ArrayList of Domino objects, which are drawn in rows underneath the hand. At the beginning of the game the table should be empty. Dominoes should be added to the end of the table.
The following is a screenshot of the layout of the "hand" and the "table", showing a hand with five dominoes, and a "table" with 12 dominoes.
Core
Complete the Constructor so that it
initialises the hand and table fields
sets up the buttons, and the mouselistener
calls the restart() method
calls the redraw() method to redraw the hand and the table
Complete the restart() method so that it
sets the table field to be empty
sets the hand field to have no dominoes in it
Complete the pickup() method so that it
looks for an empty position in the hand array, and if there is one, creates a new Domino object and puts it at that position in the hand array.
Complete the drawHand() method so that it
draws the outline of the hand
draws each domino in the hand array
highlights the currently selected position, eg by drawing a coloured rectangle around it
Complete the placeDomino() method so that it moves the domino at the selected position in the hand (if there is one) to the table.
Complete the drawTable() method so that it
draws the dominoes on the "table", (For the core, it can draw them in one long row.)
Test your program carefully, to make sure that it works correctly in all cases:
when the hand is empty, when it is full, and when it is only part full.
when the selected position is at the ends and when it is not at the ends.
Completion
Complete the flipDomino() method so that it flips over the domino at the selected position in the hand (if there is one). (Hint: use the methods provided in the Domino class.)
Complete the moveLeft() and moveRight() methods so that they move the contents of the currently selected position on the hand to the left or the right, swapping the tile (or space) with the one next to it. (Note that they should not attempt to move something off either end of the hand.)
Complete the drawTable() method so that it can draw the dominoes on the table in multiple rows, so that they are all visible.
Complete the suggestDomino() method, which finds a domino in the users hand which can be placed into a position on the board. The program should tell the user both which domino can be placed and into which position. If there are multiple options it only needs to suggest one, if there are none it should inform the user that there are no possible moves.
Challenge
There are lots of ways in which this program could be improved or extended to encompass more of the game. Getting 100% for the program would require at least two of the following.
Enforce the rule that a domino can only be placed on the table if either the top number or the bottom number matches the corresponding number of the previous domino on the table. (The example diagram above satisfies this rule.) There are methods in the Domino class that you can use for helping with this.
Let the user move Dominoes around on the hand by dragging them with the mouse. If a Domino is dragged to another Domino, it should be inserted by moving the other Dominoes along. If a Domino is dragged to a space, it can simply be put in the space.
Represent a bag of dominoes from which the user can pickup new dominoes. It should initially contain exactly one of each type of domino. (You will need to make a new constructor for the Domino class.) Once the bag is empty, the user can't pick up any more dominoes for their hand.
Reflection
Answer the following questions in the Reflection.txt file, and make sure you submit it.
Did you do any online practice questions this week? If yes, which topics did you look at and why?
What is one error, bug, or exception that you encountered this week? How did you go about fixing it? Can you think of a way of making it easier to fix next time?
What is one thing that you did in this assignment that is similar to previous ones? Was it easier this time? How did you approach doing it?
If you have any other thoughts about the assignment please write them here.
Create a Visual Basic Utility program (Home Auditing)
Design, implement, test, and debug a Visual Basic® program to create a simple home utility auditing program.
The user should be able to do the following:
Enter the cost per kilowatt-hour.
Select a home appliance from a list of home appliances.
Enter the power needed in kilowatts (kW) for the selected appliance.
Enter the number of hours used per day for the selected appliance.
The program should do the following:
Validate that the data entered has the correct format and is within a reasonable range.
Calculate and display the cost for operating a home appliance as soon as the data is entered
Powered by