Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christof Musik
sokoban
Commits
20db0c18
Commit
20db0c18
authored
Feb 01, 2010
by
Christof Musik
Browse files
implemented keys for next/prev level
parent
850de0cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/assistants/Main-assistant.js
View file @
20db0c18
function
MainAssistant
(
set
){
this
.
levels
=
[];
this
.
levelSet
=
set
;
this
.
undoData
=
[];
this
.
undoData
=
[];
}
MainAssistant
.
prototype
.
setup
=
function
(){
...
...
@@ -58,6 +58,8 @@ MainAssistant.prototype.initLevel = function(set, l){
left
:
107
,
// k
right
:
108
,
// l
undo
:
117
,
// u
next
:
0x6e
,
// n
prev
:
0x70
,
// p
}
this
.
readLevel
(
this
.
levels
[
l
]);
...
...
@@ -102,12 +104,20 @@ MainAssistant.prototype.handleKeyPress = function(event){
case
this
.
keys
.
up
:
move
.
y
=
-
1
;
break
;
case
this
.
keys
.
undo
:
this
.
undoMove
();
return
;
default
:
return
;
}
case
this
.
keys
.
undo
:
this
.
undoMove
();
return
;
case
this
.
keys
.
next
:
Mojo
.
Controller
.
stageController
.
sendEventToCommanders
(
Mojo
.
Event
.
make
(
Mojo
.
Event
.
command
,
{
command
:
"
nextLevel
"
}));
return
;
case
this
.
keys
.
prev
:
Mojo
.
Controller
.
stageController
.
sendEventToCommanders
(
Mojo
.
Event
.
make
(
Mojo
.
Event
.
command
,
{
command
:
"
previousLevel
"
}));
return
;
default
:
return
;
}
this
.
position
.
x
+=
move
.
x
;
this
.
position
.
y
+=
move
.
y
;
...
...
@@ -131,29 +141,29 @@ MainAssistant.prototype.handleKeyPress = function(event){
//Mojo.Log.info("x: %d, y: %d", this.position.x, this.position.y);
}
MainAssistant
.
prototype
.
undoMove
=
function
()
{
if
(
this
.
undoData
.
length
)
{
var
move
=
this
.
undoData
.
pop
();
var
figure
=
move
.
figure
;
var
box
=
move
.
box
;
this
.
drawEmpty
(
this
.
position
.
x
,
this
.
position
.
y
);
this
.
position
=
figure
;
this
.
drawFigure
();
if
(
box
)
{
this
.
drawEmpty
(
this
.
boxes
[
box
.
item
].
x
,
this
.
boxes
[
box
.
item
].
y
);
this
.
boxes
[
box
.
item
]
=
box
.
pos
;
this
.
drawBlock
(
this
.
boxes
[
box
.
item
].
x
,
this
.
boxes
[
box
.
item
].
y
)
}
}
MainAssistant
.
prototype
.
undoMove
=
function
(){
if
(
this
.
undoData
.
length
)
{
var
move
=
this
.
undoData
.
pop
();
var
figure
=
move
.
figure
;
var
box
=
move
.
box
;
this
.
drawEmpty
(
this
.
position
.
x
,
this
.
position
.
y
);
this
.
position
=
figure
;
this
.
drawFigure
();
if
(
box
)
{
this
.
drawEmpty
(
this
.
boxes
[
box
.
item
].
x
,
this
.
boxes
[
box
.
item
].
y
);
this
.
boxes
[
box
.
item
]
=
box
.
pos
;
this
.
drawBlock
(
this
.
boxes
[
box
.
item
].
x
,
this
.
boxes
[
box
.
item
].
y
)
}
}
}
MainAssistant
.
prototype
.
checkCollision
=
function
(
move
,
currentPos
){
var
x
=
this
.
position
.
x
;
var
y
=
this
.
position
.
y
;
var
movedBox
=
null
;
var
movedBox
=
null
;
Mojo
.
Log
.
info
(
"
next block would be: %s
"
,
this
.
level
[
y
][
x
]);
...
...
@@ -183,15 +193,15 @@ MainAssistant.prototype.checkCollision = function(move, currentPos){
return
true
;
}
movedBox
=
{
item
:
i
,
pos
:
{
"
x
"
:
this
.
boxes
[
i
].
x
,
"
y
"
:
this
.
boxes
[
i
].
y
,
"
target
"
:
this
.
boxes
[
i
].
target
,
}
};
movedBox
=
{
item
:
i
,
pos
:
{
"
x
"
:
this
.
boxes
[
i
].
x
,
"
y
"
:
this
.
boxes
[
i
].
y
,
"
target
"
:
this
.
boxes
[
i
].
target
,
}
};
// no collision with other boxes, check if on target
if
(
this
.
level
[
by
][
bx
]
==
"
.
"
)
{
this
.
boxes
[
i
].
target
=
true
;
...
...
@@ -200,7 +210,7 @@ MainAssistant.prototype.checkCollision = function(move, currentPos){
this
.
boxes
[
i
].
target
=
false
;
}
// move box
this
.
boxes
[
i
].
x
=
bx
;
this
.
boxes
[
i
].
y
=
by
;
this
.
drawBlock
(
bx
,
by
);
...
...
@@ -208,12 +218,12 @@ MainAssistant.prototype.checkCollision = function(move, currentPos){
break
;
}
}
this
.
undoData
.
push
({
figure
:
Object
.
clone
(
currentPos
),
box
:
Object
.
clone
(
movedBox
)
});
figure
:
Object
.
clone
(
currentPos
),
box
:
Object
.
clone
(
movedBox
)
});
return
false
;
}
...
...
@@ -248,12 +258,8 @@ MainAssistant.prototype.calculateBoxSize = function(){
Mojo
.
Log
.
info
(
"
w: %d, h: %d
"
,
w
,
h
);
if
(
this
.
height
>
this
.
width
)
{
}
else
{
this
.
blockSize
=
Math
.
floor
(
w
/
this
.
width
);
}
this
.
blockSize
=
Math
.
floor
(
w
/
this
.
width
);
}
MainAssistant
.
prototype
.
drawLevel
=
function
(){
...
...
@@ -362,14 +368,14 @@ MainAssistant.prototype.showLevelDoneDialog = function(){
}
MainAssistant
.
prototype
.
readLevels
=
function
(){
var
url
=
"
levels/
"
+
this
.
levelSet
+
"
.levels
"
var
url
=
"
levels/
"
+
this
.
levelSet
+
"
.levels
"
var
request
=
new
Ajax
.
Request
(
url
,
{
method
:
'
get
'
,
onSuccess
:
function
(
r
){
this
.
levels
=
r
.
responseText
.
split
(
"
;LEVEL
"
);
this
.
levels
.
splice
(
0
,
1
);
var
l
=
this
.
levelSettings
.
get
(
"
level
"
);
if
(
typeof
l
===
"
undefined
"
)
//
if (typeof l === "undefined")
l
=
0
;
this
.
initLevel
(
"
fo
"
,
l
);
}
...
...
sources.json
View file @
20db0c18
...
...
@@ -3,5 +3,9 @@
{
"scenes"
:
"Main"
,
"source"
:
"app/assistants/Main-assistant.js"
},
{
"scenes"
:
"LevelSet"
,
"source"
:
"app/assistants/LevelSet-assistant.js"
}
]
\ No newline at end of file
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment