noobatjavascrip
09-28-2012, 05:15 AM
This is a hw assignment... and know its frowned upon.
Im not looking for the answer just some help.
I have to have 1 image sliced into 4 separate images.
I have to have them in a predetermined order and when you click on a image it swaps them. Ultimately when the images are all in the right place, it makes the picture whole. The part i am having trouble with is knowing when they are in the right order and setting an alert to let the user know they are in the right order.
I know i need to set an 2 arrays. One of the solved order and one to keep track of the order they are in but i cant seem how to figure that part out
here is my code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript" type="text/javascript">
C=[0,0,0,0]
F=["images/tree_01.jpg","images/tree_02.jpg","images/tree_03.jpg","images/tree_04.jpg"]
function f(n)
{
A=document.images[n].src.split("/")
L=A.length
last=A[L-1]
alert(last + "\n" + F + )
}
function swap(n){
remember = document.images[0].src
document.images[0].src = document.images[2].src
document.images[2].src = document.images[3].src
document.images[3].src = document.images[1].src
document.images[1].src = remember
f(n)
}
/*
function testSolved(){
//assume all pieces are in right place
// puzzleissolved=true
//is piece zero in right place?
//if (the name of the first file is not what we think it should be)
// if (document.imgaes[0].src!=F[0])
// puzzlesolved=false
//then puzzlesolved=false
//if not remember it
//is piece one in right place?
//if not remember it
//is piece two in right place?
//if not remember it
//is piece three in right place?
//if not remember it
//now ask if we remember finding anythying out of place
//if so puzzle isnt solved
//if not puzzle is solved and we celebrate
}
*/
</script>
</head>
<body bgcolor="#ffcc99" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
</br>
</center>
</br>
</br>
<center><table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/tree_03.jpg" width="200" height="150" onclick="swap(0) "></td>
<td>
<img src="images/tree_01.jpg" width="200" height="150" onclick="swap(1)"></td>
</tr>
<tr>
<td>
<img src="images/tree_04.jpg" width="200" height="150" onclick="swap(2) "></td>
<td>
<img src="images/tree_02.jpg" width="200" height="150" onclick="swap(3) "></td>
</tr>
</table>
</body>
</html>
Im not looking for the answer just some help.
I have to have 1 image sliced into 4 separate images.
I have to have them in a predetermined order and when you click on a image it swaps them. Ultimately when the images are all in the right place, it makes the picture whole. The part i am having trouble with is knowing when they are in the right order and setting an alert to let the user know they are in the right order.
I know i need to set an 2 arrays. One of the solved order and one to keep track of the order they are in but i cant seem how to figure that part out
here is my code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript" type="text/javascript">
C=[0,0,0,0]
F=["images/tree_01.jpg","images/tree_02.jpg","images/tree_03.jpg","images/tree_04.jpg"]
function f(n)
{
A=document.images[n].src.split("/")
L=A.length
last=A[L-1]
alert(last + "\n" + F + )
}
function swap(n){
remember = document.images[0].src
document.images[0].src = document.images[2].src
document.images[2].src = document.images[3].src
document.images[3].src = document.images[1].src
document.images[1].src = remember
f(n)
}
/*
function testSolved(){
//assume all pieces are in right place
// puzzleissolved=true
//is piece zero in right place?
//if (the name of the first file is not what we think it should be)
// if (document.imgaes[0].src!=F[0])
// puzzlesolved=false
//then puzzlesolved=false
//if not remember it
//is piece one in right place?
//if not remember it
//is piece two in right place?
//if not remember it
//is piece three in right place?
//if not remember it
//now ask if we remember finding anythying out of place
//if so puzzle isnt solved
//if not puzzle is solved and we celebrate
}
*/
</script>
</head>
<body bgcolor="#ffcc99" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
</br>
</center>
</br>
</br>
<center><table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/tree_03.jpg" width="200" height="150" onclick="swap(0) "></td>
<td>
<img src="images/tree_01.jpg" width="200" height="150" onclick="swap(1)"></td>
</tr>
<tr>
<td>
<img src="images/tree_04.jpg" width="200" height="150" onclick="swap(2) "></td>
<td>
<img src="images/tree_02.jpg" width="200" height="150" onclick="swap(3) "></td>
</tr>
</table>
</body>
</html>