Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make a 3X3 Slider puzzle game?

843789Feb 28 2010 — edited Feb 28 2010
Hey guys, im new here and decided to make an account on here. Im coming to you guys for help. In my grade 12 infotech class, we were assigned a project dealing with 2d arrays but im having a bit of trouble doing this :S. It needs to do the required:
1. Acquire an image
2. Divide image into NINE separate images
a. You will have a TENTH image that will represent the “removed” space
3. Create TWO 2-D Image arrays
a. One array will store the correct images as reference (use the array index as coordinates for the locations)
b. One array will store the images mixed up
4. Create ONE 2-D Boolean array
a. This array will store the location of where the empty tile is since you actually don’t delete the image
5. Create ONE 2-D Rectangle array
a. This array will store the information for the tiles (width, height, x-start, y-start) you are moving
6. Display the tiles in the right order for the correct image
7. Create a button that will remove a random image-tile
8. Allow the remaining pieces to be moved around (into the empty space) to mix up the picture
9. Keep track of number of moves made
10. Create a button that will indicate it’s the “Solver’s” turn
11. Keep track of number of steps made to solve the puzzle
12. Check if the pieces have been moved into the right locations
13. If the puzzle is completed, add back in the removed piece
14. Play sounds at appropriate times

this is what ive gotten so far.. sorry if its a strain on the eyes.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class movingThingGame extends Applet implements ActionListener KeyListener {

boolean[] keyUp;

char Kp;

//Store correct image co-ordinates
Image[][] aImages;
//Store mixed image co-ordinates
Image[][] bImages;
//Store location of blanked out image
Boolean[][] cTile;
//Store x,y,width,height
Rectangle[][] dInfo;
//Top Row
Image zz; //0,0
Image oz; //1,0
Image tz; //2,0

//Middle Row
Image zo; //0,1
Image oo; //1,1
Image to; //2,1

//Last Row
Image zt; //0,2
Image ot; //1,2
Image tt; //2,2

//Blank Square
Image c;

public void init() {

keyUp=new boolean[4];
for (int x=0;x<4;x++){
keyUp[x]=true;
}

//Declare 2d array aImages have 3 by 3 perimeter
aImages=new Image[3][3];
//Top Row
aImages[0][0]=getImage(getCodeBase(),"spiralTOPLEFT(0,0).gif");
aImages[1][0]=getImage(getCodeBase(),"spiralTOPMIDDLE(1,0).gif");
aImages[2][0]=getImage(getCodeBase(),"spiralTOPRIGHT(2,0).gif");
//Middle Row
aImages[0][1]=getImage(getCodeBase(),"spiralMIDDLELEFT(0,1).gif");
aImages[1][1]=getImage(getCodeBase(),"spiralMIDDLEMIDDLE(1,1).gif");
aImages[2][1]=getImage(getCodeBase(),"spiralMIDDLERIGHT(2,1).gif");
//Bottom Row
aImages[0][2]=getImage(getCodeBase(),"spiralBOTTOMLEFT(0,2).gif");
aImages[1][2]=getImage(getCodeBase(),"spiralBOTTOMMIDDLE(1,2).gif");
aImages[2][2]=getImage(getCodeBase(),"spiralBOTTOMRIGHT(2,2).gif");

}

public void paint(Graphics g) {

//TOP
g.drawImage(aImages[0][0],20,98,128,128,this);
g.drawImage(aImages[1][0],148,98,128,128,this);
g.drawImage(aImages[2][0],276,98,128,128,this);
//MIDDLE
g.drawImage(aImages[0][1],20,226,128,128,this);
g.drawImage(aImages[1][1],148,226,128,128,this);
g.drawImage(aImages[2][1],276,226,128,128,this);
//BOTTOM
g.drawImage(aImages[0][2],20,352,128,128,this);
g.drawImage(aImages[1][2],148,352,128,128,this);
g.drawImage(aImages[2][2],276,352,128,128,this);

}

public void update(Graphics g) {
paint(g);
}

public void actionPerformed(ActionEvent e) {


}

public void keyPressed(KeyEvent event) {
Kp=event.getKeyCode();
if (Kp==37);{ //left
keyUp[0]=false;
}
else if (Kp==39);{ //right
keyUp[1]=false;
}
else if (Kp==38);{ //up
keyUp[2]=false;
}
else if (kp==40);{ //down
keyUp[3]=false;
}
moveImage();
repaint();
}

public void KeyReleased(KeyEvent event) {

Kp=event.getKeyCode();
if (Kp==37);{
keyUp[0]=true;
}
else if (Kp==39);{
keyUp[1]=true;
}
else if (Kp==38);{
keyUp[2]=true;
}
else if (Kp==40); {
keyUp[3]=true;
}
}

public void moveImage() {

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2010
Added on Feb 28 2010
4 comments
614 views