Need serious assistance with slider puzzle final project
in
Programming Questions
•
10 months ago
Hello everybody, I'm new to these forums and came here in search of help for my project which was due last night. The final project goal was to create a simple slider puzzle game ( puzzle in which the image is scrambled using an image broken up into pieces, with one piece missing to anable movement of tiles) and I just do not know what else to do. Im pretty far along considering other students from this class used these forums so that definitely helped, but the threads don't help me much more. I have the image dividied up and know I need to know more on how to utilize the array, I don't know how to make it so adjecent pieces know when the can and can't move, and how to scramble it from the beginning, how to reset it, and how it knows when its complete. It's all very overwhelming. Please Help!!!!!
It uses multiple tabs, so here it starts at the puzzle tab. The puzzle is on top and the original to look at is below it, followed by a spot for a scramble and a reset button. AHHH I'm still not very good at this so simple terms for describg things would be GREAT.
http://www.ign.com/wikis/grand-theft-auto-5/GTA_V_Week_on_IGN not sure if its all debugged to use any image so in case you want to use same one, its the pic right at the top of the article.
final color BG = color(204);
final String IMAGE_FILE = "pics/GTA5.jpg";
final int NROWS = 3, NCOLS = 4;
PImage fullImage;
PImage origImage;
int fullWidth, fullHeight;
int tileWidth, tileHeight;
Board board;
Button button;
PImage origImage;
int fullWidth, fullHeight;
int tileWidth, tileHeight;
Board board;
Button button;
void setup()
{
fullImage = loadImage(IMAGE_FILE);
origImage = loadImage(IMAGE_FILE);
fullWidth = fullImage.width;
fullHeight = fullImage.height;
size(fullWidth, ((fullHeight * 2)+ 50));
tileWidth = fullWidth / NCOLS;
tileHeight = fullHeight / NROWS;
board = new Board();
button = new Button();
}
{
fullImage = loadImage(IMAGE_FILE);
origImage = loadImage(IMAGE_FILE);
fullWidth = fullImage.width;
fullHeight = fullImage.height;
size(fullWidth, ((fullHeight * 2)+ 50));
tileWidth = fullWidth / NCOLS;
tileHeight = fullHeight / NROWS;
board = new Board();
button = new Button();
}
void draw()
{
background(BG);
board.draw();
board.mouseClicked();
button.draw();
button.mouseClicked();
image(origImage, 0, fullHeight);
}
{
background(BG);
board.draw();
board.mouseClicked();
button.draw();
button.mouseClicked();
image(origImage, 0, fullHeight);
}
_____________________________________________________________
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);
board[row][col] = new Tile(tileImage, row, col);
}
}
board[NROWS - 1][NCOLS - 1].img = null;
emptyX = NCOLS - 1;
emptyY = NROWS - 1;
}
int xFromCol(int col){
return col * tileWidth;
}
int yFromRow(int row){
return row * tileHeight;
}
int colFromMouseX(){
return mouseX / tileWidth;
}
int rowFromMouseY(){
return mouseY / tileHeight;
}
void mouseClicked()
{
if (mousePressed) {
if (mouseButton == LEFT) {
if((colFromMouseX() == emptyX - 1) && (rowFromMouseY() == emptyY))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX + 1) && (rowFromMouseY() == emptyY))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX) && (rowFromMouseY() == emptyY - 1))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX) && (rowFromMouseY() == emptyY + 1))
println(colFromMouseX() + ", " + rowFromMouseY());
}
}
}
{
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);
board[row][col] = new Tile(tileImage, row, col);
}
}
board[NROWS - 1][NCOLS - 1].img = null;
emptyX = NCOLS - 1;
emptyY = NROWS - 1;
}
int xFromCol(int col){
return col * tileWidth;
}
int yFromRow(int row){
return row * tileHeight;
}
int colFromMouseX(){
return mouseX / tileWidth;
}
int rowFromMouseY(){
return mouseY / tileHeight;
}
void mouseClicked()
{
if (mousePressed) {
if (mouseButton == LEFT) {
if((colFromMouseX() == emptyX - 1) && (rowFromMouseY() == emptyY))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX + 1) && (rowFromMouseY() == emptyY))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX) && (rowFromMouseY() == emptyY - 1))
println(colFromMouseX() + ", " + rowFromMouseY());
}
{
if((colFromMouseX() == emptyX) && (rowFromMouseY() == emptyY + 1))
println(colFromMouseX() + ", " + rowFromMouseY());
}
}
}
void draw()
{
for (int row = 0; row < NROWS; row++) {
int y = yFromRow(row);
for (int col = 0; col < NCOLS; col++) {
int x = xFromCol(col);
PImage tileImage = board[row][col].img;
if (tileImage != null)
image(tileImage, x, y);
line(x, 0, x, fullHeight - 3);
}
line(0, y, fullWidth, y);
}
line(fullWidth - 1, 0, fullWidth - 1, fullHeight);
line(0, fullHeight - 1, fullWidth, fullHeight - 1);
}
}
//_______________________________________________________________
class Button
{
void draw()
{
final color RECTANGLE = color(100);
fill(RECTANGLE);
stroke(0);
rect(0, fullHeight * 2, fullWidth / 2, 50);
final color SCRAMBLE = color(0);
textSize(30);
fill(SCRAMBLE);
text("Scramble", fullWidth + 1, fullHeight / 2 + 10);
}
void mouseClicked()
{
if (mousePressed) {
if (mouseButton == LEFT) {
if (mouseY > fullHeight * 2 && mouseX < fullWidth / 2)
println("Scramble");
}
}
}
}
{
void draw()
{
final color RECTANGLE = color(100);
fill(RECTANGLE);
stroke(0);
rect(0, fullHeight * 2, fullWidth / 2, 50);
final color SCRAMBLE = color(0);
textSize(30);
fill(SCRAMBLE);
text("Scramble", fullWidth + 1, fullHeight / 2 + 10);
}
void mouseClicked()
{
if (mousePressed) {
if (mouseButton == LEFT) {
if (mouseY > fullHeight * 2 && mouseX < fullWidth / 2)
println("Scramble");
}
}
}
}
//_____________________________________________________________________________
class Tile
{
PImage img;
int initRow, initCol;
Tile(PImage img, int iRow, int iCol)
{
this.img = img;
this.initRow = iRow;
this.initCol = iCol;
}
}
{
PImage img;
int initRow, initCol;
Tile(PImage img, int iRow, int iCol)
{
this.img = img;
this.initRow = iRow;
this.initCol = iCol;
}
}
1