Created
February 20, 2020 05:52
-
-
Save calthoff/cf791f55c02a5154c3599f8c32e621e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| #character class, defines the player | |
| class Character(): | |
| def __init__(self, name = "none", hp = 100, ap = 65): | |
| self.name = name | |
| self.hp = hp #hit points | |
| self.ap = ap #Attack points | |
| #self.items = ["health potion", "sword"] #character items. Potentially... | |
| ## Always include a space here | |
| def take_dmg(self, dmg): #if they character is hit, this i.ds that new hp | |
| # Don't put spaces here | |
| self.hp = self.hp - dmg | |
| def is_dead(self): # i.ds if character is still alive | |
| # Don't put spaces here | |
| if self.hp <1: | |
| return TRUE | |
| else: | |
| return False | |
| # put a space here | |
| def get_atk(self): # how much attacked for | |
| atk = random.randint(0,self.ap) | |
| return atk | |
| def sneak(self): | |
| rnd = random.randint(0,1) | |
| if rnd == 0: | |
| return True | |
| else: | |
| return False | |
| # You don't need else | |
| # if rnd == 0: | |
| # return True | |
| # return False | |
| def rnd_attack(self): | |
| atk = random.choice("attack","defend") | |
| return atk | |
| # don't create a variable if you don't use it. I do that a lot but it is to make my code easier for beginners to read. | |
| # return random.choice("attack","defend") | |
| #test | |
| #pc = Character("Dioni") | |
| #print(pc.name) | |
| #print(pc.get_atk()) | |
| #print(pc.is_dead()) | |
| def has_item(self,item): #checks what items character has | |
| if item in self.items: | |
| return TRUE | |
| else: # get rid of else | |
| return False | |
| # put a space here | |
| class Combat_control(): | |
| def check_attack(self,pc,npc): | |
| while not pc.is_dead() and npc.is_dead(): | |
| atk = check_answer("attack or defend"), ["attack","defend"] | |
| npc_atk = npc.rnd_attack() | |
| if atk == "attack": | |
| if npc_atk == "attack": | |
| pc.take_dmg(npc.get_atk())# the player take damage = to the npc random attack | |
| npc.take_dmg(pc.get_atk()) | |
| else: | |
| pc.take_dmg(npc.get_atk()/2) | |
| npc.take_dmg(pc.get_atk()/3) #may take less damage | |
| else: #player defending | |
| if npc_atk == "attack": | |
| pc.take_dmg(npc.get_atk()/2) | |
| npc.take_dmg(pc.get_atk()/3) #may take less damage | |
| else: | |
| print("No damage") | |
| print("player has " + str(pc.hp) + "hitpoints") | |
| print("NPC has " + str(npc.hp) + "hitpoints") | |
| class Story(): | |
| def __init__(self): | |
| self.cm = Combat_control() | |
| print("Welcome to RIVERS") | |
| self.new_game() #automatically starts a new game | |
| def check_answer(self, question, answers): #list of appropriate answers | |
| answer = " " | |
| while answer not in answers: | |
| answer = input(question).lower() #ask the question | |
| return answer #returns answer, defined in other methods | |
| def new_game(self): #new game, reset button flush outs all variables | |
| self.create_char()#character | |
| self.outside() #first room | |
| def create_char(self): #creating character | |
| name = input("What's your name? ") | |
| self.pc = Character(name) #This will assign to Character.name | |
| def dead(self): #what happens when you hp is less than 0 | |
| print("You died.") | |
| answer = self.check_answer("Do want to try again? ", ["yes","no"]) | |
| if answer == "yes": | |
| self.new_game() | |
| else: # remove else | |
| print("Game over") | |
| def outside(self): #first room | |
| print("You wake up in a forest. You don't know how you got there.") | |
| print("You see a cave.") | |
| print("Suddenly, you see a ghost appear in front of you. It tells you you must go and find a wand in the cave") | |
| print("GHOST: YOU MUST FIND THE WAND IF YOU WANT TO LIVE!") | |
| answer = self.check_answer("Do want to enter the cave? ", ["yes","no"])# No repeats on the same method | |
| if answer == "yes": | |
| self.cave() | |
| else: | |
| print("The ghost takes your soul. You died") | |
| self.dead() | |
| def cave(self): #room 2 | |
| bug = Character(hp = 70, ap = 8) | |
| print("You entered the cave. Inside there is a big bug with a key wraped around its neck.") | |
| print("As you look around the cave, across the room, there is chest a couple meters away from the bug. The key looks like it fits into the chest") | |
| print("The wand you seak may be in that chest?") | |
| options = ["leave the cave", "take the key"," sneak to the chest", "run to the chest" ] | |
| print("You can: ") | |
| for item in options: | |
| print(item) | |
| # No repeats on the same method. Looks at items in the list. | |
| answer = self.check_answer("What do you do? ", options) | |
| if answer == "leave the cave": | |
| print(" You don't have the wand, the ghost kills you ") | |
| self.dead() | |
| elif answer == "take the key": | |
| print("you take the key. The bug attacks you") | |
| self.cm.check_attack(self.pc, bug)#fight | |
| if self.pc.is_dead(): | |
| print("Bug ate you whole. You are dead") | |
| self.dead() | |
| else: | |
| print("You win the fight and get the key") | |
| self.pc.items.append("Wand") | |
| self.chest() | |
| elif answer == "sneak to the chest": | |
| print("you attempt to sneak to the chest ") | |
| if self.pc.sneak(): | |
| print("you got to the chest!") | |
| else: | |
| print("The bug senses you. IT ATTACKS YOU!" ) | |
| self.dead() | |
| else: | |
| print("You run to the chest, the bug notices and attacks you") | |
| self.dead() | |
| def chest(self): | |
| print("You get to the chest. ") | |
| print("You open the chest... ") | |
| print("You find the wand.") | |
| print("As you pick it up, the wand drains your energy. ") | |
| print("You died. ") | |
| self.dead() | |
| new_game = Story() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment