Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created September 16, 2010 12:13
Show Gist options
  • Save shaneriley/582325 to your computer and use it in GitHub Desktop.
Save shaneriley/582325 to your computer and use it in GitHub Desktop.
var l = true,
n = null,
o = false,
p = [
["book of healing", 5],
["book of vision", 5],
["book of cure", 5],
["book of genocide", 5]
],
q = [
["apple", 3],
["bread", 3],
["meat", 3],
["egg", 3],
["spaghetti", 3],
["jelly", 3],
["gold", 1],
["strange potion", 9],
["soda", 9],
["milk", 9],
["water", 9],
["tea", 9]
],
r = [
["spider"],
["wasp"],
["rat", "bat", "snake"],
["poisonous bat", "vampire bat", "poisonous snake"],
["rabid mole"],
["mutant", "zombie"],
["ghost"]
],
t = n,
u = Math.floor,
v = Math.random,
w = Math.abs;
function x(a, d) {
if (a instanceof Array) return a[u(v() * a.length)];
return u(a + v() * (d - a))
}
function y(a) {
return a > 0 ? 1 : a < 0 ? -1 : 0
}
function z(a) {
$("#l").append("&gt; " + a + "<br>").scrollTop(1E6)
}
function A() {
t.D(function (a) {
if (a.v && (a.e || a.h.length)) t.i(a)
})
}
function B() {
this.c = n;
this.n = x(this.d * 5, this.d * 10);
this.w = o;
this.da = this.qa = 0;
this.ia = function () {
var a = this.c;
a.e = n;
if (this.w || v() < 0.5) a.h.push(new D("gold"));
a.N = l
};
this.ga = function (a, d) {
a.n -= d;
if (a.n <= 0) {
z((this.j ? "something" : a.a).charAt(0).toUpperCase() + (this.j ? "something" : a.a).slice(1) + " dies.");
if (a.w) {
t.ea = l;
z("You killed the monster, return to the surface!")
}
if (a instanceof E) {
if (confirm("You have died, continue?")) {
a.n = x(10, 20);
a.G = 0;
++a.ha
} else S();
return o
}
a.ia();
t.i(a.c);
return l
}
if (v() < this.qa) {
z(a.a + " has been poisoned!");
a.G = x(3, 10)
}
if (v() < this.da) {
z(a.a + " has been blinded!");
a.j = x(20, 30);
A()
}
return o
};
this.ca = function (a, d) {
var c = this.d,
b = this instanceof E;
b && !d && ++c;
if (!b && !(a instanceof E)) return o;
c = !a.w || d ? x(5 * c, 7 * c) : 1;
var e = this.j;
z((b ? "You hit " + (e ? "something" : a.a) : (e ? "something" : this.a).charAt(0).toUpperCase() + (e ? "something" : this.a).slice(1) + " hits " + a.a) + " for " + c + " hit points.");
return this.ga(a, c)
};
this.B = function (a, d) {
if (!(a | d) || a && d) return o;
var c = this.c,
b = c.x + a,
e =
c.y + d;
if (b < 0 || b >= t.k || e < 0 || e >= t.l) return o;
b = t.g[e][b];
if (b.b == 0 || b.b == 2) return o;
if (b.e != n) {
this.ca(b.e);
return l
}
c.e = n;
b.e = this;
this.c = b;
t.i(c);
t.i(b);
return l
};
this.ta = function (a, d) {
var c = a * a > d * d;
if (!this.B(a, d)) if (c) this.B(a, 0) || this.B(0, d);
else this.B(0, d) || this.B(a, 0)
}
}
function F(a, d, c, b, e) {
this.f = a;
this.key = d;
this.a = c;
this.Ea = b;
this.Ca = e;
this.Y = this.J = o;
this.U = function (f, i) {
this.Ca.call(this.f, f, i)
}
}
function G() {
this.h = [];
this.T = function (a, d) {
a.b &= -2;
if (a.c != n) {
a.c.p(a);
a.c = n
}
d || z("You picked up " + a.a + ".");
this.h.push(a)
};
this.find = function (a) {
for (var d = this.h, c = 0; c < d.length; ++c) {
var b = d[c];
if (b.a == a) return b
}
return n
};
this.ba = function (a) {
var d = this.h;
a = d.indexOf(a);
a >= 0 && d.splice(a, 1)
};
this.W = function () {
for (var a = 0, d = this.h, c = 0; c < d.length; ++c) a |= d[c].b;
return a
};
this.toString = function () {
var a = {},
d = this.h;
if (!d.length) return "nothing";
for (var c = 0; c < d.length; ++c) {
var b = d[c].a;
if (a[b])++a[b];
else a[b] = 1
}
d = "";
for (c in a) {
b = a[c];
d += c;
if (b > 1) d += "*" + b;
d += ", "
}
return d = d.slice(0, -2)
}
}
function H(a, d) {
this.a = a;
this.d = d;
B.call(this);
this.H = function () {
var c = t.f.c,
b = this.c,
e = c.x - b.x;
c = c.y - b.y;
b = u(Math.sqrt(e * e + c * c));
if (this.w || b > 6) {
e = x(-1, 2);
c = x(-1, 2)
} else {
e = y(e);
c = y(c)
}
this.ta(e, c)
}
}
function E() {
this.a = "Mario";
this.d = 1;
this.M = 7;
B.call(this);
this.I = 0;
this.o = new G;
this.ha = this.z = this.j = this.G = 0;
this.F = ["Beggar", "Poor", "Labourer", "Professional", "Prosperous", "Millionaire", "Billionaire"];
this.A = function () {
return 100 + this.d * 50
};
this.R = function () {
return Math.pow(10, this.d + 1)
};
this.n = this.A();
this.p = function (a) {
a.c != n ? a.c.p(a) : this.o.ba(a)
};
this.Ga = function (a) {
this.o.T(a)
};
this.Ha = function (a) {
z("You read " + a.a + ".");
this.p(a);
a = a.a;
if (a.indexOf("healing") >= 0) {
this.n = this.A();
z("You feel fully restored.")
} else if (a.indexOf("vision") >= 0) {
z("You feel somewhat enlightened.");
t.D(function (d) {
if (!d.v) {
d.v = l;
t.i(d)
}
})
} else if (a.indexOf("cure") >= 0) {
this.z = this.G = 0;
if (this.j) {
this.j = 0;
A()
}
} else a.indexOf("genocide") >= 0 && t.D(function (d) {
if (d.e != n && d.e != t.f && !d.e.w) {
d.e.ia();
d.e = n;
t.i(d)
}
})
};
this.ma = function (a) {
var d = this.n,
c = d;
d += a;
a = this.A();
if (d > a) d = a;
d != c && z("You restored " + (d - c) + " health points.");
this.n = d
};
this.za = function (a) {
this.p(a);
z(x(["Umph, it's rotten!", "Tastes great!", "Smells awful.", "You feel satiated."]));
this.ma(x(1, this.A() / 10))
};
this.ua = function (a, d, c) {
this.p(a);
for (var b = "You threw " + a.a + " and hit ", e = t.f.c, f = e.x, i = e.y;;) {
e = t.g[i + c][f + d];
if (e.b == 2) {
b += "the wall";
break
}
if (e.e) {
b += e.e.a;
a = n;
break
}
f += d;
i += c
}
I(f, i, a, e.e, b + ".")
};
this.J = function (a, d) {
var c = n;
this.p(a);
this.p(d);
var b = (a.a.charCodeAt(0) ^ a.a.charCodeAt(1) << 1 ^ a.a.length) + (d.a.charCodeAt(0) ^ d.a.charCodeAt(1) << 1 ^ d.a.length) & 15,
e = "got nothing.";
if (b >= 0 && b < 4) {
c = p[b];
c = new D(c[0], c[1]);
e = "got " + c.a + "."
} else if (b >= 4 && b < 8) {
this.z = x(30, 40);
e = "felt dizzy."
} else if (b >= 8 && b < 12) if (t.wa()) e = "were attacked from ambush!";
z("You tried to combine " + a.a + " and " + d.a + " and " + e);
c && this.o.T(c, l)
};
this.ya = function (a) {
this.p(a);
z("Refreshing!");
a = this.A();
this.ma(x(a / 5, a / 3));
if (v() < 0.05) {
z("You feel dizzy.");
this.z = x(30, 40)
}
};
this.va = function () {
t.Q(q);
v() < 0.1 && t.P(1);
v() < 0.05 && t.Q(p)
};
this.Ba = function (a) {
a.b &= -33;
a.a = "fixed pipes";
a = u(3 * this.d / this.M + 3);
L(a, this.R(), 10 - a)
};
this.aa = function (a) {
var d = this.R();
z("You got $" + a + ".");
this.I += a;
if (this.d < this.M && this.I >= d) {
++this.d;
z(x(["Occasionally you feel stronger!", "You gained next level!"]));
this.I -= d
}
};
this.W = function () {
for (var a = this.c, d = a.h, c = 0, b = 0; b < d.length;) {
var e = d[b];
switch (e.a) {
case "gold":
d.splice(b, 1);
e = this.R();
this.aa(x(e / 10, e / 5));
t.i(a);
continue;
case "key":
this.o.T(e, l);
d.splice(b, 1);
z("You picked up key to the next level.");
t.i(a);
continue;
default:
c |= e.b;
++b
}
}
c |= this.o.W();
d = [];
c & 1 && d.push(new F(this, "p", "<em>P</em>ickup", 1, this.Ga));
if (c & 2) {
d.push(new F(this, "e", "<em>E</em>at", 2, this.za));
b = new F(this, "t", "<em>T</em>hrow", 2, this.ua);
b.Y = l;
d.push(b);
if (c & 8) {
b = new F(this, "a", "<em>A</em>lchemy", 10, this.J);
b.J = l;
d.push(b)
}
}
c & 4 && d.push(new F(this, "r", "<em>R</em>ead", 4, this.Ha));
c & 8 && d.push(new F(this, "d", "<em>D</em>rink", 8, this.ya));
c & 32 && d.push(new F(this, "f", "<em>F</em>ix", 32, this.Ba));
d.push(new F(this, "s", "<em>S</em>earch", 0, this.va));
a = a.b;
if (a == 4 || a == 3) d.push(new F(this, "x", "E<em>x</em>it", 0, this.Aa));
return d
};
this.la = function (a, d) {
var c = [],
b = this.c.h.concat(this.o.h);
d || (d = 2);
for (var e = 0; e < b.length; ++e) {
var f = b[e];
if (a.J ? d & f.b : a.Ea & f.b) c.push([f, a])
}
return c
};
this.Aa = function () {
this.c.b == 3 ? t.Ia() : t.xa()
};
this.H = function () {
if (this.G > 0) {
z(x(["You are slowly dying.", "You feel sick."]));
this.c.N = l;
var a = this.A();
this.ga(this, x(a / 20, a / 10));
--this.G
}
if (this.j > 0) {
--this.j;
this.j <= 0 && A()
}
this.z > 0 && --this.z
}
}
function D(a, d) {
this.b = d;
this.a = a
}
function M(a) {
this.b = a;
this.h = [];
this.e = n;
this.N = this.v = o;
this.p = function (d) {
var c = this.h;
d = c.indexOf(d);
d >= 0 && c.splice(d, 1);
t.i(this)
}
}
function N(a, d, c, b) {
this.r = a;
this.t = c;
this.u = d;
this.q = b;
this.k = c - a;
this.l = b - d;
this.Da = function (e) {
return this.r <= e.t && this.t >= e.r && this.u <= e.q && this.q >= e.u
};
this.X = function (e) {
var f = this.u + this.q >> 1,
i = e.u + e.q >> 1;
return w((this.r + this.t >> 1) - (e.r + e.t >> 1)) + w(f - i)
};
this.ra = function (e) {
var f = this.r,
i = this.t;
d = this.u;
b = this.q;
for (var g = d; g < b; ++g) for (var m = f; m < i; ++m) {
var h = e[g][m];
if (h.b == 0) {
h.b = m == f || m == i - 1 || g == d || g == b - 1 ? 2 : 1;
h.sa = [f, d, i, b]
}
}
}
}
function O(a, d) {
this.k = a;
this.l = d;
this.g = [];
this.h = [];
this.L = this.i = n;
this.F = [];
this.d = 0;
this.f = new E;
this.fixed = this.Z = 0;
this.ea = o;
this.Fa = function (c, b, e) {
if (c >= 0 && c < this.k && b >= 0 && b < this.l) {
c = this.g[b][c];
if (c.b == 0) {
c.b = e;
return l
}
}
return o
};
this.pa = function (c, b) {
for (;;) {
var e = x(c.r + 1, c.t - 1);
e = this.g[x(c.u + 1, c.q - 1)][e];
if (e.b == 1) {
e.b = b;
return e
}
}
};
this.fa = function (c, b) {
for (var e = c.r + c.t >> 1, f = c.u + c.q >> 1, i = b.r + b.t >> 1, g = b.u + b.q >> 1; e != i || f != g;) {
var m = w(e - i),
h = w(f - g),
j = m ? (i - e) / m : 0,
k = h ? (g - f) / h : 0,
s = v();
if (s < 0.3) j = 0;
else if (s > 0.7) k = 0;
if (j != 0 && k != 0) if (m >= h) k = 0;
else j = 0;
m = this.g[f][e];
switch (m.b) {
case 0:
case 2:
m.b = 1
}
for (m = -1; m <= 1; ++m) for (h = -1; h <= 1; ++h) h | m && this.Fa(e + h, f + m, 2);
e += j;
f += k
}
};
this.O = function (c, b, e) {
b = this.g[e][b];
c.c = b;
b.h.push(c);
this.i(b)
};
this.K = function (c, b) {
c.c = b;
b.e = c
};
this.Q = function (c) {
var b = x(0, this.k),
e = x(0, this.l);
if (this.g[e][b].b == 1) {
c = x(c);
this.O(new D(c[0], c[1]), b, e)
}
};
this.ja = function () {
for (var c = 1 / 1.75, b = [], e = this.k, f = this.l, i = this.g = [], g = 0; g < f; ++g) {
i[g] = [];
for (var m = i[g], h = 0; h < e; ++h) {
m.push(new M(0));
var j = m[h];
j.x = h;
j.y = g
}
}
m = this.f;
if (m.d == m.M) {
var k = new N(1, 1, e - 2, f - 2);
k.ra(i);
c = i[f >> 1][e >> 1];
c.b = 3;
for (j = 0; j < e * f / 4; ++j) i[x(1, f)][x(1, e)].N = l;
this.F[this.d] = i;
this.K(m, c);
b = new H("Killer Rabbit of Caerbannog", 25);
b.w = l;
this.K(b, this.g[f / 2][e / 2 + 7]);
z(" Follow! But! follow only if ye be men of valor, for the entrance to this cave is guarded by a creature so foul, so cruel that no man yet has fought with it and lived! Bones of four fifty men lie strewn about its lair. So, brave " + m.a + ", if you do doubt your courage oryour strength, come no further, for death awaits you all with nasty big pointy teeth.");
this.$();
this.L()
} else {
for (j = 0; j < 50; ++j) {
var s = x(5, (this.k - 5 - 2) * 0.3);
g = c + v() * (1.75 - c);
k = s * g | 0;
h = x(0, e - s);
g = x(0, f - k);
if (!(h + s >= e || g + k >= f || s < 5 || k < 5)) {
k = new N(h, g, h + s, g + k);
for (g = 0; g < b.length; ++g) if (k.Da(b[g])) break;
if (g == b.length) {
k.id = b.length;
b.push(k);
k.ra(i)
}
if (b.length >= 10) break
}
}
for (j = h = x(0, b.length); h == j;) j = x(0, b.length);
c = this.pa(b[h], 3);
this.pa(b[j], 4);
for (j = 0; j < b.length; ++j) {
k =
b[j];
k.V = [];
k.C = [];
for (g = 0; g < b.length; ++g) k.V.push(j != g ? k.X(b[g]) : 0)
}
for (j = 0; j < b.length - 1; ++j) {
k = b[j];
g = k.V.slice();
g.sort();
s = g[u(Math.sqrt(g.length))];
if (b.length <= 4) s = g[g.length - 1];
for (g = j + 1; g < b.length; ++g) if (k.V[g] <= s) {
k.C.push(g);
b[g].C.push(j);
this.fa(k, b[g])
}
}
h = [h];
for (s = [];;) {
for (; h.length;) {
j = h.pop();
s.indexOf(j) < 0 && s.push(j);
k = b[j];
for (g = 0; g < k.C.length; ++g) {
j = k.C[g];
if (s.indexOf(j) < 0) {
h.push(j);
s.push(j)
}
}
}
if (s.length < b.length) {
var C = k = n,
Q = 0;
for (j = 0; j < b.length; ++j) if (!(s.indexOf(j) < 0)) {
var J =
b[j];
for (g = 0; g < b.length; ++g) if (s.indexOf(g) < 0) {
var K = b[g];
if (k == n || J.X(K) < Q) {
k = J;
C = K;
Q = J.X(K)
}
}
}
if (k == n) {
alert("closest_room1 == null");
break
}
k.C.push(C.id);
C.C.push(k.id);
h.push(k.id);
h.push(C.id);
this.fa(k, C)
} else break
}
this.K(m, c);
this.F[this.d] = i;
this.L();
for (this.$();;) {
h = x(0, e);
g = x(0, f);
if (i[g][h].b == 1) {
m = new D("key", 1);
this.O(m, h, g);
break
}
}
if (v() < 0.3) {
for (;;) {
h = x(0, e);
g = x(0, f);
if (i[g][h].b == 1) {
m = new D("pipes", 32);
this.O(m, h, g);
++this.Z;
break
}
}
z("Your senses tell you about broken pipe on this floor!")
}
for (j =
0; j < b.length * 5; ++j) this.Q(q);
this.Q(p);
this.P(b.length * 5)
}
};
this.wa = function () {
for (var c = this.f.c, b = [], e = -1; e <= 1; ++e) for (var f = -1; f <= 1; ++f) if (f | e) {
var i = this.g[c.y + e][c.x + f];
i.b == 1 && !i.e && b.push(i)
}
if (b.length) {
i = x(b);
this.K(this.ka(), i);
this.i(i);
return l
}
return o
};
this.ka = function () {
var c = this.f,
b = r.length;
c = 1 + u(b * (c.d - 1) / c.M);
c > 3 && c < b && ++c;
b = r.slice(0, c);
c = b.length;
c = x(c > 3 ? c - 3 : 0, c);
b = x(b[c]);
c = new H(b, c + 1);
if (b.indexOf("poison") >= 0) c.qa = 0.2;
if (b == "ghost" || b == "mutant" || b == "wasp") c.da = 0.3;
return c
};
this.P = function (c) {
for (var b = 0; b < c; ++b) {
var e = x(0, this.k);
e = this.g[x(0, this.l)][e];
if (e.b == 1 && !e.e) {
this.K(this.ka(), e);
this.i(e)
}
}
};
this.na = function (c) {
this.D(function (b) {
if (b.b == c) t.f.c = b
})
};
this.Ia = function () {
var c = this.d,
b = this.F;
if (c == 0) this.ea && this.fixed >= this.Z ? this.Ka(this.f) : z("You must fix all pipes(and probably kill someone), until then there's no way out!");
else {
z("you climbed up the stairs to the level " + c + ".");
this.g = b[--c];
this.d = c;
this.na(4);
this.P(5);
this.L()
}
};
this.xa = function () {
var c =
this.d + 1,
b = this.F,
e = this.f,
f = e.o.find("key");
if (c >= b.length && f == n) z("This door is locked. Find the key to unlock it.");
else {
this.d = c;
z("you stepped down the stairs to the level " + (c + 1) + ".");
if (c >= b.length) {
e.o.ba(f);
this.ja()
} else {
this.g = b[c];
this.na(3);
this.L();
this.P(5)
}
}
};
this.Ja = function (c, b, e, f) {
if (e | f) for (var i = this.k, g = this.l; c >= 0 && c < i && b >= 0 && b < g;) {
var m = this.g[b][c];
if (!m.v) {
m.v = l;
this.i(m)
}
if (m.b == 2) break;
c += e;
b += f
}
};
this.$ = function () {
var c = this.f,
b = c.c;
if (b.sa) {
b = b.sa;
for (var e = b[1]; e < b[3]; ++e) for (var f =
b[0]; f < b[2]; ++f) {
var i = this.g[e][f];
if (!i.v) {
i.v = l;
this.i(i)
}
}
}
for (e = -1; e <= 1; ++e) for (f = -1; f <= 1; ++f) this.Ja(c.c.x, c.c.y, f, e)
};
this.H = function () {
this.$();
var c = [];
this.D(function (e) {
e = e.e;
e != n && c.push(e)
});
for (var b = 0; b < c.length; ++b) c[b].H()
};
this.D = function (c) {
for (var b = 0; b < this.l; ++b) for (var e = 0; e < this.k; ++e) c(this.g[b][e])
}
}
document.title = "Fontanero. 10k Adventure for Gold and Glory. v2";
var P = n,
R = n,
T = o,
U = n,
V = o;
function W() {
if (t != n) {
var a = t.f,
d = "<dl><dt id='f'>" + a.a + " the Fontanero<small>Level: " + a.d + " (" + a.F[a.d - 1] + ")</small></dt><dd>";
d += "<b>HP:</b> " + a.n + " (" + a.A() + ")" + (a.G ? " <b id='ps'>[POISONED]</b> " : "") + (a.j ? " <b id='bl'>[BLINDED]</b>" : "") + (a.z ? " <b id='cf'>[CONFUSED]</b>" : "") + "<br><b>Cash:</b> $" + a.I + " / " + a.R() + "<br><b>Pipes found:</b> " + t.Z + "<br><b>Pipes fixed:</b> " + t.fixed;
if (V) d += "<dt>Choose direction:</dt><dd>Press up, down, left or right to throw " + U.a + "</dd>";
else if (R) {
d += "<dt>Choose item:</dt><dd><ol>";
for (a = 0; a < R.length; ++a) {
var c = R[a];
d += "<li>" + c[0].a + "</li>"
}
d += "</ol></dd>"
} else {
d += "<dt>You are carrying:</dt><dd>" + a.o + "</dd>";
P = a.W();
var b = a.c.h,
e = 0;
d += "<dt>You see:</dt><dd>";
if (b.length) for (a = 0; a < b.length; ++a) {
c = b[a];
e |= c.b;
d += (a ? ", " : "") + c.a
} else d += "nothing";
d += "</dd>";
d += '<dt>Actions:</dt><dd id="a"><ul>';
for (a = 0; a < P.length; ++a) d += "<li>" + P[a].a + "</li>";
d += "</ul></dd>"
}
$("#panel").html(d)
}
}
$(document).bind($.browser.mozilla ? "keypress" : "keydown", function (a) {
var d = t.f;
if (!(t == n || a.metaKey || $("#mg").is(":visible") || d.n <= 0)) {
var c = a.which || a.keyCode,
b = String.fromCharCode(c).toLowerCase();
c = b.charCodeAt(0);
var e = o,
f = l;
switch (c) {
case 27:
e = l;
V = T = o;
U = n;
break;
case 37:
case 38:
case 39:
case 40:
b = [-1, 0, 1, 0][c - 37];
c = [0, -1, 0, 1][c - 37];
if (d.z > 0) {
b = -b;
c = -c
}
if (V) {
d.ua(U, b, c);
f = o
} else d.B(b, c);
e = l;
V = o;
R = U = n;
break;
default:
if (R != n) {
var i = c - 97;
if (i >= 0 && i < R.length) {
b = R[i];
c = b[1];
b = b[0];
if (T && U == n) {
U = b;
R = d.la(c, 8);
f = o;
e = l;
break
}
if (c.Y) {
U = b;
V = l;
f = o;
e = l;
break
}
c.U(b, U)
}
e = l;
R = n
} else if (P != n) for (i = 0; i < P.length; ++i) {
c = P[i];
if (c.key == b) {
R = d.la(c);
T = c.J;
U = n;
switch (R.length) {
case 0:
c.U();
R = n;
break;
case 1:
b = R[0][0];
if (T) {
f = o;
break
}
if (c.Y) {
U = b;
V = l;
f = o;
break
}
c.U(b);
R = n;
break;
default:
f = o
}
P = n;
e = l;
break
}
}
}
if (e) {
a.preventDefault();
f && t.H();
W()
}
}
});
function L(a, d, c) {
function b(h, j, k) {
for (var s = 0; s < a; s++) {
i(h, s);
i(s, j)
}
i(h, j);
f() && !k && e()
}
function e() {
g.oa = l;
$("#mg").hide().empty();
++t.fixed;
t.f.aa(g.m)
}
function f() {
for (var h = 0; h < a; ++h) for (var j = 0; j < a; ++j) if (!m[h][j]) return o;
return l
}
function i(h, j) {
var k = m[j];
k[h] = !k[h];
$("#m" + h + "_" + j).toggleClass("r")
}
a = a || 10;
c = c || a;
var g = {
oa: o,
m: d || 30
},
m = [];
$("#mg").html('<p id="mt">$' + d + '</p><p id="mr"><br>Goal of this minigame is turn <br>all the pipes to its right position (+).<br>Click to turn pipe. <br><br><button id="ms">Start!</button></p><p id="mf"></p><button id="g">Give up!</button>');
(function () {
for (var h = 0, j = ""; h < a; ++h) {
m[h] = [];
for (var k = 0; k < a; ++k) {
m[h][k] = l;
j += '<b class="f" id="m' + k + "_" + h + '"></b>'
}
}
$("#mf").html(j).css({
width: a * 32,
height: a * 32
});
for (k = 0; k < c; ++k) {
b(x(0, a), x(0, a), l);
if (f()) k = 0
}
})();
$("#mg").bind("click.mg", function (h) {
h = h.target;
h.tagName == "B" && b(h.id.replace(/^m(\d+)_\d+$/, "$1"), h.id.replace(/^m\d+_(\d+)$/, "$1"));
switch (h.id) {
case "g":
g.m = 1;
e();
break;
case "ms":
$("#mr").hide();
$("#mf, #g").show();
$("#mg").bind("tick.mg", {
s: g,
id: setInterval("$('#mg').trigger('tick.mg')", 1E3)
}, function (j) {
var k = j.data.s;
if (k.m > 100) k.m = u(k.m / 1.5);
else k.m -= x(1, 4);
if (k.m < 1) k.m = 1;
if (k.oa) {
clearInterval(j.data.id);
$("#mg").unbind(".mg")
} else $("#mt").html("$" + k.m)
})
}
}).show();
$("#ms").focus()
}
function X(a) {
if (!a.v) return -1;
var d = a.e,
c = t.f,
b = c.j > 0;
if (d == c) return 4;
if (d != n) {
if (b) return 24;
if (d.w) return 22;
return (a = {
wasp: 9,
spider: 14,
rat: 15,
bat: 16,
snake: 17,
"poisonous bat": 16,
"vampire bat": 16,
"poisonous snake": 17,
"rabid mole": 18,
mutant: 19,
zombie: 20,
ghost: 21
}[d.a]) ? a : 24
}
d = a.h;
if (c = d.length) {
if (b) return 24;
for (b = a = 0; b < c; ++b) a |= d[b].b & -2;
if (c == 1 || (a & a - 1) == 0) {
a = d[0];
b = a.b;
if (a.a.indexOf("pipes") >= 0) return b & 32 ? 12 : 13;
if (b & 8) return 11;
if (b & 2) return 7;
if (b & 4) return 8;
switch (a.a) {
case "gold":
return 6;
case "key":
return 10
}
}
return 5
}
switch (a.b) {
case 1:
return a.N ? 23 : 0;
case 3:
return 2;
case 4:
return 3;
case 2:
return 1;
default:
return -1
}
}
function Y(a) {
var d = $("#c" + a.y + "_" + a.x);
a = X(a);
a >= 0 ? d.css({
visibility: "visible",
"background-position": "0 " + a * -16 + "px"
}).addClass("t" + a) : d.css("visibility", "hidden")
}
function Z() {
for (var a = '<i id="th"></i>', d, c = t.k, b = t.l, e = 0; e < b; ++e) for (var f = 0; f < c; ++f) {
d = f == 0 ? "u" : "i";
a += "<" + d + " id='c" + e + "_" + f + "'></" + d + ">"
}
$("#map").html(a);
t.D(function (i) {
Y(i);
$("#c" + i.y + "_" + i.x).click(function () {
var g = t.f,
m = g.c;
g.ta(y(i.x - m.x), y(i.y - m.y));
t.H();
W()
})
});
W()
}
function I(a, d, c, b, e) {
var f = t.f.c,
i = a - f.x,
g = d - f.y;
distance = Math.max(Math.abs(i), Math.abs(g));
$("#th").css({
left: (f.x + y(i)) * 16,
top: (f.y + y(g)) * 16
}).show().animate({
left: a * 16,
top: d * 16
}, 20 * distance, function () {
$(this).hide();
z(e);
if (c) {
c.b |= 1;
t.O(c, a, d)
}
b && t.f.ca(b, l);
t.H()
})
}
function aa(a) {
a = '<p id="mr">PURE WIN!!!<br>Got $' + a.I + "<br>Being dead " + a.ha + " times. <br><br><b>Programmed by:</b><br>Vladimir Menshakov<br>&amp;<br>Vladimir Zhuravlev<br>&copy;2010</p>";
$("#mg").html(a).show()
}
window.S = function () {
t == n && $("body").append("<div id='p'><h1>" + document.title + "</h1><div id='c'><p id='map'></p><button id='s'></button><p id='l'></p></div><div id='panel'></div></div><div id='mg'></div>");
$("#s").click(function () {
this.innerHTML = "Turn shadows " + ($("body").toggleClass("on").hasClass("on") ? "off" : "on")
}).click();
if ($.browser.msie) {
$("body").addClass("ie");
$("#s").click()
}
t = new O(40, 24);
$("#c").css("width", 656);
t.i = Y;
t.L = Z;
t.Ka = aa;
t.ja();
z("You've entered the <s>dungeon</s> cellar to fix all broken pipes and vents.");
W()
};
$("head").append($("<style>*{margin:0;padding:0;font-weight:normal;font-style:normal;list-style:none}body{font:normal 12px Verdana;background:#055;color:#fff}h1,#mg{text-align:center}#c,#panel,i,u,.f{float:left}small,.f,i,u,#s{display:block}#mg,#mf,#g,#th{display:none}#mf,#mr,#c,dt,#l{padding:8px}dd,.t1,#map{position:relative}#mt,dt,b{font-weight:bold}#f,.f{font-size:14px}#mf,#mr,#map,#l{overflow:hidden}#p{width:1000px;margin:0 auto}h1{padding:20px 0}#c,dt,#mf,#mr{border:3px solid #c93}#c,dt,#mf,#mr,#l{-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px}#c,dt{background:#122}dt{padding:8px 20px;border-left:0;-moz-border-radius:0 5px 5px 0;-webkit-border-radius:0 5px 5px 0;border-radius:0 5px 5px 0}dd{padding:10px 20px 25px;background:-moz-linear-gradient(-80deg,rgba(0,0,0,0.8),rgba(0,0,0,0) 80px);background:-webkit-gradient(linear,center -40%,55% 50,from(rgba(0,0,0,0.8)),to(rgba(0,0,0,0)));margin:0 3px}#panel{margin-left:-3px;width:325px}#l{font:12px monospace;height:128px;overflow:auto;background:#244}dd b{display:inline-block;width:100px}ol li{list-style:lower-alpha inside}em{color:#c00}#ps{color:#0c0;text-shadow:0 0 3px #0c0}#bl{color:#cc0;text-shadow:0 0 3px #cc0}#cf{color:#0cc;text-shadow:0 0 3px #0cc}u,i{background:url(t.png);width:16px;height:16px}u{clear:left}#s{margin:0 0 8px auto;padding:0 8px;border:2px solid}.on i{-moz-box-shadow:0 0 4px #323a55;-webkit-box-shadow:0 0 4px #323a55;box-shadow:0 0 4px #323a55}.on .t1{-moz-box-shadow:3px 2px 2px #000;-webkit-box-shadow:3px 2px 2px #000;box-shadow:3px 2px 2px #000}#mg{left:0;top:0;position:fixed;width:100%;height:100%;background:rgba(0,0,0,0.9);color:#000}#mf,#mr{margin:100px auto 20px;width:250px;height:150px;background:#fff}.f{font-size:18px;width:32px;height:32px;line-height:32px;-moz-transition-property:-moz-transform,color;-moz-transition-duration:.4s;-webkit-transition-property:-webkit-transform,color;-webkit-transition-duration:.4s;-o-transition-property:-o-transform,color;-o-transition-duration:.4s;color:#060}.f:after{content:'+'}.ie .r:after{content:'\\00d7'}.f:hover{background:#ccc}#mt{font-size:40px;color:#0c0}.r{color:#600;-moz-transform:rotate(45deg);-webkit-transform:rotate(45deg);-o-transform:rotate(45deg)}#th{position:absolute;background-position:0 -112px}</style>"));
@jvfotografias
Copy link

Great game, because i cant finish it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment