Write a version of the domino game

Assignment Help C/C++ Programming
Reference no: EM131065464

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.

Reference no: EM131065464

Questions Cloud

Describe the steps you would take to control heat stress : The workers at the site are required to wear semi-impermeable clothing, nitrile gloves, hard hat, safety boots, and an air purifying respirator. Describe the steps you would take to control heat stress at this site.
Write a program that lets the user enter the total rainfall : Write a program that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should use two 12-element arrays. One array will hold strings, the names of the 12 months. This array will be initialized when ..
Compare and contrast two african-american musicians : Compare and contrast two African-American musicians from different time periods. In your conclusion, state who is the better musician and why. Cite sources in-text and on References page.
Probability that in any hour exactly six complaits : What is the probability that fewer than 5 minutes will elapse between successive complaints?
Write a version of the domino game : 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.
What types of clouds produced most of observed precipitation : How does the air pressure during rainy days compare with that on days with mostly clear, sunny skies? What types of clouds produced most of the observed precipitation?
Find an article that you disagree with rebuttal argument : Remember to look at the use of evidence: examples, stats, analogy, cause/effect, comparison, definition, anecdote, etc. How can (or can they) be disputed? Do you have stronger evidence to refute the author's claim?
-what is the probability that demand will exceed 1000 pounds : -What is the probability that demand will exceed 1000 pounds?
What is the probability that at least one line stalls : What is the probability that at least one line stalls at least once in any given week?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that asks you to enter your height in inches

Write a program that asks you to enter your height in inches and then displays your height in centimeters. Or, if you prefer, ask for the height in centimeters and convert that to inches.

  Create a graphical (not text-based) visual c++ program

Create a graphical (not text-based) Visual C++ program that allows the user to enter the coefficients for a system of four equations with four unknowns. Include a button that when clicked, will solve the system of equations and display the results in..

  Implementation of the class integer

Implementation of the class Integer, Implementation of the Array class The class will handle an array of objects of class Integer.

  Create a bar chart showing the average monthly mean temperat

Write a ++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013. The point of the exercise is to compute the sie and location of the rectangles rather than explicitely hardcode that informat..

  Write a program in c to implement bubble sort

Write a program in c to implement bubble sort?

  Omaha foods manufacturescorn meal in a continuous

Omaha Foods manufacturescorn meal in a continuous, mass production process. Corn is added at the beginningof the process. Normal losses are minimal and abnormal losses infrequentlyoccur when foreign materials are found in the corn meal. Routine inspe..

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  Design a grade average program

Grade Average Program - Design a grade average program that will produce the numerical grade average of test scores input by a user

  Create a program that draws a two-dimensional house

Create a program that draws a two-dimensional house seen from the front, the way a child would see it: with a door, two windows, and a roof with a chimney

  Write a function that permanently swaps two floats

Write a function that permanently swaps two floats using references.

  Develop a program that calculates monthly payments for loan

Home Loan Amortization Develop and test a program that calculates the monthly payments for a loan amount and a term (number of years) input by the user.

  Find the prime numbers

Write a c++ program to find the prime numbers

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd