From 71635d978b810725fa400ea4f3ec85da28d53c0d Mon Sep 17 00:00:00 2001 From: Karen Seunsom Date: Fri, 11 Jun 2021 11:08:10 -0500 Subject: [PATCH 1/4] initial commit --- __init__.py | 0 __pycache__/character.cpython-39.pyc | Bin 0 -> 1039 bytes __pycache__/hero.cpython-39.pyc | Bin 0 -> 1143 bytes character.py | 17 ++++++++ hero.py | 37 ++++++++++++++++++ rpg-0.py | 56 +++++++++++++-------------- 6 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 __init__.py create mode 100644 __pycache__/character.cpython-39.pyc create mode 100644 __pycache__/hero.cpython-39.pyc create mode 100644 character.py create mode 100644 hero.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__pycache__/character.cpython-39.pyc b/__pycache__/character.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1442e166cba85cbe3940deda9bb540d4d7236e8b GIT binary patch literal 1039 zcmZWoy>8nu5GEx`mjBu`LuL(KG{gpq4jqc3K!$EYfuf5RmJnIXjxD()-6Ddv_$`V& zK!(0VU!c3zPM*7U>Kz^b#HDb@Bky!~-$zmmhdl!0$Li;&UzCvFxHuj@EZ%~cb5QSy zB$BQ{ZoQ01?*mEv9QGfL{U0OPRwSd6WS$&IU$QmLd>P1aO)@4sGJ-jfUD<;|Du0YHMsD?I#lg0y08y~bM38bQF;T7K zfvn?v*XU?@(?*;_wB;OIGnkLi5Wf0+k7u+C$uVX((8h2F=LHxIWn@MgGNZ2mCnpww z&HV4cIqt#iH5Au(!7Zh59(V?69mcX!Ca(Lj6bms?v902S9nb-GJuR)noOrqeg|b0q z3#IuI&{m}bzg1muwxO_APUPJhIIr!kmfnkwj}y@;hr{@){2<65KyD}KCYxd$m(s4)%v?Cmi?<48pjls*wdE4WB zQOVUD?E&XsR${*OXnX;Bfa)o#XQ=R!9w|I5jm)DMbVjrnL@e^%ZVGIp=jacYz@2gQ NdRzAmM*IOG{{RCe&Kv*$ literal 0 HcmV?d00001 diff --git a/__pycache__/hero.cpython-39.pyc b/__pycache__/hero.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4c95a3a2227d53689961b3a40f92fd501475eb84 GIT binary patch literal 1143 zcmb_b&2G~`5Z?7)+@xs(673E7gw#XhD+h!saVVz1lAV#jhbO3No zIN@{+c56jAv$zd28)lR{H{`-iVAX@M-~SZCg1|ZwS={F~ch)qrxy!vZi5%X6-A9e{ zS}3`}iZ(7l;S`kJn3y@YepvB1zsp+V;8z+zFqVX~j&x)*Z7xJr6 zwbM9S%swd(HmeST4^R`;gTEhP_)ZI@Llx^uJ`v#?C8r`Obhua*nanTMBE3xE)G&h@ zhl^F?GX@I_#;_`lhZ5?+uk0g>;VzqCdNa4PDMDXGYmJ_mM;6cz_sQ+fx@ zy|-^Eg_c8W>`~cyFP8zAL3tMNcpj%BC}dD%B1q+UHpz#zec%L))g&)2EQP&{y5pF$ z1(1`u;kt!mNHtzu6mjwyyP-|D>426!LtvX3!68_+LM3Y#Sz~V*Yr2fhC11|aKW6O9 zGM;TSs*mdj2-w*c;FXF3pqcx8+I3ANfyje__g#VMzj`^|wdukJW!PZ7|MGSec0l3F zQ%4Ag>P_KD3$3m7>Gt0LuJ+*VURe-b=%74p$-a`yp*n$5b_(}WDgPj`5#lkHz1O$@ wtLTHm_&up}ghvPm;>I)VpFjeggKQYV=Ye7>ocwNI 0 + + def print_status(self): + print(f'{self.name} has {self.health} and {self.power}.') + + diff --git a/hero.py b/hero.py new file mode 100644 index 0000000..5ba59e1 --- /dev/null +++ b/hero.py @@ -0,0 +1,37 @@ +# class Hero: +# def __init__(self, name, health=10, power=5): +# self.name = name +# self.health = health +# self.power = power + +# def attack(self, bad_person): +# bad_person.health -= self.power +# print(f'You do {self.power} damage to the goblin.') + +# def is_alive(self): +# self.health > 0 + +# def print_status(self): +# print(f'You have {self.health} and {self.power}') + + +# class Goblin: +# def __init__(self, name, health=6, power=2): +# self.name = name +# self.health = health +# self.power = power + +# def attack(self, good_person): +# good_person.health -= self.power +# print(f'The goblin does {self.power} damage to you.') + +# def is_alive(self): +# self.health > 0 + +# def print_status(self): +# print(f'The goblin has {self.health} and {self.power}') + + + + + diff --git a/rpg-0.py b/rpg-0.py index 3551493..c0737ab 100644 --- a/rpg-0.py +++ b/rpg-0.py @@ -1,3 +1,6 @@ +from character import Character + +# ---------------- """ In this simple RPG game, the hero fights the goblin. He has the options to: @@ -8,40 +11,37 @@ """ def main(): - hero_health = 10 - hero_power = 5 - goblin_health = 6 - goblin_power = 2 + hero = Character('Hero') + goblin = Character('Goblin', health=6, power=2) + + while hero.is_alive and goblin.is_alive: + hero.print_status + goblin.print_status + # print("> ",) + print(""" - while goblin_health > 0 and hero_health > 0: - print("You have %d health and %d power." % (hero_health, hero_power)) - print("The goblin has %d health and %d power." % (goblin_health, goblin_power)) - print() - print("What do you want to do?") - print("1. fight goblin") - print("2. do nothing") - print("3. flee") - print("> ",) +What do you want to do? +1: fight goblin +2: do nothing +3. flee +>""",) user_input = input() - if user_input == "1": - # Hero attacks goblin - goblin_health -= hero_power - print("You do %d damage to the goblin." % hero_power) - if goblin_health <= 0: + if user_input == '1': + hero.attack(goblin) + if goblin.health <= 0: print("The goblin is dead.") - elif user_input == "2": + exit() + elif user_input == '2': pass - elif user_input == "3": - print("Goodbye.") + elif user_input == '3': + print("GOODBYE") break else: - print("Invalid input %r" % user_input) - - if goblin_health > 0: - # Goblin attacks hero - hero_health -= goblin_power - print("The goblin does %d damage to you." % goblin_power) - if hero_health <= 0: + print(f"Invalid input {user_input}") + if goblin.is_alive: + goblin.attack(hero) + if hero.health <= 0: print("You are dead.") + exit() main() From 857a0190b1d04750fa14a221fd50f20f27ab30ce Mon Sep 17 00:00:00 2001 From: Karen Seunsom Date: Fri, 11 Jun 2021 12:24:40 -0500 Subject: [PATCH 2/4] changed method print_status to __str__ --- __pycache__/character.cpython-39.pyc | Bin 1039 -> 1016 bytes character.py | 7 +++++-- rpg-0.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/__pycache__/character.cpython-39.pyc b/__pycache__/character.cpython-39.pyc index 1442e166cba85cbe3940deda9bb540d4d7236e8b..4481817e355d1b861f9fa6b366d4ba624ea18a67 100644 GIT binary patch delta 438 zcmZvYKT88K7{-(I{@M1b9mGZO)?2(maVXZMxE4WNT+Yx2uBG0cZzAF$^b?4b+Z0EK zehzm(K*3MpB2K>VwTOa&_xB`u^E@PZ@IKv^^!+-+as2pt(Gj!O8=ueKce*xifkSW+ za|UZDUwhG+R-hx0dX$b-bOPB}4UCTRTa#pIoG;g9hrb;Bm=|^qqtpOJh5|g4^JZoe z1#ymHSz2W;Q7<=z+#>6oS114U?nQS>y&jg{M%=M6dtyV5%25TXK&?GHr!2Jkg&ibP z2SqbTl$@9(km)ce+#t_x6zqb939wF}$E_}avxOVS+CUt)aiIl*@uJ;JB*;O-pmWtO z$F=>d26n+GY!JxuE3OKr{{@bq()50h*KN=8oNBip@=E`+Exg0aYY5Z%3x7yB*C diff --git a/character.py b/character.py index ea59c4b..56f288a 100644 --- a/character.py +++ b/character.py @@ -11,7 +11,10 @@ def attack(self, other_person): def is_alive(self): self.health > 0 - def print_status(self): - print(f'{self.name} has {self.health} and {self.power}.') + # def print_status(self): + # return f'{self.name} has {self.health} and {self.power}.' + + def __str__(self): + return f'{self.name} has {self.health} health and {self.power} power.' diff --git a/rpg-0.py b/rpg-0.py index c0737ab..86b8917 100644 --- a/rpg-0.py +++ b/rpg-0.py @@ -15,17 +15,17 @@ def main(): goblin = Character('Goblin', health=6, power=2) while hero.is_alive and goblin.is_alive: - hero.print_status - goblin.print_status + print(f''' +~~~~~CURRENT STATS~~~~~~ +{hero} +{goblin} +''') # print("> ",) - print(""" - -What do you want to do? + print("""What do you want to do? 1: fight goblin 2: do nothing -3. flee ->""",) - user_input = input() +3. flee """) + user_input = input('> ') if user_input == '1': hero.attack(goblin) if goblin.health <= 0: From d93a59071da1535d7a19d92109e787dbe7744748 Mon Sep 17 00:00:00 2001 From: Karen Seunsom Date: Fri, 11 Jun 2021 16:04:42 -0500 Subject: [PATCH 3/4] new branch --- __pycache__/character.cpython-39.pyc | Bin 1016 -> 1013 bytes character.py | 2 +- rpg-0.py | 35 ++++++++++++++++++--------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/__pycache__/character.cpython-39.pyc b/__pycache__/character.cpython-39.pyc index 4481817e355d1b861f9fa6b366d4ba624ea18a67..9f8280c308a596dfcb1e6ddc6500fdc2be555a91 100644 GIT binary patch delta 77 zcmeyt{*|3Kk(ZZ?0SJ0e9ZoRY$ji#8VWJ;eoLW?@UzAv!nU|TWA5fH^m6}{qtY1)B fl98XMTU3y)o1U1Py4jNP2qO!Jf=9q)R_4zDywn*) delta 80 zcmey${)3%2k(ZZ?0SH`Y9Zs;?$ji#8Zmb_#oLW?@UzAv!nU|TWA5fH^m6}{qtY1)B el98VmUjX56wqiWO$ibtKk(!uOk};Wy`7;3dO&ZGp diff --git a/character.py b/character.py index 56f288a..4328e4e 100644 --- a/character.py +++ b/character.py @@ -15,6 +15,6 @@ def is_alive(self): # return f'{self.name} has {self.health} and {self.power}.' def __str__(self): - return f'{self.name} has {self.health} health and {self.power} power.' + return f'{self.name} has {self.health} HP and {self.power} power.' diff --git a/rpg-0.py b/rpg-0.py index 86b8917..bf47317 100644 --- a/rpg-0.py +++ b/rpg-0.py @@ -1,26 +1,36 @@ from character import Character # ---------------- -""" -In this simple RPG game, the hero fights the goblin. He has the options to: -1. fight goblin -2. do nothing - in which case the goblin will attack him anyway -3. flee - -""" def main(): - hero = Character('Hero') - goblin = Character('Goblin', health=6, power=2) + user_hero = input('What would you like to name your hero? ') + # hero = Character(user_hero) + goblin = Character('Goblin', health=20, power=4) + special = int(input(f""" +What special would you like, {user_hero}? +1. Max HP +2. + 10 Power +3. Cuddly Pet +> """)) + if special == 1: + hero = Character(user_hero, health=99999) + print("\nYOU NOW HAVE 99999 HP.") + elif special == 2: + hero = Character(user_hero, health=25, power=15) + print("\n*10 POWER HAS BEEN ADDED*") + elif special == 3: + hero = Character(user_hero) + cuddlypet = Character('Cuddly Pet', health=999, power=500) + print(f"\n{cuddlypet.name} stored in inventory.") while hero.is_alive and goblin.is_alive: print(f''' -~~~~~CURRENT STATS~~~~~~ +~~~~~~~~~~CURRENT STATS~~~~~~~~~~~ {hero} {goblin} -''') - # print("> ",) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''') + print("> ",) print("""What do you want to do? 1: fight goblin 2: do nothing @@ -37,6 +47,7 @@ def main(): print("GOODBYE") break else: + # line below not working ? print(f"Invalid input {user_input}") if goblin.is_alive: goblin.attack(hero) From 89b980e74111bf9c3470076e69254d001cd27377 Mon Sep 17 00:00:00 2001 From: Karen Seunsom Date: Mon, 14 Jun 2021 15:36:48 -0500 Subject: [PATCH 4/4] second menu option up and running --- __pycache__/character.cpython-39.pyc | Bin 1013 -> 1018 bytes __pycache__/weapons.cpython-39.pyc | Bin 0 -> 636 bytes character.py | 4 +- rpg-0.py | 87 +++++++++++++++++++++++---- weapons.py | 10 +++ 5 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 __pycache__/weapons.cpython-39.pyc create mode 100644 weapons.py diff --git a/__pycache__/character.cpython-39.pyc b/__pycache__/character.cpython-39.pyc index 9f8280c308a596dfcb1e6ddc6500fdc2be555a91..1e3659a5db64b3fb727d159d7e3da209bd357900 100644 GIT binary patch delta 109 zcmey${)?SAk(ZZ?0SNwXKAvDXk++{QW#ZfyT zNHYRy<{Cy2e=b`yBO^l!LokCTi{C9quFc08{TUerCW|u{aq|JS7YTw0p~+L269FW0 B8btsA delta 108 zcmeyx{*|3Kk(ZZ?0SJ0e9ZoQt$lK4zHF53>E;gWuGY}UWP3~tDRjy&kVxG;A!U&`p zfizPMBZxnjwV9ETA%!8BL6g~U^BG2eMn?Y0GR#HXyg;2r0w6+g@&#t`$s3rx0K&i- Ay#N3J diff --git a/__pycache__/weapons.cpython-39.pyc b/__pycache__/weapons.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0e70eaae0c12e5b920d87dc1a7cb72f29b8b2ad3 GIT binary patch literal 636 zcmZuv%SyvQ6rGtoTB<^E?IPQNZNQZa5y6GKB8UjtjG;63L7T*x6luv$|3dr#xBi6x zFe||y5Zt-)+|+`C7tVdm%{}))vYnj{gS@@GUVp&8Q}A0n1Sf#qg*s!3DgFT5iugqyo3)w+ zV_|5hG|;)8FPlBriuyZmVKq5FgLnCAYcn`9gE*l5=yp=Nj+FC4EoS6zOL@DYt&D(zSGKhI&|0{9rqjjfas`~`kH?ezw-~a#s literal 0 HcmV?d00001 diff --git a/character.py b/character.py index 4328e4e..cc4fcef 100644 --- a/character.py +++ b/character.py @@ -1,12 +1,12 @@ class Character: - def __init__(self, name, health=10, power=5): + def __init__(self, name, health=100, power=5): self.name = name self.health = health self.power = power def attack(self, other_person): other_person.health -= self.power - print(f'{self.name} does {self.power} damage to {other_person.name}') + print(f'\n{self.name} does {self.power} damage to {other_person.name}') def is_alive(self): self.health > 0 diff --git a/rpg-0.py b/rpg-0.py index bf47317..fbf174d 100644 --- a/rpg-0.py +++ b/rpg-0.py @@ -1,27 +1,39 @@ from character import Character +from weapons import Weapons +import random # ---------------- +inventory = [] +banana = Weapons('Banana', 2) +sword = Weapons('Sword', 8) +monkey_bomb = Weapons('Monkey Bomb', 6) +duck = Weapons('DigitalCrafts Duck', 5) +bootcamp = Weapons('Coding Bootcamp',10) + + def main(): user_hero = input('What would you like to name your hero? ') # hero = Character(user_hero) goblin = Character('Goblin', health=20, power=4) + mamagoblin = Character('Mama Goblin', health=50, power=12) special = int(input(f""" What special would you like, {user_hero}? -1. Max HP +1. MAX HP 2. + 10 Power 3. Cuddly Pet > """)) if special == 1: - hero = Character(user_hero, health=99999) - print("\nYOU NOW HAVE 99999 HP.") + hero = Character(user_hero, health=500) + print("\nYOU NOW HAVE A MAX HP OF 500.") elif special == 2: - hero = Character(user_hero, health=25, power=15) + hero = Character(user_hero, power=15) print("\n*10 POWER HAS BEEN ADDED*") elif special == 3: hero = Character(user_hero) - cuddlypet = Character('Cuddly Pet', health=999, power=500) + cuddlypet = Character('Cuddly Pet', health=99999, power=500) + # inventory.append(cuddlypet.name) print(f"\n{cuddlypet.name} stored in inventory.") while hero.is_alive and goblin.is_alive: @@ -32,27 +44,78 @@ def main(): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''') print("> ",) print("""What do you want to do? -1: fight goblin -2: do nothing -3. flee """) +1: Punch goblin +2: Nothing +3. Flee """) user_input = input('> ') if user_input == '1': hero.attack(goblin) if goblin.health <= 0: print("The goblin is dead.") - exit() + # exit() + break elif user_input == '2': pass elif user_input == '3': - print("GOODBYE") + print(f"You escaped goblin.") break else: - # line below not working ? - print(f"Invalid input {user_input}") + print(f"Invalid input: {user_input}") if goblin.is_alive: goblin.attack(hero) if hero.health <= 0: print("You are dead.") exit() + + if goblin.health <= 0: + print("\nMama Goblin did not like that.") + else: print("\nWhile fleeing, you encountered another fiend.") + + while hero.is_alive and mamagoblin.is_alive: + print(f''' +~~~~~~~~~~CURRENT STATS~~~~~~~~~~~ +{hero} +{mamagoblin} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''') + user_input_2 = int(input('''What would you like to do? +1. Spin mystery box +2. Use Cuddly Pet to attack +3. Attempt to hug Mama Goblin +> ''')) + if user_input_2 == 1: + mystery_box = [sword, banana, monkey_bomb, bootcamp] + choice = random.choice(mystery_box) + print(f'{choice.use(mamagoblin)}') + if choice == bootcamp: + print("It was super effective!") + if mamagoblin.health <= 0: + print('Mama Goblin is ded') + exit() + elif user_input_2 == 2 and special == 3: + cuddlypet.attack(mamagoblin) + if mamagoblin.health <= 0: + print("""OVERKILL! Cuddly Pet is OP and needs a nerf! +Mama Goblin was demolished.""") + exit() + if user_input_2 == 2 and special != 3: + print("You do not have Cuddly Pet in your inventory.") + elif user_input_2 == 3: + mamagoblin.attack(hero) + print("Hug attempt not very effective.") + if mamagoblin.is_alive and user_input_2 != 3: + mamagoblin.attack(hero) + if hero.health <= 0: + print("You are dead.") + exit() + + + + + + + + + +# Need to add try and except for invalid inputs ? main() diff --git a/weapons.py b/weapons.py new file mode 100644 index 0000000..5dd3e6b --- /dev/null +++ b/weapons.py @@ -0,0 +1,10 @@ +class Weapons: + def __init__(self, name, power): + self.name = name + self.power = power + + def use(self, enemy): + enemy.health -= self.power + return f'\n{self.name} did {self.power} damage to {enemy.name}' + +