change meta data handling, added trampoline and some map updates

This commit is contained in:
Stefan Bühler 2012-07-14 19:54:38 +02:00
parent 09dd09bca2
commit f1d8389b1a
19 changed files with 210 additions and 29 deletions

View File

@ -1,5 +1,7 @@
MAPS=$(wildcard ../maps/flood*.map) MAPS=
MAPS+=$(wildcard ../maps/trampoline*.map)
MAPS+=$(wildcard ../maps/flood*.map)
MAPS+=$(wildcard ../maps/contest?.map ../maps/contest10.map) MAPS+=$(wildcard ../maps/contest?.map ../maps/contest10.map)
MAPS+=$(wildcard ../maps/ems*.map) MAPS+=$(wildcard ../maps/ems*.map)
MAPS+=../maps/pacman.map ../maps/pacman2.map MAPS+=../maps/pacman.map ../maps/pacman2.map

View File

@ -1,4 +1,4 @@
var mineGui_mine, mineGui_curmap, mineGui_curndx, mineGui_moves = ""; var mineGui_mine = false, mineGui_curmap, mineGui_curndx, mineGui_moves = "";
var mineGui_movesBackup = []; var mineGui_movesBackup = [];
var mineGui_customNdx = 1; var mineGui_customNdx = 1;
var mineGui_canvas = true; var mineGui_canvas = true;
@ -14,7 +14,9 @@ var mineGui_spriteOffset = {
'L': 3, 'L': 3,
'O': 4, 'O': 4,
'.': 0, '.': 0,
' ': 1 ' ': 1,
'A': 8,'B': 8,'C': 8,'D': 8,'E': 8,'F': 8,'G': 8,'H': 8,'I': 8,
'1': 9,'2': 9,'3': 9,'4': 9,'5': 9,'6': 9,'7': 9,'8': 9,'9': 9
}; };
var mineGui_images = {}; var mineGui_images = {};
@ -192,7 +194,8 @@ function mineGui_updateMine() {
} }
function mineGui_show() { function mineGui_show() {
var waterLevel = Math.max(mineGui_mine.meta.Water, 0); if (!mineGui_mine) return;
var waterLevel = Math.max(mineGui_mine.water_level, 0);
var map = mineGui_mine.toString().split(/\n/); var map = mineGui_mine.toString().split(/\n/);
var canv = document.getElementById("mineGui_mineCanvas"); var canv = document.getElementById("mineGui_mineCanvas");
var mapNode = document.getElementById("mineGui_mineMap"); var mapNode = document.getElementById("mineGui_mineMap");

File diff suppressed because one or more lines are too long

View File

@ -2,14 +2,6 @@
var Mine = function() { var Mine = function() {
var ALIVE = 0, LOST = 1, ABORTED = 2, WON = 3; var ALIVE = 0, LOST = 1, ABORTED = 2, WON = 3;
function defaultMeta() {
return {
Water: 0,
Flooding: 0,
Waterproof: 10,
}
}
function repeat(str, n) { function repeat(str, n) {
return new Array(n+1).join(str); return new Array(n+1).join(str);
} }
@ -45,7 +37,18 @@ var Mine = function() {
this.moves = 0; this.moves = 0;
this.score = 0; this.score = 0;
this.moves_below_water = 0; this.moves_below_water = 0;
this.water = {
level: 0,
flooding: 0,
proof: 10
};
this.lift = this.robot = false; this.lift = this.robot = false;
this.trampoline = {
sources: { }, // x, y and target
targets: { }, // x, y and sources
};
this.trampoline.targets = {};
for (i = 0; i < height; ++i) { for (i = 0; i < height; ++i) {
// padding // padding
if (map[i].length < width) map[i] += repeat(' ', width - map[i].length); if (map[i].length < width) map[i] += repeat(' ', width - map[i].length);
@ -70,6 +73,18 @@ var Mine = function() {
if (this.robot !== false) throw "Only one robot is allowed"; if (this.robot !== false) throw "Only one robot is allowed";
this.robot = { x: x, y: i }; this.robot = { x: x, y: i };
break; break;
default:
if (line[x] >= 'A' && line[x] <= 'I') {
if (this.trampoline.sources[line[x]]) throw "Can have only one trampoline " + line[x];
this.trampoline.sources[line[x]] = { x: x, y: i, target: false };
this.trampoline.fromSources
} else if (line[x] >= '1' && line[x] <= '9') {
if (this.trampoline.targets[line[x]]) throw "Can have only one trampoline target " + line[x];
this.trampoline.targets[line[x]] = { x: x, y: i, sources: [] };
} else {
throw "Invalid character in map: '" + line[x] + "'";
}
break;
} }
} }
} }
@ -78,12 +93,49 @@ var Mine = function() {
if (this.robot === false) throw "Need a robot"; if (this.robot === false) throw "Need a robot";
// meta data // meta data
this.meta = defaultMeta(); this.meta = {};
for (i = 0; i < lines.length; ++i) { for (i = 0; i < lines.length; ++i) {
if (0 == lines[i].length) continue; if (0 == lines[i].length) continue;
pair = lines[i].split(/ +/); var words = lines[i].split(/ +/);
this.meta[pair[0]] = pair.splice(1).join(" "); switch (words[0]) {
case 'Water':
this.water.level = words[1];
break;
case 'Flooding':
this.water.flooding = words[1];
break;
case 'Waterproof':
this.water.proof = words[1];
break;
case 'Trampoline':
if (words.length !== 4 || words[2] !== 'targets')
throw "Invalid trampoline: '" + words.join(" ") +"'";
if (words[1].length != 1 || words[1] < 'A' || words[1] > 'I')
throw "Invalid trampoline source '" + words[1] +"'";
if (words[3].length != 1 || words[3] < '1' || words[3] > '9')
throw "Invalid trampoline target '" + words[3] +"'";
if (!this.trampoline.sources[words[1]]) throw "Trampoline " + words[1] + " not defined";
if (!this.trampoline.targets[words[3]]) throw "Trampoline target " + words[3] + " not defined";
if (this.trampoline.sources[words[1]].target) throw "Trampoline " + words[1] + " already has a target";
this.trampoline.sources[words[1]].target = words[3];
this.trampoline.targets[words[3]].sources.push(words[1]);
break;
default:
this.meta[words[0]] = words.splice(1).join(" ");
break;
} }
}
for (i in this.trampoline.sources) {
if (this.trampoline.sources.hasOwnProperty(i)) {
if (!this.trampoline.sources[i].target) throw "Trampoline " + i + " has no target";
}
}
for (i in this.trampoline.targets) {
if (this.trampoline.targets.hasOwnProperty(i)) {
if (0 == this.trampoline.targets[i].sources.length) throw "Trampoline target " + i + " has no sources";
}
}
this.water_level = this.water.level;
this.state = ALIVE; this.state = ALIVE;
}; };
@ -94,7 +146,7 @@ var Mine = function() {
Mine.prototype.validMove = function (command) { Mine.prototype.validMove = function (command) {
if (this.state != ALIVE) return false; if (this.state != ALIVE) return false;
var n; var n, c;
command = command.toUpperCase(); command = command.toUpperCase();
switch (command) { switch (command) {
case 'L': case 'L':
@ -102,7 +154,8 @@ var Mine = function() {
n = (command == 'L' ? -1 : 1); n = (command == 'L' ? -1 : 1);
if (this.robot.x + n < 0) return false; if (this.robot.x + n < 0) return false;
if (this.robot.x + n >= this.width) return false; if (this.robot.x + n >= this.width) return false;
switch (this.map[this.robot.y][this.robot.x+n]) { c = this.map[this.robot.y][this.robot.x+n];
switch (c) {
case '#': return false; case '#': return false;
case ' ': case ' ':
case '.': case '.':
@ -113,6 +166,9 @@ var Mine = function() {
if (this.robot.x + 2*n < 0) return false; if (this.robot.x + 2*n < 0) return false;
if (this.robot.x + 2*n >= this.width) return false; if (this.robot.x + 2*n >= this.width) return false;
if (' ' == this.map[this.robot.y][this.robot.x+2*n]) return true; if (' ' == this.map[this.robot.y][this.robot.x+2*n]) return true;
default:
if (this.trampoline.sources.hasOwnProperty(c)) return true;
break;
} }
break; break;
case 'U': case 'U':
@ -120,7 +176,8 @@ var Mine = function() {
n = (command == 'D' ? -1 : 1); n = (command == 'D' ? -1 : 1);
if (this.robot.y + n < 0) return false; if (this.robot.y + n < 0) return false;
if (this.robot.y + n >= this.height) return false; if (this.robot.y + n >= this.height) return false;
switch (this.map[this.robot.y+n][this.robot.x]) { c = this.map[this.robot.y+n][this.robot.x];
switch (c) {
case '#': return false; case '#': return false;
case ' ': case ' ':
case '.': case '.':
@ -128,7 +185,10 @@ var Mine = function() {
case 'L': return false; case 'L': return false;
case 'O': return true; case 'O': return true;
case '*': return false; case '*': return false;
" style="} default:
if (this.trampoline.sources.hasOwnProperty(c)) return true;
break;
}
break; break;
case 'W': case 'W':
case 'A': case 'A':
@ -139,7 +199,7 @@ var Mine = function() {
Mine.prototype.move = function(command) { Mine.prototype.move = function(command) {
if (this.state != ALIVE) return false; if (this.state != ALIVE) return false;
var n; var n, c, s, t;
command = command.toUpperCase(); command = command.toUpperCase();
if (this.validMove(command)) { if (this.validMove(command)) {
switch (command.toUpperCase()) { switch (command.toUpperCase()) {
@ -147,7 +207,8 @@ var Mine = function() {
case 'R': case 'R':
n = (command == 'L' ? -1 : 1); n = (command == 'L' ? -1 : 1);
this.map[this.robot.y][this.robot.x] = ' '; this.map[this.robot.y][this.robot.x] = ' ';
switch (this.map[this.robot.y][this.robot.x+n]) { c = this.map[this.robot.y][this.robot.x+n];
switch (c) {
case '*': case '*':
this.map[this.robot.y][this.robot.x+2*n] = '*'; this.map[this.robot.y][this.robot.x+2*n] = '*';
break; break;
@ -158,6 +219,18 @@ var Mine = function() {
case 'O': case 'O':
this._foundLift(); this._foundLift();
break; break;
default:
if (this.trampoline.sources.hasOwnProperty(c)) {
s = this.trampoline.sources[c];
t = this.trampoline.targets[s.target];
for (n = 0; n < t.sources.length; ++n) {
s = this.trampoline.sources[t.sources[n]];
this.map[s.y][s.x] = ' ';
}
this.robot.x = t.x;
this.robot.y = t.y;
n = 0;
}
} }
this.robot.x += n; this.robot.x += n;
this.map[this.robot.y][this.robot.x] = 'R'; this.map[this.robot.y][this.robot.x] = 'R';
@ -166,7 +239,8 @@ var Mine = function() {
case 'D': case 'D':
n = (command == 'D' ? -1 : 1); n = (command == 'D' ? -1 : 1);
this.map[this.robot.y][this.robot.x] = ' '; this.map[this.robot.y][this.robot.x] = ' ';
switch (this.map[this.robot.y+n][this.robot.x]) { c = this.map[this.robot.y+n][this.robot.x];
switch (c) {
case '\\': case '\\':
this.lambdas--; this.lambdas--;
this.found_lambdas++; this.found_lambdas++;
@ -174,6 +248,18 @@ var Mine = function() {
case 'O': case 'O':
this._foundLift(); this._foundLift();
break; break;
default:
if (this.trampoline.sources.hasOwnProperty(c)) {
s = this.trampoline.sources[c];
t = this.trampoline.targets[s.target];
for (n = 0; n < t.sources.length; ++n) {
s = this.trampoline.sources[t.sources[n]];
this.map[s.y][s.x] = ' ';
}
this.robot.x = t.x;
this.robot.y = t.y;
n = 0;
}
} }
this.robot.y += n; this.robot.y += n;
this.map[this.robot.y][this.robot.x] = 'R'; this.map[this.robot.y][this.robot.x] = 'R';
@ -185,7 +271,9 @@ var Mine = function() {
} }
this.moves++; this.moves++;
if (0 == this.lambdas) { if (0 == this.lambdas) {
if (false !== this.lift) this.map[this.lift.y][this.lift.x] = 'O'; if (false !== this.lift && 'L' == this.map[this.lift.y][this.lift.x]) {
this.map[this.lift.y][this.lift.x] = 'O';
}
} }
var newMap = [], x, y, below; var newMap = [], x, y, below;
@ -216,14 +304,14 @@ var Mine = function() {
} }
this.map = newMap; this.map = newMap;
if (this.robot.y < this.meta['Water']) { if (this.robot.y < this.water_level) {
this.moves_below_water++; this.moves_below_water++;
if (this.moves_below_water > this.meta['Waterproof']) this._drown(); if (this.moves_below_water > this.water.proof) this._drown();
} else { } else {
this.moves_below_water = 0; this.moves_below_water = 0;
} }
if (this.meta['Flooding'] > 0 && 0 == (this.moves % this.meta['Flooding'])) { if (this.water.flooding > 0 && 0 == (this.moves % this.water.flooding)) {
this.meta['Water']++; ++this.water_level;
} }
switch (this.state) { switch (this.state) {
@ -274,12 +362,24 @@ var Mine = function() {
Mine.prototype.metaText = function() { Mine.prototype.metaText = function() {
var k, keys = [], lines = []; var k, keys = [], lines = [];
if (this.water.level != 0) lines.push("Water " + this.water.level);
if (this.water.flooding != 0) lines.push("Flooding " + this.water.flooding);
if (this.water.proof != 10) lines.push("Waterproof " + this.water.proof);
for (k in this.trampoline.sources) {
if (this.trampoline.sources.hasOwnProperty(k)) keys.push(k);
}
keys.sort();
for (k = 0; k < keys.length; ++k) {
lines.push("Trampoline " + keys[k] + " targets " + this.trampoline.sources[keys[k]].target);
}
keys = [];
for (k in this.meta) { for (k in this.meta) {
if (this.meta.hasOwnProperty(k)) keys.push(k); if (this.meta.hasOwnProperty(k)) keys.push(k);
} }
keys.sort(); keys.sort();
for (k = 0; k < keys.length; ++k) { for (k = 0; k < keys.length; ++k) {
lines[k] = keys[k] + " " + this.meta[keys[k]]; lines.push( keys[k] + " " + this.meta[keys[k]]);
} }
return lines.join("\n"); return lines.join("\n");
}; };

BIN
js/sprites.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
js/target.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

BIN
js/trampoline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

19
maps/ems6.map Normal file
View File

@ -0,0 +1,19 @@
###########################
#............R............#
#.####.######L######.####.#
#.####.#*#########*#.####.#
#.####..\#*******#\..####.#
#.######..\\\\\\\..######.#
#.####*######.######*####.#
#.####\.....#.#.....\####.#
#......####.#.#.####....#.#
#####.#***#.#.#.#***#.#.#.#
#......\\\..#.#..\\\..#.#.#
#.#########*****#####.#.#.#
#..........\\\\\......#...#
###########################
Author ems_ (irc)
Water 7
Waterproof 42
Highscore 1414

View File

@ -1,3 +1,5 @@
trampoline1: RRLDDRRRRUULLDLLLURRRRRRDD (424)
flood1: LLLLDDRRLDRRDRRDLLUUURRRRRDDDD (945) flood1: LLLLDDRRLDRRDRRDLLUUURRRRRDDDD (945)
flood2: RRUDRRULURULLLLDDDL (281) flood2: RRUDRRULURULLLLDDDL (281)
flood3: LLUURUUURUULRRRRRRRDDDDDDDLLRRUUUUULLLLLRDDDDDD (1303) flood3: LLUURUUURUULRRRRRRRDDDDDDDLLRRUUUUULLLLLRDDDDDD (1303)

10
maps/trampoline1.map Normal file
View File

@ -0,0 +1,10 @@
############
#..*.R..*..#
#..A....B..######
#....2.. ..#\\\C#
#......* *.#\\\1#
########L########
Trampoline A targets 1
Trampoline B targets 1
Trampoline C targets 2

16
maps/trampoline2.map Normal file
View File

@ -0,0 +1,16 @@
######
#....#
#.**.#
#.**.#
#.**.#
######.\\.######
#**....*.......#
#\\....L\\\....#
#A......*****..#
######R.....###########
###.....*.....\\\#
#\\\\#..1...\\\#
#\\\\#......\\\#
################
Trampoline A targets 1

29
maps/trampoline3.map Normal file
View File

@ -0,0 +1,29 @@
#######################################
#****................#..1...\\\\\\\B..#
#R.......##############################
#.. ..................................#
#.. ........ \ ......#
#.. .*. ....**.*...#....... ..........#
#.. ... ....\\\\...#.A..... ..........#
#.. ... ....\ .....#....... * \\..#
#.. ... ....\......#....... ..........#
#.. ... ....\......#....... ..........#
#.. ... ...........#................**#
#..\\\\\...........#................\\#
########### ############## ############
#...*.................................#
#....*.................. ......#
#... .*....*.............. ..... .....#
#....*2*........########.. ..... .....L
#...*...*.......#\\\#..... ...*.......#
#.....\\\.......#\\\#....**..***......#
#.... .......#\\\#*................#
#...............#\\\#*...**...*.......#
#...............#.....................#
###### ############## ### #######
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#######################################
Trampoline A targets 1
Trampoline B targets 2

BIN
specs/images/bricks.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/images/lambda.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/images/lift.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/images/miner.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/images/openlift.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/images/rock.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
specs/trampoline.pdf Normal file

Binary file not shown.