Skip to content

Instantly share code, notes, and snippets.

@airvzxf
Created November 28, 2022 16:18
Show Gist options
  • Save airvzxf/ebe6f9441242c52afbf510dd6746b45d to your computer and use it in GitHub Desktop.
Save airvzxf/ebe6f9441242c52afbf510dd6746b45d 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 Player:
"""
Player class
"""
def __init__(self, name: str, hp: int, money: int):
self.name = name
self.hp = hp
self.money = money
print(f"Player {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 todo")
self.money -= amount
# Puede ser que obtengamos la informacion para determinar si es Player o Enemy, de esa forma podemos
# condicionar si es el player, entonces no decremente el dinero
# Info: {self.name} | HP: {self.hp} | Money: ${self.money}
class EnemyPlayer(Player):
"""
Handler the enemy player
"""
def buy_recruit(self):
"""
Buy a recruit
"""
recruit = {
"name": 'Walking Corpse',
"cost": 8,
}
print(f"MyPlayer buy recruit. Cost ${recruit.get('cost')}")
self.decrease_money(recruit.get("cost"))
class MyPlayer(Player):
"""
Handler the current player
"""
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 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 recruits ===")
israel.buy_recruit()
israel.buy_recruit()
print("=== Player money ===")
print(f"Money: ${israel.money}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment