PDA

View Full Version : Puzzle help? (making an array?)



SemiSuicidal
04-13-2011, 07:16 PM
Attempting a programming project that requires me to create a "puzzle" (essentially a picture divided into 6 pieces), that can be scrambled then switched around to reassemble the picture. The hitch i'm hitting is that I need the program to recognize when the pieces are in the correct order and alert the user of such. My intent was to do this with an array (assigning each picture a slot in the array so that that slot moves when the picture does and use the array to recognize when all pics are in the correct order.) I'm not sure how to make a proper array in java nor how to assign my pictures a slot in said array. My code thus far is:
<html>
<script type="text/javascript">
function scramble(){
document.images[0].src="Pic_04.jpg"
document.images[1].src="Pic_01.jpg"
document.images[2].src="Pic_05.jpg"
document.images[3].src="Pic_03.jpg"
document.images[4].src="Pic_06.jpg"
document.images[5].src="Pic_02.jpg"
O=[3,0,4,2,5,1]
}
z=0
function store(x){
z++
if(z==2){
store2=x
remember=document.images[store1].src

document.images[store1].src=document.images[store2].src
document.images[store2].src=remember

z=0
}
else{
store1=x
}

//check to see if a=0 b=1 ect.
checkfinished()
}
function Checkfinished(){
if



}
function finish(){
//celebrate
//alert ("-Imagine fireworks here-")
//alert ("Aren't they awesome?")
//alert (I thought so too.")
//rescramble
//scramble()


}


</script>
<body onload="scramble()">
<img id="uno" alt="Pic_01.jpg" onclick="store(0)">
<img id="dos" alt="Pic_02.jpg" onclick="store(1)">
<img id="tres" alt="Pic_03.jpg" onclick="store(2)">
<img id="quatro" alt="Pic_04.jpg" onclick="store(3)">
<img id="cinco" alt="Pic_05.jpg" onclick="store(4)">
<img id="ces" alt="Pic_06.jpg" onclick="store(5)">
</html>
The pictures can now be moved but I do not know how to assign them something that can be recognized by the array so it knows when it's done. Any help would be greatly appreciated.
:confused:

Chimbo
09-20-2011, 03:47 AM
I too would be very much interested in this.
At present, my puzzles work, though they're the hardest thing for me to solve.
I have a 'sane' 24 piece puzzle, and the rest are 96 pieces each.

Minos
09-20-2011, 03:13 PM
Well, you could create a simple array that contains the names of the images in the correct order. This would look like:



var puzSolu = ["Pic_01.jpg", "Pic_02.jpg", "Pic_03.jpg"]


Your checks would then be a simple for loop along these lines:


complete=true;
for (i=0; i<puzSolu.length; i++){
if (document.images[i].src != puzSolu[i]) complete = false
}
if (complete == true)finish();