def __init__(self, stepsTaken, monstersEncountered): super(MonsterRoom, self).__init__(Room.TYPE_MONSTER) monsterModifier = int(stepsTaken / 50) monsterName = choice(MonsterRoom.MONSTER_NAMES) if monsterModifier > len(MonsterRoom.MONSTER_CLASSES): monsterClass = MonsterRoom.MONSTER_CLASSES[len(MonsterRoom.MONSTER_CLASSES) - 1] else: monsterClass = MonsterRoom.MONSTER_CLASSES[monsterModifier] monster = Entity() monster.name = monsterClass + " " + monsterName monster.setMaximumHealth(10 + MonsterRoom.HEALTH_SCALING * monsterModifier) monster.setHealth(monster.getMaximumHealth()) monster.setAttack(1 + MonsterRoom.ATTACK_SCALING * monsterModifier) monster.setDefense(0 + MonsterRoom.DEFENSE_SCALING * monsterModifier) monster.setExperience(monster.getHealth()) monster.setGold(1 + MonsterRoom.GOLD_SCALING * monsterModifier) if monstersEncountered > 10: if happens(10): monster.name = "Boss " + monster.name monster.setMaximumHealth(monster.getMaximumHealth() * MonsterRoom.BOSS_HEALTH_SCALING) monster.setHealth(monster.getMaximumHealth()) monster.setAttack(monster.getAttack() * MonsterRoom.BOSS_ATTACK_SCALING) monster.setDefense(monster.getDefense() * MonsterRoom.BOSS_DEFENSE_SCALING) monster.setExperience(monster.getExperience() * MonsterRoom.BOSS_EXPERIENCE_SCALING) monster.setGold(monster.getGold() * MonsterRoom.BOSS_GOLD_SCALING) self.enemy = monster print "You've encountered a {monster}. Prepare to fight.".format(monster=monster.name)
class World: MONSTER_NAMES = "Goblin", "Imp", "Orc", "Grue" MONSTER_CLASSES = "Frail", "Common", "Brawny", "Elite", "Legendary" def __init__(self, player): self.player = player self.stepsTaken = 0 self.enemy = None self.bossSafePeriod = 10 def generateMonster(self): self.bossSafePeriod = self.bossSafePeriod - 1 boss = False if self.bossSafePeriod < 0: bossRoll = randint(1, 100) if bossRoll <= 25: boss = True healthScaling = 10 attackScaling = 1 defenseScaling = 0.5 goldScaling = 2 modifier = self.stepsTaken / 50 if modifier >= len(World.MONSTER_CLASSES): monsterClass = World.MONSTER_CLASSES[len(World.MONSTER_CLASSES) - 1] else: monsterClass = World.MONSTER_CLASSES[modifier] monsterName = random.choice(World.MONSTER_NAMES) if boss: monsterName = "Boss " + monsterName self.enemy = Entity(monsterClass + " " + monsterName, 10 + int(healthScaling * modifier), 1 + int(attackScaling * modifier), 0 + int(defenseScaling * modifier)) self.enemy.setExperience(self.enemy.getHealth()) self.enemy.setGold(1 + int(goldScaling * modifier)) if boss: self.enemy.setMaximumHealth(self.enemy.getMaximumHealth() * 10) self.enemy.setHealth(self.enemy.getMaximumHealth()) self.enemy.setAttack(self.enemy.getAttack() * 4) self.enemy.setDefense(self.enemy.getDefense() * 1.5) self.enemy.setGold(self.enemy.getGold() * 10) self.enemy.setExperience(self.enemy.getExperience() * 10) def setEnemy(self, enemy): self.enemy = enemy def getEnemy(self): return self.enemy def setStepsTaken(self, stepsTaken): self.stepsTaken = stepsTaken def getStepsTaken(self): return self.stepsTaken