diff --git a/combat.js b/combat.js index 8fefdf7..015998d 100644 --- a/combat.js +++ b/combat.js @@ -12,6 +12,9 @@ function punchAttack(attacker) { desc: "Punch a nerd", attack: function(defender) { return "You punch the " + defender.description() + " for " + attack(attacker, defender, attacker.str) + " damage"; + }, + attackPlayer: function(defender) { + return "The " + attacker.description() + " punches you for " + attack(attacker, defender, attacker.str) + " damage"; } }; } @@ -22,6 +25,9 @@ function flankAttack(attacker) { desc: "Be sneaky", attack: function(defender) { return "You run around the " + defender.description() + " and attack for " + attack(attacker, defender, attacker.dex) + " damage"; + }, + attackPlayer: function(defender) { + return "The " + attacker.description() + " runs past you, then turns and hits you for " + attack(attacker, defender, attacker.str) + " damage"; } }; } diff --git a/feast.css b/feast.css index b8a0f34..630aae9 100644 --- a/feast.css +++ b/feast.css @@ -6,6 +6,18 @@ body { font-family: sans-serif; } +body.combat { + background: #311; +} + +body.explore { + background: #111; +} + +body.eaten { + background: #500; +} + button { background: #222; color: #eee; diff --git a/feast.js b/feast.js index 4ca86e4..72b2528 100644 --- a/feast.js +++ b/feast.js @@ -11,10 +11,6 @@ let newline = " "; let player = new Player(); -let attacks = []; - -attacks.push(new punchAttack(player)); -attacks.push(new flankAttack(player)); function round(number, digits) { return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits); } @@ -64,13 +60,13 @@ function updateCombat() { list.removeChild(list.firstChild); } - for (let i = 0; i < attacks.length; i++) { + for (let i = 0; i < player.attacks.length; i++) { let li = document.createElement("li"); let button = document.createElement("button"); button.classList.add("combat-button"); - button.innerHTML = attacks[i].name; - button.addEventListener("click", function() { attackClicked(i) }); - button.addEventListener("mouseover", function() { attackHovered(i) }); + button.innerHTML = player.attacks[i].name; + button.addEventListener("click", function() { attackClicked(i); } ); + button.addEventListener("mouseover", function() { attackHovered(i); } ); li.appendChild(button); list.appendChild(li); } @@ -186,6 +182,23 @@ function update(lines=[]) { updateDisplay(); } +function changeMode(mode) { + this.mode = mode; + let body = document.querySelector("body"); + body.className = ""; + switch(mode) { + case "explore": + case "dialog": + body.classList.add("explore"); + break; + case "combat": + body.classList.add("combat"); + break; + case "eaten": + body.classList.add("eaten"); + break; + } +} function startCombat(opponent) { mode = "combat"; currentFoe = opponent; @@ -193,17 +206,27 @@ function startCombat(opponent) { } function attackClicked(index) { - update([attacks[index].attack(currentFoe)]); + update([player.attacks[index].attack(currentFoe)]); if (currentFoe.health <= 0) { update(["The " + currentFoe.description() + " falls to the ground!"]); startDialog(new FallenFoe(currentFoe)); + } else { + let attack = pick(currentFoe.attacks); + + update([attack.attackPlayer(player)]); + + if (player.health <= 0) { + update(["You fall to the ground..."]); + changeMode("eaten"); + } } } function attackHovered(index) { - document.getElementById("combat-desc").innerHTML = attacks[index].desc; + document.getElementById("combat-desc").innerHTML = player.attacks[index].desc; } + function startDialog(dialog) { mode = "dialog"; currentDialog = dialog; diff --git a/vore.js b/vore.js index 45c513b..4afa060 100644 --- a/vore.js +++ b/vore.js @@ -10,6 +10,7 @@ function Creature(name = "Creature") { this.bowels = new Bowels(); this.stomach = new Stomach(this.bowels); this.butt = new Butt(this.bowels,this.stomach); + this.attacks = []; this.str = 10; this.dex = 10; @@ -21,7 +22,10 @@ function Player(name = "Player") { this.fullness = function() { return this.stomach.fullness(); - } + }; + + this.attacks.push(new punchAttack(this)); + this.attacks.push(new flankAttack(this)); } function Anthro() { @@ -39,6 +43,9 @@ function Anthro() { this.description = function() { return this.build + " " + this.species; }; + + this.attacks.push(new punchAttack(this)); + this.attacks.push(new flankAttack(this)); } function Micro() {