Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
class Hero: username: str health: float damage: float level: int def __init__(self, username: str, level: int, health: float, damage: float): self.username = username self.level = level self.health = health self.damage = damage def battle(self, enemy_hero): if enemy_hero.username == self.username: raise Exception("You cannot fight yourself") if self.health <= 0: raise ValueError("Your health is lower than or equal to 0. You need to rest") if enemy_hero.health <= 0: raise ValueError(f"You cannot fight {enemy_hero.username}. He needs to rest") player_damage = self.damage * self.level enemy_hero_damage = enemy_hero.damage * enemy_hero.level self.health -= enemy_hero_damage enemy_hero.health -= player_damage if self.health <= 0 and enemy_hero.health <= 0: return "Draw" if enemy_hero.health <= 0: self.level += 1 self.health += 5 self.damage += 5 return "You win" enemy_hero.level += 1 enemy_hero.health += 5 enemy_hero.damage += 5 return "You lose" def __str__(self): return f"Hero {self.username}: {self.level} lvl\n" \ f"Health: {self.health}\n" \ f"Damage: {self.damage}\n"
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)