ckle the problem JAVA FXML Replace the Model of the tile puzzle game with a "stub" for the Model of the concentration game. This stub only needs to specify the size of the game grid at this point (that's why it's called a stub—there's not much functionality yet.) Get the program to display a 4 x 6 blank grid. Hints:- on what to do Need to replace the Model in the starter code with a model that provides logic for the concentration game. It is recommend to keep the same basic methods as the original model, except that you should replace getSide() with getRows() and getColumns() methods. *-------------------------------* package model; import java.util.ArrayList;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Tackle the problem JAVA FXML

  1. Replace the Model of the tile puzzle game with a "stub" for the Model of the concentration game. This stub only needs to specify the size of the game grid at this point (that's why it's called a stub—there's not much functionality yet.) Get the program to display a 4 x 6 blank grid.

Hints:- on what to do

Need to replace the Model in the starter code with a model that provides logic for the concentration game. It is recommend to keep the same basic methods as the original model, except that you should replace getSide() with getRows() and getColumns() methods.

*-------------------------------*

package model;

import java.util.ArrayList;
import java.util.Random;

public class TilePuzzle
{
private String [ ][ ] tiles;
private int side; // grid size
private int emptyRow;
private int emptyCol;
private Random randGen;
private int row;
private int column;
/** constructor
* @param newSide grid size
*/
public TilePuzzle( int newSide )
{
randGen = new Random();   
setUpGame( newSide );
}
  
/** setUpGame
* @param newSide grid size
*/
public void setUpGame( int newSide )
{
if ( newSide < 3 )
side =3;
else
side = newSide;
tiles = new String[side][side];
  
ArrayList<String> textList = new ArrayList<>();
for ( int i = 0; i < side*side; i+=1 )
textList.add(String.valueOf(i));
textList.add( "" );
  
// initialize tiles
for ( int i = 0; i < side; i++ )
{
for ( int j = 0; j < side; j++ )
{
tiles[i][j] = textList.remove(randGen.nextInt(textList.size()));
if(tiles[i][j].equals(""))
{
emptyRow = i;
emptyCol = j;
}
  
}
}
  
}
  
/** getSide
* @return side
*/
public int getSide( )
{
return side;
}
  
/** getTiles
* @return a copy of tiles
*/
public String[ ][ ] getTiles( )
{
String[ ][ ] copyOfTiles = new String[side][side];
  
for ( int i = 0; i < side; i++ )
{
for ( int j = 0; j < side; j++ )
{
copyOfTiles[i][j] = tiles[i][j];
}
}
return copyOfTiles;
}
  
/** tryToPlay
* enable play if play is legal
* @return true if the play is legal, false otherwise
*/
public boolean tryToPlay( int row, int col )
{
if ( possibleToPlay( row, col ) )
{
// play: switch empty String and tile label at row, col
tiles[emptyRow][emptyCol] = tiles[row][col];
tiles[row][col] = "";
// update emptyRow and emptyCol
emptyRow = row;
emptyCol = col;
return true;
}
else
return false;
}
  
/** possibleToPlay
* @return true if the play is legal, false otherwise
*/
public boolean possibleToPlay( int row, int col )
{
if ( ( col == emptyCol && Math.abs( row - emptyRow ) == 1 )
|| ( row == emptyRow && Math.abs( col - emptyCol ) == 1 ) )
return true;
else
return false;
}
  
/** won
* @return true if the tiles are all at the right place, false
*/
public boolean won( )
{
for ( int i = 0; i < side ; i++ )
{
for ( int j = 0; j < side; j++ )
{
if ( !( tiles[i][j].equals(
String.valueOf( i * side + j + 1 ) ) )
&& ( i != side - 1 || j != side - 1 ) )
return false;
}
}
return true;
}

}

Just need to fix the class to display a empty gridPane

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY