Created
July 18, 2015 19:40
-
-
Save luisangelma/b50bc4cdbdc996bbb649 to your computer and use it in GitHub Desktop.
Enemy generators
This file contains hidden or 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
| // Warmup Enemy generator | |
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| var Enemy = function() { | |
| var self = this; | |
| this.type = ''; | |
| this.hitPoints = 0; | |
| this.defense = 0; | |
| var types = ['Ancient Dragon', 'Prowler', 'Mighty Grunt']; | |
| var setHitPoints = function(){ | |
| if (self.type === types[0]) { | |
| self.hitPoints = getRandomInt(80, 100); | |
| } else if (self.type === types[1]) { | |
| self.hitPoints = getRandomInt(50, 79); | |
| } else if (self.type === types[2]) { | |
| self.hitPoints = getRandomInt(20, 49); | |
| } | |
| self.defense = self.hitPoints * 3; | |
| }; | |
| var setType = function() { | |
| self.type = types[getRandomInt(0, types.length -1)]; | |
| setHitPoints(); | |
| }; | |
| setType(); | |
| } | |
| function generateEnemies() { | |
| var enemies = []; | |
| for (var i = 0; i < 1000; i++) { | |
| var enemy = new Enemy(); | |
| enemies.push(enemy); | |
| console.log('Type = ' + enemy.type + ' HP: ' + enemy.hitPoints + ' Def: ' + enemy.defense); | |
| } | |
| } | |
| generateEnemies(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment