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

  Represents the nth fibonacci number

Prove by induction that the number of nodes in the activation tree for the Fibonacci function is 2F(n + 1) - 1.

  Write a recursive method to print all the permutations

Write a recursive method to print all the permutations of a string.

  Define a class that consists of three objects

Define a class that consists of three objects: day, month, and year. Within this class define two member function (constructor ) to initialize the objects to today?s date and one that display the date as follows: 05/7/2002

  Calculates how much money you''ll end up

Write a C program that calculates how much money you'll end up with if you invest an amount of money at a fixed interest rate, compounded yearly.

  Program that will input any four float values

You need to prepare a program to print the given output - write a program that will input any four float values where the four variables are declared in the 'main' function and perform

  Program that prompts the user to enter a test score

Write a complete C++ program that prompts the user to enter a test score. The test score must be greater than or equal to 0 and less than or equal to 100.

  Class arrayprogram that generates an array of fifty integers

If the user does enter an integer, call a method named returnIndexValue to return the integer at the specified index in the array

  Design a java software system that simulates

Design a java software system that simulates a calculator that performs at least the basic arithmetic operation and trigonometric functions. Your program must contain selection (if), repetition (loop) and functions, arrays and classes

  Create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  Calculate and prints the average of the ratings

Write a C program that accepts by keyboard input (8) user-ratings of the Galaxy S5. The ratings use a scale of 1 to 10, where 10 represents a high rating and 1 represent a low rating: Calculate and prints the average of the ratings

  Selection and repetition concepts

Use Selection and Repetition Concepts for this problem. A parts inventory record contains the following fields:

  Declare the variables mark and grade to be of type int and c

Use the grading system for a school to determine which grade the student is worth receiving depending on their mark score.

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