Intro to programming class student here, currently have to complete a slider puzzle program. I've been working on it a lot over the past few days and have a decent amount of code done I think. I have the picture loading into tiles, it recognizes mouse input and the location of each tile relative to one empty tile, and I have a scramble button with no functionality yet. IDK what to do from here though :( I need to get the program to do three things, swap a tile I click with the empty tile when they are adjacent, scramble the tiles using the scramble button, and have the program recognize when the puzzle is put together correctly.
final color BG = color(204);
final String IMAGE_FILE = "simpsons.jpg";
final int NROWS = 4, NCOLS = 5;
PImage fullImage;
int fullWidth, fullHeight;
int tileWidth, tileHeight;
Board board;
Button button;
void setup()
{
fullImage = loadImage(IMAGE_FILE);
fullWidth = fullImage.width;
fullHeight = fullImage.height;
size (fullWidth + (fullWidth / 2), fullHeight);
tileWidth = fullWidth / NCOLS;
tileHeight = fullHeight / NROWS;
board = new Board();
button = new Button();
}
void draw()
{
background(BG);
board.draw();
board.mouseClicked();
button.draw();
button.mouseClicked();
}
class Board
{
Tile[][] board;
int emptyX;
int emptyY;
Board()
{
initialize();
}
void initialize()
{
board = new Tile[NROWS][NCOLS];
for (int row = 0; row < NROWS; row++) {
for (int col = 0; col < NCOLS; col++) {
int x = xFromCol(col);
int y = yFromRow(row);
PImage tileImage = fullImage.get(x, y, tileWidth, tileHeight);