wok-6.x view sokojs/stuff/undo.u @ rev 24196
updated perl-datetime-locale (0.45 -> 1.33)
author | Hans-G?nter Theisgen |
---|---|
date | Fri Dec 31 15:04:43 2021 +0100 (2021-12-31) |
parents | db9d9cb3c164 |
children |
line source
1 --- main.htm
2 +++ main.htm
3 @@ -11,8 +11,9 @@
4 -->
5 <html>
6 <head>
7 +<meta http-equiv="Content Type" content="text/html;charset=utf-8">
8 <meta name="viewport" content="width=device-width, initial-scale=1">
9 -<style>
10 +<style type="text/css">
11 <!--
12 img.r{
13 width:30px;
14 @@ -84,11 +85,11 @@
15 if (evenement.which == 52 || evenement.which == 37) {
16 Move(eval(manpos) - 1)
17 } else if (evenement.which == 56 || evenement.which == 38) {
18 - Move(eval(manpos) - Row)
19 + Move(eval(manpos) - Col)
20 } else if (evenement.which == 54 || evenement.which == 39) {
21 Move(eval(manpos) + 1)
22 } else if (evenement.which == 50 || evenement.which == 40) {
23 - Move(eval(manpos) + Row)
24 + Move(eval(manpos) + Col)
25 }
26 }
28 @@ -108,7 +109,7 @@
29 if (window.event.keyCode == 37) {
30 Move(eval(manpos) - 1)
31 } else if (window.event.keyCode == 38) {
32 - Move(eval(manpos) - Row)
33 + Move(eval(manpos) - Col)
34 } else if (window.event.keyCode == 39) {
35 Move(eval(manpos) + 1)
36 } else if (window.event.keyCode == 40) {
37 @@ -152,6 +153,7 @@
38 level = new Array()
39 maxLevel = 97
40 moves = 0
41 +saved = ""
43 function ReloadLevel() {
44 manpos = parent.frames[0].document.forms[0].elements[Row*Col].value
45 @@ -174,44 +176,57 @@
46 function dir(d) {
47 if (d == -1) return "L";
48 if (d == 1) return "R";
49 - if (d == Row) return "D";
50 - if (d == -Row) return "U";
51 + if (d == Col) return "D";
52 + if (d == -Col) return "U";
53 +}
54 +
55 +function undoDir(c) {
56 + if (c.toLowerCase() == 'u') return Col;
57 + if (c.toLowerCase() == 'd') return -Col;
58 + if (c.toLowerCase() == 'r') return -1;
59 + if (c.toLowerCase() == 'l') return 1;
60 }
62 function print_moves(m) {
63 document.getElementById('moves').firstChild.nodeValue=m + " moves"
64 }
65 +
66 function UndoMove() {
67 - if (ua != -1) {
68 - document.images[manpos].src = eval("img" + level[manpos] + ".src")
69 - document.images[ua].src = eval("img" + lua + ".src")
70 - document.images[ub].src = eval("img" + lub + ".src")
71 - level[ua] = lua
72 - level[ub] = lub
73 - level[um] = lum
74 - document.images[manpos = um].src = usrc
75 - nbBoxin = unb
76 - print_moves(--moves)
77 - ua = -1
78 - }
79 + if (saved.length > 0) {
80 + var c = saved.charAt(saved.length-1)
81 + var m = eval("manD.src")
82 + do {
83 + saved = saved.substring(0,saved.length-1)
84 + d = undoDir(c)
85 + a = manpos - d
86 + if (c != c.toLowerCase()) {
87 + if (level[a] == boxin && level[manpos] != dest) nbBoxin++
88 + if (level[a] != boxin && level[manpos] == dest) nbBoxin--
89 + print_moves(--moves)
90 + level[a] = (level[a] == boxin) ? dest : floor
91 + level[manpos] = (level[manpos] == dest) ? boxin : boxout
92 + document.images[a].src = eval("img" + level[a] + ".src")
93 + }
94 + document.images[manpos].src = eval("img" + level[manpos] + ".src")
95 + manpos += d
96 + if (saved.length == 0) break
97 + c = saved.charAt(saved.length-1)
98 + m = eval("man"+c.toUpperCase()+".src")
99 + } while (c == c.toLowerCase())
100 + document.images[manpos].src = m
101 + }
102 }
104 function Move(a) {
105 d = a - manpos
107 if (d == 1 || d == -1 || d == Col || d == -Col) {
108 + var m = dir(d).toLowerCase()
109 if (level[a] == boxin || level[a] == boxout) {
110 b = a + d
111 - um = manpos
112 - ua = a
113 - ub = b
114 - lum = level[manpos]
115 - lua = level[a]
116 - lub = level[b]
117 - usrc = document.images[manpos].src
118 - unb = nbBoxin
119 - print_moves(++moves)
120 + m = dir(d)
121 if (level[b] == floor || level[b] == dest) {
122 + ++moves
123 level[a] == boxin ? (level[a] = dest, nbBoxin++) : level[a] = floor
124 level[b] == dest ? (level[b] = boxin, nbBoxin--) : level[b] = boxout
125 document.images[b].src = eval("img" + level[b] + ".src")
126 @@ -221,7 +236,9 @@
127 if (level[a] == floor || level[a] == dest) {
128 document.images[manpos].src = eval("img" + level[manpos] + ".src")
129 document.images[manpos = a].src = eval("man" + dir(d) + ".src")
130 + saved+=m
131 }
132 + print_moves(moves)
134 if (nbBoxin == 0) {
135 if (nbLevel < maxLevel) {
136 @@ -246,14 +263,15 @@
137 for (y = 0 ; y < Row; y++) {
138 document.write ("<TR>")
139 for (x = 0; x < Col; x++) {
140 - level[x + Row * y] = parent.frames[0].document.forms[0].elements[x + Row * y].value
141 - if (level[x + Row * y] == dest) nbBoxin++
142 - if (level[x + Row * y] == land || level[x + Row * y] == wall)
143 + var i = x + Col * y
144 + level[i] = parent.frames[0].document.forms[0].elements[i].value
145 + if (level[i] == dest) nbBoxin++
146 + if (level[i] == land || level[i] == wall)
147 document.write("<TD VALIGN=TOP>",
148 - "<IMG align=middle class=r border=0 src=\"", level[x + Row * y], ".gif\"<\/TD>")
149 + "<IMG align=middle class=r border=0 src=\"", level[i], ".gif\"<\/TD>")
150 else
151 - document.write("<TD VALIGN=TOP><A HREF=\"JavaScript:Move(", x + Row * y, ")\">",
152 - "<IMG align=middle class=r border=0 src=\"", level[x + Row * y], ".gif\"</A><\/TD>")
153 + document.write("<TD VALIGN=TOP><A HREF=\"JavaScript:Move(", i, ")\">",
154 + "<IMG align=middle class=r border=0 src=\"", level[i], ".gif\"</A><\/TD>")
155 }
156 document.write("<\/TR>")
157 }