1 working on the gamebegin with your working code from

Assignment Help Computer Engineering
Reference no: EM13370084

(1) Working On the Game:

Begin with your working code from assignment #5. Complete the game so that the following happens:

1. Add a private score integer attribute to the ShinyButtons model class. Create a getScore() method that returns the score.

2. When the user presses the New Game button, the score resets to zero and the game pieces are reset to a different set of random colors again.

3. When the user presses the Quit button, the application stops and the window closes.

4. When there is currently no selected game piece and then the user clicks on a game piece, that game piece's JButton becomes the "selectedButton". Each JButton can have two ImageIcons assigned to it: (1) the regular icon, and (2) the selected icon:

1048_Shiny Buttons game.png

At this point, we have only used regular icons. You can also set a selected Icon for each JButton (i.e., a different image) by doing this: (aJButton.setSelectedIcon(new ImageIcon("..."));. This just has to be set once, when you create the JButtons. Add the following array to your code and make sure that you download the additional 7 selected icon images (shown above). Use the array to set the appropriate selected icon for each JButton according to its current color.

public static ImageIcon[] selectedIcons = {
new ImageIcon("SelectedRedButton.png"),
new ImageIcon("SelectedOrangeButton.png"),
new ImageIcon("SelectedYellowButton.png"),
new ImageIcon("SelectedGreenButton.png"),
new ImageIcon("SelectedBlueButton.png"),
new ImageIcon("SelectedLightGrayButton.png"),
new ImageIcon("SelectedDarkGrayButton.png")
};

Adjust your code so that all JButtons are NOT selected except for the selectedButton, which should be selected. You can set aJButton to be selected by saying: aJButton.setSelected(true); JAVA will then show the appropriate image icon automatically. As a result, the background of the button image should be colored in to a non-white color.

5. Adjust your code so that when the user has already selected a game piece, and then an adjacent game piece is selected that lies beside (i.e., to its immediate left, right, up or down position) the selected game piece (i.e., the selectedButton) then this piece should swap positions with the selectedButton's piece. Note that you should NOT swap JButtons ... just game pieces. However, you WILL need to ensure that the JButtons' regular and selected icons are properly swapped also. Just create an appropriate method in the ShinyButtons model class to swap two game pieces when given their rows and columns ... then update() the GUI accordingly. Once the swap is made, the selectedButton should be set to null so that no JButtons are selected anymore. You should see the swap happen visually on the window. If the game piece that was pressed was NOT beside the selectedButton's piece, then no swap is made and the selectedButton should be set to null, so that no buttons remain selected.

6. Adjust your code so that it automatically highlights any horizontal or vertical sequences of 3 or more game pieces if they are the same color.

981_Shiny Buttons game1.png

In order to determine which game pieces to highlight (i.e., to select), you will need to write some code in the ShinyButtons class. Create the following attribute: private boolean[][] selectionTable; Create a method in the ShinyButtons class called processTable() which resets the selectionTable to have all false values and then checks all rows for sequences of same color pieces and then checks the columns for sequences of same color pieces. Here is some pseudocode for checking the rows:

FOR each row r FROM 0 TO 7 DO {
set matches to 0
FOR each column c FROM 1 TO 7 DO {
IF (piece at (r, c) has same color as piece at (r, c-1)) THEN {
increase matches by 1
IF (matches >= 2) THEN
Select all three pieces at row r from column c-2 to column c.
}
ELSE set matches to 0
}
}

Do something similar for the columns. Make sure that whenever a new game is started, then the processTable() method is called. Also, make sure that it is called whenever two pieces' positions are swapped (from step 5).

(2) Completing Game:

Now it is time to complete the game

1. Write a public void cleanTable() method in the ShinyGame class that causes all selected sequences of game pieces to be removed from the game board. As a piece is removed from a row, all game pieces above it will drop down one row and a new game piece will appear at the top row of the board (within the same column that the removed piece was taken away). The method should work from the bottom row upwards and look for selected pieces to remove. Here is the pseudocode:

set newPieceAdded to FALSE
set r = 7
WHILE (r >= 0) DO {
newPieceAdded = FALSE
FOR each column c FROM 0 TO 7 DO {
IF (piece at (r, c) is selected) THEN {
// move the pieces down now ...
FOR each row r2 FROM r TO 1 DO {
selection of piece at (r2, c) = selection of piece at (r2-1, c)
piece at (r2, c) = piece at (r2-1, c);
}
// Add a new piece
set the piece color for piece at (0, c) to a valid random color index
unselect piece at (0, c)
set newPieceAdded to TRUE
}
}
IF (newPieceAdded is FALSE) THEN
decrease r by 1
}

To test this, add a private Timer timer; attribute to the ShinyButtonsApp. Add the following
Timer and its event handler within the constructor:

timer = new Timer(500,new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Write code here to clean the table, process it, and then update
}});
timer.start(); // This line starts the timer which will happen every 0.5 seconds

2. Finally, we need to work at getting the game to keep score. To record the score, you will need to update your processTable() method so that whenever the number of matches is 2 or more, you update the score. Make sure to update the score for both rows and columns, separately. Each time you find a sequence of 3 or more similar colored buttons, you will update the score as follows (where S is the size of the sequence):

2002_Shiny Buttons game2.png

So, for example, here is the increase in score that should occur depending on the sequence size:

528_Shiny Buttons game3.png

Make sure to test your code carefully. However, it will be hard to test sequences of 6, 7 or 8 ... these can only occur my chance if new buttons are added to a row/column which happen to match the others in the row. However, you should be able to test sequences of size 3, 4 or 5. Please note, though, that this game never ends ... so the score will increase until the user quits.

Keep in mind that nothing special needs to happen with horizontal and vertical sequences that cross. For example, in the picture above you will notice a yellow vertical sequence of 4 and two horizontal sequences of 3.

Reference no: EM13370084

Questions Cloud

Abc organization unadjusted trial balance as of 31 december : abc organization unadjusted trial balance as of 31 december 2012account codes dr cr cash 10789furniture and fixtures
Question 1explain why maximizing the current value of a : question 1explain why maximizing the current value of a firms stock is or is not the az1-z- management.question 2how is
Q a company has started a phone service that uses overseas : q. a company has started a phone service that uses overseas doctors to provide emergency medical consultations.
1 recursive sorts are easier to write in functional style : 1 recursive sorts are easier to write in functional style than others. two recursive sorts are quicksort and mergesort.
1 working on the gamebegin with your working code from : 1 working on the gamebegin with your working code from assignment 5. complete the game so that the following happens1.
1what is opportunity cost explain with the help of an : 1.what is opportunity cost? explain with the help of an example why assumption of constant opportunity cost is very
Database systems1 list the acid properties explain the : database systems1. list the acid properties. explain the usefulness of each.2. consider the following two transactions
It inventory database given a school system database with : it inventory database given a school system database with over 2000 computers 100 elmos 200 smartboards 200 projectors
Policy brief medicaid expansionassume you are working in : policy brief medicaid expansionassume you are working in the governors office of lsquoyour state. you have now been

Reviews

Write a Review

Computer Engineering Questions & Answers

  Benefits of ansi/tia/eia cabling standards

Discuss about the benefits of the ANSI/TIA/EIA cabling standards in detail and also explain why telecommunications managers must be familiar with them.

  Modify java application that displays the product number

make a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit).

  Provide a java class named "input"

Provide a Java class named "Input" containing the method "readInt" (prototype given below) that displays the prompt string, reads an integer, and tests either it is between the supplied minimum and maximum. If not, it prints an error message and r..

  Program on different statements

Program on different statements

  Monitoring of patient vital signs using mobile computing

Compare and contrast the monitoring of patient vital signs utilizing the mobile computing technology to in-patient visits to the doctor’s office or hospital.

  Questionfind nearby pair and most-distant pair from a given

questionfind nearby pair and most-distant pair from a given point.produce two random integer numbers between 1 and 200.

  Opening the "create and manage publications"

This project would challenge you to set up replication on your SQL Server installation. Every step to complete this process is not laid out for you here. Complete the steps and document your choices throughout the process with screen shots and exp..

  Describing the microsoft access

Describe what is going on within the Microsoft Access. What role do you think SQL is playing?

  Companies sometimes purchase expensive applications

Companies sometimes purchase expensive applications, and after that under-utilize or misuse these. In a sense, the economic downturn has been beneficial, as many companies are beginning to more regularly scrutinize the programs they are investing i..

  Write a report on how to used them

For several of the commands, you require to practice them on some files.

  New core of modern business

Evaluate the concept that IT is becoming the new core of modern business. How might you justify or negate this assertion? Offer your informed opinion on how a company's use of IT might be used as an indicator of its overall success.

  What represent the length and width of a room in feet

build a Java class that declares variables to represent the length and width of a room in feet. Assign appropriate values to the variables. calculate and display the floor spae of th eroom in square feet (area = length * width). Display explnatory ..

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