Java
import java.util.ArrayList; import java.util.Collections; /** * The mind game board containing n by n tiles. * * @author musfiqrahman */ public class Board { private Tile[] gameBoard; // Mind Game board of Tiles private int size; // Number of Tiles on board private int rowLength; // Number of Tiles printed in a row private int numberOfTileFaceUp; // Number of Tiles face-up private FixdLenStringList possibleTileValues; // Possible Tile values /** * Constructs n by n mind game board of Tiles whose image values are chosen * from the already filled FixdLenStringList. Precondition: n is the length * of a side of the board, n is an even positive integer. FixdLenStringList * contains at least n * n / 2 strings. * * @param n is length of the side of the mind game board (an even number) * @param list the FixdLenStringList from which the values for the tiles are * chosen */ public Board(int n, FixdLenStringList list) { // your code goes here } /** * Randomly fills this Mind Game Board with tiles. The number of distinct * tiles used on the board is size/2. Any one tile image appears exactly * twice. Precondition: number of position on board is even, * FixdLenStringList contains at least size / 2 elements. */ private void fillBoard() { // Your code goes here // You may find Collections.shuffle() class useful. } /** * Precondition: 0 <= p < gameBoard.length. Precondition: Tile in position p * is face-down. Postcondition: After execution, Tile in position p is * face-up @param p the index of the tile to turn face-up */ public void lookAtTile(int p) { // Your code goes here } /** * Checks whether the Tiles in pos1 and pos2 have the same image. If they * do, the Tiles are turned face-up. If not, the Tiles are turned face-down. * Precondition: gameBoard[pos1] is face-up, gameBoard[pos2] is face-up * * @param pos1 index in gameBoard, 0 <= pos1 < gameBoard. length @param pos2 * index in gameBoard, 0 <= pos1 < gameBoard. length */ public void checkMatch(int pos1, int pos2) { // Your code goes here } /** * Board is printed for the Player. If the Tile is turned face-up, the image * is printed. If the Tile is turned face-down, the Tile position is * printed. */ public void printBoard() { final int PADDING = 3; int spacing = possibleTileValues.getStringLength() + PADDING; for (int i = 0; i < size; i++) { // Your code goes here } } /** * Returns Tile in position pos. Precondition: 0 <= pos < gameBoard.length. * @param pos * * is index in gameBoard * @return tile in position pos, null otherwise */ public Tile pickTile(int pos) { if (pos < 0 || pos >= gameBoard.length) { return null; } return gameBoard[pos]; } /** * Right-justifies a number to a given number of places. * * @param number an integer to be formatted * @param p total number of characters in returned string * @return right-justified number with p places as a string */ private String format(int number, int p) { String str = String.format("%1$" + p + "s", (number + "")); return str; } /** * Right-justifies a string to a given number of places. * * @param word a string to be formatted * @param p total number of characters in returned string * @return right-justified word with p places as a string */ private String format(String word, int p) { String str = String.format("%1$" + p + "s", word); return str; } /** * Checks whether all tiles are face-up. * * @return true if all tiles are face-up; false otherwise */ public boolean allTilesUp() { // Your code goes here } }