Created
January 12, 2018 13:58
-
-
Save NoxWings/8c2d990c05bfedfa5334770c24d06d90 to your computer and use it in GitHub Desktop.
Cheat for ztype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cheat { | |
constructor (game) { | |
this.game = game; | |
this._target = undefined; | |
} | |
get target () { | |
if (!this._target || this._target.remainingWord.length === 0) { | |
this._target = this.bestTarget; | |
} | |
return this._target; | |
} | |
get bestTarget () { | |
return this.potentialTargets | |
.sort((a, b) => this.game.player.distanceTo(a) > this.game.player.distanceTo(b))[0]; | |
} | |
get potentialTargets () { | |
return Object.values(this.game.targets) | |
.filter(t => t.length > 0) | |
.reduce((flat, toFlaten) => flat.concat(toFlaten), []); | |
} | |
shoot () { | |
if (this.target) { | |
this.game.shoot(this.target.remainingWord[0]); | |
} | |
} | |
start (interval = 10) { | |
this._interval = setInterval(this.shoot.bind(this), interval); | |
} | |
stop () { | |
clearTimeout(this._interval); | |
} | |
} | |
c = new Cheat(ig.game); | |
c.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?