def attack(entity1, entity2): print("\n\n" + colored(entity1.name, entity1.color) + " is " + entity1.stats + "\n" + colored(entity1.name, entity1.color) + " deal " + str(entity1.damage) + " damage to " + colored(entity2.name, entity2.color) + "!") entity2.health -= entity1.damage print(colored(entity2.name, entity2.color) + " health is down to " + str(entity2.health) + ".") if entity2.health <= 0: print("\n" + colored(entity2.name, entity2.color) + " is defeated! Congratulations!") return True else: return False
def DEBUG_printMap(self, lim=2): ''' Prints the map. ''' for x in range(self.size_x): for y in range(self.size_y): if x == 0 or x == 1 or y == 0 or y == 1 or x == self.size_x - 1 or x == self.size_x - 2 or y == self.size_y - 1 or y == self.size_y - 2: print(' ', end='') elif self.map[x][y] < -lim: # sea print(colored('_', 'blue'), end='') elif self.map[x][y] >= -lim and self.map[x][y] <= lim: # flat print(colored('"', 'green'), end='') elif self.map[x][y] > lim: # mountains print(colored('^', 'yellow'), end='') else: print(colored(self.map[x][y], 'red'), end='') print()
def printMap(self): ''' Prints the map. ''' for x in range(self.size_x): for y in range(self.size_y): if x == 0 or x == 1 or y == 0 or y == 1 or x == self.size_x - 1 or x == self.size_x - 2 or y == self.size_y - 1 or y == self.size_y - 2: print(' ', end='') elif self.map[x][y] == -1: # sea print(colored('_', 'blue'), end='') elif self.map[x][y] == 0: # flat print(colored('"', 'green'), end='') elif self.map[x][y] == 1: # mountains print(colored('^', 'yellow'), end='') else: print(colored(self.map[x][y], 'red'), end='') print()
def answer_handler(ch): print('\n') for i in range(1, len(ch) + 1): print('\t\t' + str(i) + ') ' + ch[i - 1]) q = False while not q: ans = input('\t\t>> ') if is_integer(ans) and int(ans) > 0 and int(ans) < len(ch) + 1: q = True else: print(colored('\t\tInvalid input!', 'red')) sleep(0.5) return [int(ans), ch[int(ans) - 1]]
def battle(player, enemy): ''' player = '' for entity in entity_list: if isinstance(entity, Player): player = entity entity_list.remove(player) ''' turn = 0 _exit = False while not _exit: turn += 1 if turn % 2 != 0: _exit = attack(player, enemy) else: _exit = attack(enemy, player) print(colored("\nBattle is finished!\n", 'yellow'))
def emote(emotion, color='bright_black', on_color='on_black'): print(colored('\n [' + emotion + ']', color, on_color), end='') sleep(0.75)
def phrase(speaker, line, color, on_color='on_black'): sleep(0.75) print('\n ' + colored(speaker, color, on_color) + ': ' + line, end='')
def updateStats(self): return (" [" + colored("H:%i " % self.health, 'red') + colored("D:%i " % self.damage, 'blue') + colored("S:%s " % self.setSkill(), 'yellow') + "] ")