-
Notifications
You must be signed in to change notification settings - Fork 5
/
oriscript5.html
110 lines (100 loc) · 2.52 KB
/
oriscript5.html
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
<html>
<head>
<title>OriMaze in JavaScript</title>
<script language="JavaScript">
<!--
var mc = 0
var b = new Array()
var fs = 14
b[0] = 1; b[1] = 1; b[2] = 1; b[3] = 1; b[4] = 3
b[5] = 2; b[6] = 1; b[7] = 1; b[8] = 2; b[9] = 2
b[10] = 1; b[11] = 2; b[12] = 2; b[13] = 1; b[14] = 0
b[15] = 1; b[16] = 1; b[17] = 2; b[18] = 2; b[19] = 1
b[20] = 1; b[21] = 2; b[22] = 2; b[23] = 2; b[24] = 1
function checkforwin() {
if (b[0] > 2) {
alert("Great job, you solved it!")
}
}
function gotkey(a) {
if (document.all) {
a = window.event;
}
if (a.keyCode == 39 && canMoveRight()) { doMove(fs+1) }
if (a.keyCode == 40 && canMoveDown()) { doMove(fs+5) }
if (a.keyCode == 38 && canMoveUp()) { doMove(fs-5) }
if (a.keyCode == 37 && canMoveLeft()) { doMove(fs-1) }
drawboard()
checkforwin()
}
document.onkeydown = gotkey
var imgname = new Array()
imgname[0] = 'img/go.gif'
imgname[1] = 'img/ver.gif'
imgname[2] = 'img/hor.gif'
imgname[3] = 'img/target.gif'
function xco() { return fs % 5 }
function yco() { return fs / 5 }
function drawboard() {
for (i=0;i<25;i++) {
document.images[i].src = imgname[b[i]]
}
document.mcform.mc.value = mc
}
function canMoveLeft() { return (xco() > 0) && (b[fs-1] > 1) }
function canMoveRight() { return (xco() < 4) && (b[fs+1] > 1) }
function canMoveUp() { return (yco() > 0) && (b[fs-5] == 1) }
function canMoveDown() { return (yco() < 4) && (b[fs+5] == 1) }
function doMove(j) {
var tmp = b[fs]
b[fs] = b[j]
b[j] = tmp
fs = j
mc++
}
// -->
</script>
</head>
<body onload="drawboard();">
The puzzle shown below is the hardest possible on 5x5 and takes a lot
of moves to solve.
<P>
Get the target piece <-- to the top left.
Use cursor keys to move around.
<p>
<table border=1 cellspacing='0' cellpadding='0'><tr>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td></tr><tr>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td></tr><tr>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td></tr><tr>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td></tr><tr>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td>
<td><image></td></tr></table>
<form name="mcform">moves: <input name="mc" value="0"></form>
<!--
<P> Claudio Baiocchi revised the puzzle to offer mouse support and
a history of visited cells.
-->
<HR>
Back to my <A HREF="http://tromp.github.io">home page</A>. <BR>
<a href="mailto:[email protected]">[email protected]</a>
</BODY>
</HTML>