Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions problems/py101/make_a_game/lib/player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from .pythonmon import Pythonmon
import random

class Player:
def __init__(self):
self._in_game = True
self.name = None
self.pymon = None

def say_hello(self):
return "Hello!"
Expand All @@ -16,8 +20,30 @@ def repeat(self, message):
def in_game(self):
return self._in_game

def catch_pymon(self):
self.has_pymon = True
list_of_pymon = ["Pykachu", "Pymander", "Pytle", "Pybasaur"]
seed = random.randint(0,len(list_of_pymon) - 1)
name = list_of_pymon[seed]
self.pymon = Pythonmon(name)
pass

def check_pymon(self):
if self.pymon is not None:
print(f'Your pymon is called :{self.pymon.name} and has {self.pymon.hp} hp')
else:
print("Go catch a Pymon")

def fight_baddie(self):
if self.pymon is None:
print("No Pymon")
else:
self.pymon.get_attacked()

@in_game.setter
def in_game(self, game_state):
if not isinstance(game_state, bool):
raise Exception("Must set game state to True or False")
self._in_game = game_state


15 changes: 11 additions & 4 deletions problems/py101/make_a_game/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

if __name__ == "__main__":
player = Player()
player_name = input("Hello! What is your name? ")
player_name = input("Yo! What is your name? ")
player.set_name(player_name)
print(f"Welcome {player.name} to this new game!")
print("Right now, all we can do is repeat what you say.")
print("Edit this program to add in more functionality!")
print(f"Welcome {player.name} to Pymon!")
print("Type 'catch' to catch a Pymon!")
print("Type 'Fight' to fight!")
print("To stop playing, type quit")

while player.in_game:
message = input("What would you like me to repeat? (type quit to exit) ")
if message == "quit":
print("Roger that, thanks for playing!")
player.in_game = False
elif message == "catch":
player.catch_pymon()
print("You just caught a Pymon!")
elif message == "fight":
player.fight_baddie()
elif message == "check":
player.check_pymon()
else:
print(player.repeat(message))