Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91789847
  • Price:- $35

Priced at Now at $35, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As