Tackle 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...



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 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

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here