Skip to content

Instantly share code, notes, and snippets.

@airvzxf
Created November 28, 2022 16:17
Show Gist options
  • Save airvzxf/11fa0955bf4dcf314eb5e8b8e2b1adcd to your computer and use it in GitHub Desktop.
Save airvzxf/11fa0955bf4dcf314eb5e8b8e2b1adcd to your computer and use it in GitHub Desktop.
Tutorial de hackeo de videojuegos en Linux. Ejemplo de una supuesta funcionalidad de una función que decrece el dinero.
"""
Handle all the player class
"""
class EnemyPlayer:
"""
Handler the enemy player
"""
def __init__(self, name: str, hp: int, money: int):
self.name = name
self.hp = hp
self.money = money
print(f"EnemyPlayer {self.name} | HP: {self.hp} | Money: ${self.money}")
def decrease_money(self, amount: int):
"""
Decrease player money given an amount.
:type amount: int
:param amount: Amount of money which will be reduced
"""
print(f"Decrease money: ${self.money} - ${amount} = ${self.money - amount}")
self.money -= amount
def buy_recruit(self):
"""
Buy a recruit
"""
recruit = {
"name": 'Walking Corpse',
"cost": 8,
}
print(f"EnemyPlayer buy recruit. Cost ${recruit.get('cost')}")
self.decrease_money(recruit.get("cost"))
class MyPlayer:
"""
Handler the current player
"""
def __init__(self, name: str, hp: int, money: int):
self.name = name
self.hp = hp
self.money = money
print(f"MyPlayer {self.name} | HP: {self.hp} | Money: ${self.money}")
def decrease_money(self, amount: int):
"""
Decrease player money given an amount.
:type amount: int
:param amount: Amount of money which will be reduced
"""
print(f"Decrease money: ${self.money} - ${amount} = ${self.money - amount}")
print("PENDIENTE: Modificar esta linea para demostrar que afecte solo esta clase")
self.money -= amount
def buy_recruit(self):
"""
Buy a recruit
"""
recruit = {
"name": 'Elvish Fighter',
"cost": 14,
}
print(f"MyPlayer buy recruit. Cost ${recruit.get('cost')}")
self.decrease_money(recruit.get("cost"))
if __name__ == "__main__":
print("=== Creating player ===")
israel = MyPlayer("Israel", 38, 100)
print("\n=== Creating player ===")
alberto = MyPlayer("Alberto", 72, 350)
print("\n=== Creating enemy ===")
roldan = EnemyPlayer("Roldan", 45, 50)
print("\n=== Buying enemy recruits ===")
roldan.buy_recruit()
roldan.buy_recruit()
print("=== Enemy money ===")
print(f"Money: ${roldan.money}")
print("\n=== Buying player #1 recruits ===")
israel.buy_recruit()
israel.buy_recruit()
print("=== Player money ===")
print(f"Money: ${israel.money}")
print("\n=== Buying player #2 recruits ===")
alberto.buy_recruit()
alberto.buy_recruit()
print("=== Player money ===")
print(f"Money: ${alberto.money}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment