DEV Community

annakedrick
annakedrick

Posted on

Any Cat

Any Cat is a simple, text-based game where you can battle two cats against each other. https://learnaboutcat.com/category/facts-about-cat/
The game is easy to learn but difficult to master, and it can be played by people of all ages.
Any Cat is a great way to pass the time, and it's also a lot of fun.
So why not give it a try? You might just find your new favorite game.

import random

class Cat:
def init(self, name, color):
self.name = name
self.color = color
self.hp = 100
self.atk = 10
self.defence = 5

def attack(self, opponent):
    opponent.hp -= self.atk

def defend(self, damage):
    self.hp -= damage

def is_alive(self):
    return self.hp > 0
Enter fullscreen mode Exit fullscreen mode

def main():
# Create two cats
cat1 = Cat("Carl", "blue")
cat2 = Cat("Doug", "grey")

# Start the game
while cat1.is_alive() and cat2.is_alive():
    # Choose a random cat to attack
    attacker = random.choice([cat1, cat2])
    defender = cat1 if attacker == cat2 else cat2

    # Attack the defender
    attacker.attack(defender)

    # Defender defends
    defender.defend(attacker.atk)

# Announce the winner
if cat1.is_alive():
    print("Cat1 wins!")
else:
    print("Cat2 wins!")
Enter fullscreen mode Exit fullscreen mode

if name == "main":
main()

This game is very simple, but it can be easily modified to make it more complex. For example, you could add more cats, different types of attacks, or different levels of difficulty.

Top comments (0)