Fixed a heisenbug with taverns.
This commit is contained in:
parent
36387c563c
commit
e9119d0eb9
|
@ -69,23 +69,27 @@ class Maze
|
||||||
console.log "Special encounter set to (#{x}, #{y})"
|
console.log "Special encounter set to (#{x}, #{y})"
|
||||||
###
|
###
|
||||||
|
|
||||||
|
mettavern = false
|
||||||
metbath = false
|
metbath = false
|
||||||
metworkshop = false
|
metworkshop = false
|
||||||
for y in [0..(@height-1)]
|
for y in [0..(@height-1)]
|
||||||
for x in [0..(@width-1)]
|
for x in [0..(@width-1)]
|
||||||
type = @data[x][y].getType()
|
type = @data[x][y].getType()
|
||||||
if type == 'bath'
|
switch type
|
||||||
metbath = true
|
when 'bath'
|
||||||
salet.character.bathname = @data[x][y].loctitle
|
metbath = true
|
||||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
salet.character.bathname = @data[x][y].loctitle
|
||||||
bathevent()
|
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||||
)
|
bathevent()
|
||||||
if type == 'workshop'
|
)
|
||||||
metworkshop = true
|
when 'workshop'
|
||||||
salet.character.workshopname = @data[x][y].loctitle
|
metworkshop = true
|
||||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
salet.character.workshopname = @data[x][y].loctitle
|
||||||
workshopevent()
|
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||||
)
|
workshopevent()
|
||||||
|
)
|
||||||
|
when 'tavern'
|
||||||
|
mettavern = true
|
||||||
|
|
||||||
# если внезапно на карте ни одной бани, ставим баню на 0,0 и вешаем событие
|
# если внезапно на карте ни одной бани, ставим баню на 0,0 и вешаем событие
|
||||||
unless metbath
|
unless metbath
|
||||||
|
@ -97,6 +101,9 @@ class Maze
|
||||||
@setCell('workshop', 'interior', @height-2, @width-1, improv, () ->
|
@setCell('workshop', 'interior', @height-2, @width-1, improv, () ->
|
||||||
workshopevent()
|
workshopevent()
|
||||||
)
|
)
|
||||||
|
# особенно если ни одной таверны
|
||||||
|
unless mettavern
|
||||||
|
@setCell('tavern', 'interior', 0, @width-1, improv)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
setCell: (type, position, x, y, improv, event) ->
|
setCell: (type, position, x, y, improv, event) ->
|
||||||
|
@ -104,7 +111,8 @@ class Maze
|
||||||
@data[x][y].setTag('position', position)
|
@data[x][y].setTag('position', position)
|
||||||
@data[x][y].loctitle = improv.gen('loctitle', @data[x][y])
|
@data[x][y].loctitle = improv.gen('loctitle', @data[x][y])
|
||||||
salet.character.bathname = @data[x][y].loctitle
|
salet.character.bathname = @data[x][y].loctitle
|
||||||
jQuery(document).on("maze_"+x+"_"+y, event)
|
if event?
|
||||||
|
jQuery(document).on("maze_"+x+"_"+y, event)
|
||||||
at: (x, y) ->
|
at: (x, y) ->
|
||||||
if x? and y? and @data[x]? and @data[x][y]?
|
if x? and y? and @data[x]? and @data[x][y]?
|
||||||
return @data[x][y]
|
return @data[x][y]
|
||||||
|
|
|
@ -35,10 +35,12 @@ sysroom = (name, options) ->
|
||||||
options.dsc ?= () ->
|
options.dsc ?= () ->
|
||||||
return @text.fcall()
|
return @text.fcall()
|
||||||
options.text ?= () -> name.l()
|
options.text ?= () -> name.l()
|
||||||
|
###
|
||||||
options.actions = {
|
options.actions = {
|
||||||
exit: () ->
|
exit: () ->
|
||||||
return salet.goBack()
|
return salet.goBack()
|
||||||
}
|
}
|
||||||
|
###
|
||||||
return croom(name, options)
|
return croom(name, options)
|
||||||
|
|
||||||
croom = (name, spec) ->
|
croom = (name, spec) ->
|
||||||
|
|
|
@ -52,12 +52,11 @@
|
||||||
<!-- Dependency JS Libraries -->
|
<!-- Dependency JS Libraries -->
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
||||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js"></script>
|
|
||||||
<script src="https://code.jquery.com/qunit/qunit-2.3.3.js"></script>
|
<script src="https://code.jquery.com/qunit/qunit-2.3.3.js"></script>
|
||||||
|
|
||||||
<script src="game/salet.min.js"></script>
|
<script src="game/salet.min.js"></script>
|
||||||
<script src="game/bundle.js"></script>
|
|
||||||
|
|
||||||
|
<script defer="defer" src="game/bundle.js"></script>
|
||||||
<script defer="defer" src="test/main.js"></script>
|
<script defer="defer" src="test/main.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
36
test/main.js
36
test/main.js
|
@ -4,32 +4,30 @@ salet.autoload = false;
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
QUnit.test("The game starts okay.", function(assert) {
|
QUnit.test("The game starts okay.", function(assert) {
|
||||||
assert.notEqual(salet, void 0, "Salet is initialized");
|
assert.notEqual(salet, void 0, "Salet is initialized");
|
||||||
return assert.equal(salet.current, salet.start, "Salet is in the room called '"+salet.start+"'");
|
assert.notEqual(salet.character.maze, void 0, "The maze exists");
|
||||||
|
assert.notEqual(salet.character.x, undefined, "We know the character's position.");
|
||||||
|
assert.notEqual(salet.character.y, undefined, "We know the character's position.");
|
||||||
|
assert.notEqual(salet.character.getCell(), false, "The current map cell exists")
|
||||||
});
|
});
|
||||||
QUnit.test("There are no game-breaking bugs when entering rooms.", function(assert) {
|
QUnit.test("There are no game-breaking bugs in all rooms or actions.", function(assert) {
|
||||||
for (var key in salet.rooms) {
|
for (var key in salet.rooms) {
|
||||||
// skip loop if the property is from prototype
|
// skip loop if the property is from prototype
|
||||||
if (!salet.rooms.hasOwnProperty(key)) continue;
|
if (!salet.rooms.hasOwnProperty(key)) continue;
|
||||||
|
|
||||||
var room = salet.rooms[key];
|
var room = salet.rooms[key];
|
||||||
|
|
||||||
|
// we place the character to the map centre, so there are cells around
|
||||||
|
salet.character.x = 2;
|
||||||
|
salet.character.y = 2;
|
||||||
assert.ok(salet.goTo(room.name), "Entered room "+room.name);
|
assert.ok(salet.goTo(room.name), "Entered room "+room.name);
|
||||||
}
|
if (room.actions !== undefined) {
|
||||||
});
|
for (var act in room.actions) {
|
||||||
QUnit.test("There are no game-breaking bugs in all actions.", function(assert) {
|
if (!room.actions.hasOwnProperty(act)) continue;
|
||||||
for (var key in salet.rooms) {
|
assert.ok(act.fcall(room), "Executed action "+act);
|
||||||
// skip loop if the property is from prototype
|
}
|
||||||
if (!salet.rooms.hasOwnProperty(key)) continue;
|
for (var act in room.writers) {
|
||||||
var room = salet.rooms[key];
|
if (!room.writers.hasOwnProperty(act)) continue;
|
||||||
|
assert.ok(act.fcall(room), "Executed action "+act);
|
||||||
salet.goTo(room.name);
|
}
|
||||||
for (var act in room.actions) {
|
|
||||||
if (!room.actions.hasOwnProperty(act)) continue;
|
|
||||||
assert.ok(act.fcall(room), "Executed action "+act);
|
|
||||||
}
|
|
||||||
for (var act in room.writers) {
|
|
||||||
if (!room.writers.hasOwnProperty(act)) continue;
|
|
||||||
assert.ok(act.fcall(room), "Executed action "+act);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue