Difficulty Coin won’t let me win. I used JS since it forced me to. My code should work here it is:
// Create a hero
var hero = game.spawnHeroXY('knight', 40, 47);
hero.maxHealth = 99999999999999999999999999999999;
hero.maxSpeed = 10;
hero.attackDamage = 100000;
// Create three coins to collect.
var copperCoin = game.spawnXY('bronze-coin', 26, 33);
var silverCoin = game.spawnXY('silver-coin', 44, 28);
var goldCoin = game.spawnXY('gold-coin', 60, 44);
// Create a manual goal to collect one coin.
var chooseGoal = game.addManualGoal('Choose wisely');
game.addDefeatGoal();
game.addSurviveGoal();
game.difficulty = '...';
// Add visuals
ui.track(game, 'difficulty');
ui.track(game, 'score');
hero.say('Which should I choose...');
function onCollect(event) {
// When the hero collects a coin, destroy the other
// two and build the level based on difficulty choice.
var item = event.other;
if ((item.type == 'coin')) {
if (item.value == 1) {
game.difficulty = 'Easy';
silverCoin.destroy();
goldCoin.destroy();
}
if (item.value == 2) {
game.difficulty = 'Medium';
goldCoin.destroy();
copperCoin.destroy();
}
if (item.value == 3) {
game.difficulty = 'Impossible';
// Destroy the copper and silver coins
copperCoin.destroy();
silverCoin.destroy();
}
beginFight();
chooseGoal.success == True;
}
}
hero.on('collect', onCollect);
function beginFight() {
if (game.difficulty == 'Easy') {
// Create a few barriers and weak enemies
game.spawnXY('forest', 56, 54);
game.spawnXY('forest', 56, 46);
game.spawnXY('forest', 56, 38);
game.spawnXY('forest', 9, 23);
game.spawnXY('forest', 17, 23);
game.spawnXY('forest', 25, 23);
var ogre1 = game.spawnXY('munchkin-m', 11, 14);
ogre1.behavior = "AttacksNearest";
var ogre2 = game.spawnXY('munchkin-m', 67, 51);
ogre2.behavior = "AttacksNearest";
var ogre3 = game.spawnXY('munchkin-m', 66, 13);
ogre3.behavior = "AttacksNearest";
hero.say('This battle is laughably easy!');
}
if (game.difficulty == 'Medium') {
// Create medium-difficulty enemies in a maze
game.spawnMaze(21);
var ogre = game.spawnXY('ogre-f', 45, 43);
ogre.behavior = "AttacksNearest";
ogre = game.spawnXY('ogre', 42, 40);
ogre.behavior = "AttacksNearest";
ogre = game.spawnXY('munchkin', 60, 13);
ogre.behavior = "AttacksNearest";
ogre = game.spawnXY('munchkin', 60, 19);
ogre.behavior = "AttacksNearest";
ogre = game.spawnXY('archer-f', 13, 28);
ogre.behavior = "AttacksNearest";
ogre = game.spawnXY('archer-f', 13, 44);
ogre.behavior = "AttacksNearest";
hero.say('This is non-trivial...');
}
if (game.difficulty == 'Impossible') {
// Create a cluster of various enemies,
// with nowhere to hide!
var i = 0;
while (i < 20) {
var randomUnit = game.randomInteger(0,9);
var randomX = game.randomInteger(13,60);
var randomY = game.randomInteger(13,60);
if (randomUnit >= 8) {
unitType = 'ogre';
}
else if (randomUnit >= 6) {
unitType = 'thrower';
}
else {
var unitType = 'munchkin';
}
var unit = game.spawnXY(unitType, randomX, randomY);
unit.behavior = 'AttacksNearest';
i += 1;
}
hero.say("Oh I'm in trouble...");
}
}
function onDefeat(event) {
// Keep score. The harder the difficulty, the
// higher the score can be!
if (event.target.type == 'munchkin') {
game.score += 1;
}
if (event.target.type == 'thrower') {
game.score += 3;
}
if (event.target.type == 'ogre') {
game.score += 10;
}
hero.say('defeated ' + event.target.type);
}
// Add the event handlers
game.setActionFor("munchkin", "defeat", onDefeat);
game.setActionFor("ogre", "defeat", onDefeat);
game.setActionFor("headhunter", "defeat", onDefeat);
// For testing. Comment this out.
beginFight();