1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 |
var narutoImages=new Array("images/blank.jpg",
"images/naruto-top-middle.jpg",
"images/naruto-top-right.jpg",
"images/naruto-middle-left.jpg",
"images/naruto-middle-middle.jpg",
"images/naruto-middle-right.jpg",
"images/naruto-bottom-left.jpg",
"images/naruto-bottom-middle.jpg",
"images/naruto-bottom-right.jpg");
var openSpace=0;
var order=new Array(0,1,2,3,4,5,6,7,8); var initFlag=0;
var board;
function start(){
alert("Maskanios Jigsaw Puzzle, match the images with the one on the right!");
}
function move(ndx)
{
if(openSpace==ndx){
return false;
}
if ((openSpace==0 &&(ndx==3||ndx==1))||
(openSpace==1 &&(ndx==0||ndx==2||ndx==4))||
(openSpace==2 &&(ndx==1||ndx==5))||
(openSpace==3 &&(ndx==0||ndx==4||ndx==6))||
(openSpace==4 &&(ndx==3||ndx==1||ndx==5||ndx==7))||
(openSpace==5 &&(ndx==2||ndx==4||ndx==8))||
(openSpace==6 &&(ndx==3||ndx==7))||
(openSpace==7 &&(ndx==4||ndx==6||ndx==8))||
(openSpace==8 &&(ndx==5||ndx==7))){
swap(ndx);
checkOrder();
return false;
}
}
function swap(dex)
{
temp=order[openSpace];
order[openSpace]=order[dex];
order[dex]=temp;
openSpaceSource=document.getElementById(openSpace);
openSpaceSource.setAttribute('src',(narutoImages[dex]));
dexSource=document.getElementById(dex);
dexSource.setAttribute('src',('images/blank.jpg'))
checkOrder();
openSpace=dex;
}
function checkOrder()
{
var i;
for(i=0; i<=8; i++){
return false;
alert("You complete the puzzle, great job!");
}
}
function setup(){
var randomNum;
var i;
var gameboard;
var j;
board=document.getElementById('gameboard');
for(var i=0;i<1000;i++)
{
randomNum=Math.floor((Math.random() * 9));
move(randomNum);
}
initflag=true;
}
function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function')
{
window.onload = func;
}
else
{
window.onload = function()
{
oldonload();
func();
}
}
}
addLoadEvent(setup);
addLoadEvent(start); |