For this assignment you will once again write a program to play the Tile Puzzle game,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this assignment you will once again write a program to play the Tile Puzzle game, but this time your program will interact with the player using Dialog Boxes (i.e. javax.swing.JOptionPane). Your program should not use System.out.print or the Scanner class at all. There should be no Console I/O for this program (none, nada, zilch). The only code that changes in this assignment, compared to the previous assignment, is the UI class. The actual playing of the game (in the TilePuzzle class) is identical to what you wrote before (don't write the same code twice!). As before, you must not change any of the class provided for the previous assignment (e.g., TilePuzzleDriver) As before, you should query the user for the size of the puzzle, which must be a value between 3 and 8. If the user enters garbage (e.g., "abc"), then your program should prompt the user again to enter a numeric value. If the user fails to do so after three attempts, then your program should throw an IllegalStateException. Your program should then query the user for the initial configuration of the puzzle. There are two possible choices. Either the initial puzzle is the "default" configuration, where the blank tile is in the upper-left corner and the tiles are arranged in order from left-to-right and top- to-bottom. Or the initial puzzle is randomly generated. You can use the shuffle method in the Collections class to randomly shuffle a List of numbers. The position of the Blank Tile in the original puzzle layout should be included in this randomization. As before, the goal configuration of the puzzle is to have the blank tile in the bottom- right corner, with the remaining tiles arranged in order from left-to-right and top-to-bottom. The default starting puzzle, and the solution for a 3x3 grid is illustrated below. 1 21 1 2 3 3 4 5 4 5 6 6 7 8 7 8 After displaying the initial tile puzzle, your program should prompt the user to enter the next move. You should use JOptionPane.showOptionDialog( ... ) to display a series of choices to the player (i.e., Left, Right, Up, Down and Quit). The user will click on their choice of move. Your program should only display options that are currently legal moves in the game. Unlike in the previous assignment, the user will only be able to specify a single move at a time. The program should then display the new configuration of the puzzle. If the user closes this dialog box (using the X in the top-right corner) then this should be considered as quitting the game. If the state of the puzzle reaches the goal configuration, then your program should display a "Congratulations" message and the number of moves used to reach the goal configurations, and then halt. If the user quits the game, then your program should display a "Good-bye" message, and halt. You can display a message to the player by using: JOptionPane.showMessageDialog(null, "Hello world"); You can get arbitrary String input from the user using: String input =JOptionPane.showInputDialog( "What is your input?”); You can give the user a limited number of choices using: String[] moveChoices = { "Left", "Right", "Up", "Down" }; int choice =JOptionPane.showOptionDialog( null, // No parent "What move do you want?", // Prompt message "Tile Puzzle Move", // Window title JOptionPane. YES_NO_CANCEL_OPTION, // Option type JOptionPane.QUESTION_MESSAGE, null, moveChoices, moveChoices[moveChoices.length - 1]); JOptionPane.showMessageDialog(null, "You chose: "+moveChoices [choice] ); // Message type // Icon // List of choices // Default choice Your program will need to import the Swing libraries by including: import javax.swing.JOptionPane; at the top of your program. To submit your work, upload a zipfile containing your UI.java file and also an executable jar file of your program to the Program 4 Assignment on Canvas. You should be sure to include YOUR NAME in a comment at the top of your source code file, for this and all other assignments in this course. Your source code must use proper style, i.e., variables should be well named (name is not too short, not too long, and is meaningful), and bodies of loops, if's, etc.. should be properly indented. Your program must show appropriate modularization into methods. In general, a method should not exceed one page. If it does, then break it up into smaller, helper methods. For this assignment you will once again write a program to play the Tile Puzzle game, but this time your program will interact with the player using Dialog Boxes (i.e. javax.swing.JOptionPane). Your program should not use System.out.print or the Scanner class at all. There should be no Console I/O for this program (none, nada, zilch). The only code that changes in this assignment, compared to the previous assignment, is the UI class. The actual playing of the game (in the TilePuzzle class) is identical to what you wrote before (don't write the same code twice!). As before, you must not change any of the class provided for the previous assignment (e.g., TilePuzzleDriver) As before, you should query the user for the size of the puzzle, which must be a value between 3 and 8. If the user enters garbage (e.g., "abc"), then your program should prompt the user again to enter a numeric value. If the user fails to do so after three attempts, then your program should throw an IllegalStateException. Your program should then query the user for the initial configuration of the puzzle. There are two possible choices. Either the initial puzzle is the "default" configuration, where the blank tile is in the upper-left corner and the tiles are arranged in order from left-to-right and top- to-bottom. Or the initial puzzle is randomly generated. You can use the shuffle method in the Collections class to randomly shuffle a List of numbers. The position of the Blank Tile in the original puzzle layout should be included in this randomization. As before, the goal configuration of the puzzle is to have the blank tile in the bottom- right corner, with the remaining tiles arranged in order from left-to-right and top-to-bottom. The default starting puzzle, and the solution for a 3x3 grid is illustrated below. 1 21 1 2 3 3 4 5 4 5 6 6 7 8 7 8 After displaying the initial tile puzzle, your program should prompt the user to enter the next move. You should use JOptionPane.showOptionDialog( ... ) to display a series of choices to the player (i.e., Left, Right, Up, Down and Quit). The user will click on their choice of move. Your program should only display options that are currently legal moves in the game. Unlike in the previous assignment, the user will only be able to specify a single move at a time. The program should then display the new configuration of the puzzle. If the user closes this dialog box (using the X in the top-right corner) then this should be considered as quitting the game. If the state of the puzzle reaches the goal configuration, then your program should display a "Congratulations" message and the number of moves used to reach the goal configurations, and then halt. If the user quits the game, then your program should display a "Good-bye" message, and halt. You can display a message to the player by using: JOptionPane.showMessageDialog(null, "Hello world"); You can get arbitrary String input from the user using: String input =JOptionPane.showInputDialog( "What is your input?”); You can give the user a limited number of choices using: String[] moveChoices = { "Left", "Right", "Up", "Down" }; int choice =JOptionPane.showOptionDialog( null, // No parent "What move do you want?", // Prompt message "Tile Puzzle Move", // Window title JOptionPane. YES_NO_CANCEL_OPTION, // Option type JOptionPane.QUESTION_MESSAGE, null, moveChoices, moveChoices[moveChoices.length - 1]); JOptionPane.showMessageDialog(null, "You chose: "+moveChoices [choice] ); // Message type // Icon // List of choices // Default choice Your program will need to import the Swing libraries by including: import javax.swing.JOptionPane; at the top of your program. To submit your work, upload a zipfile containing your UI.java file and also an executable jar file of your program to the Program 4 Assignment on Canvas. You should be sure to include YOUR NAME in a comment at the top of your source code file, for this and all other assignments in this course. Your source code must use proper style, i.e., variables should be well named (name is not too short, not too long, and is meaningful), and bodies of loops, if's, etc.. should be properly indented. Your program must show appropriate modularization into methods. In general, a method should not exceed one page. If it does, then break it up into smaller, helper methods.
Expert Answer:
Answer rating: 100% (QA)
Heres a possible implementation of the Tile Puzzle game using JOptionPane dialog boxes for user interaction java import javaxswingJOptionPane public c... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
You are to write a program to play the game Wheel of Fortune. If you are not familiar with the game, please watch this YouTube video: https://www.youtube.com/watch?v=OeX1rJ9Abr0. The game you are to...
-
Find the maximum volume of a box inscribed in the tetrahedron bounded by the coordinate planes and the plane 1 1 x+2y+12=1 3
-
A cognitive psychologist was interested in the ability of men and women to multitask-a cognitive skill thought to engage short-term or working memory. The psychologist observed a sample of 5 men (n =...
-
You are the Chief Information Officer for a startup FinTech (financial services/technology) company that currently has 12 employees and expects to grow to 50 employees by the end of the year. Form a...
-
Bernardino Santos-Rodiguez was piloting a boat owned by his friend, Raul Viera-Torres, in waters near Guayama, Puerto Rico. The boat was equipped with a hydraulic steering system manufactured by...
-
Before Gordon Corporation engages in the treasury stock transactions listed below, its general ledger reflects, among others, the following account balances (par value of its stock is $30 per share)....
-
What is operating leverage and how is it related to the cost structure of any organisation ?
-
For the given truss, the force in member 2 is 1000 N Aa- (A) 250 N (C) ON 2 3 B 000 IAL 2.5 a (B) 500 N (D) 125 N
-
physician care services is for sale and they have indicated to us that they would consider a cash sale to us at 1.5 times its current book value- A number we consider high. Should we consider this...
-
3. Consider a population which is given by the following function of t years: P(t) = 300+5t t, Ost6 a. Find the average rate of growth of the population over the first 3 years b. Find the...
-
Anne had health insurance for all of 2022 from Covered California. Which health insurance-related forms might she need to provide you to complete her return and reconcile any advance payments?
-
using separate demand and supply diagrams explain the effect on the price and quantity of smartphones if the price of music streaming subscription falls?
-
The expected rate of return on the common stock of Marvin Construction is 15 percent. The stock's dividend is expected to grow at a constant rate of 6 percent per year. The current market price of...
-
You work for a large restaurant chain that is controlled tightly by the corporate headquarters. The restaurant chain started with one restaurant which focused only on high-quality hamburgers and...
-
Without solving, determine the character of the solutions of each equation in the complex number system. 3x 2 3x + 4 = 0
-
Its possible (and actually common) to have several transaction records with the same record key. This situation occurs, for example, when a customer makes several purchases and cash payments during a...
-
Write an application that asks the user to enter two integers, obtains them from the user and prints the square of each, the sum of their squares, and the difference of the squares (first number...
-
Create a UsingGradients app that displays a Rectangle and enables the user to fill it with a radial or a linear gradient. The app should enable users to modify either gradient by specifying the RGBA...
-
Graph the following table: a. What is marginal product and average product at each level of production? b. Graph marginal product and average product. c. Label the areas of increasing marginal...
-
If average product is falling, what is happening to short-run average variable cost?
-
If marginal cost is increasing, what do we know about average cost?
Study smarter with the SolutionInn App