Apr-04-2018, 01:47 PM
Hey every body,
I got motivated the other day and started working on a long time project of mine. I've always wanted to code my very own Dungeons and Dragons Auto Dice Roller. SO, this is my latest attempt. I'm just a noob so be nice:) I wanted to figure out how to pass a variable between classes. I thought this would be a fun way to do that. Please feel free to tear it apart or point out any optimizations or better practices. Please advise with any : thoughts, concerns, etc..
I got motivated the other day and started working on a long time project of mine. I've always wanted to code my very own Dungeons and Dragons Auto Dice Roller. SO, this is my latest attempt. I'm just a noob so be nice:) I wanted to figure out how to pass a variable between classes. I thought this would be a fun way to do that. Please feel free to tear it apart or point out any optimizations or better practices. Please advise with any : thoughts, concerns, etc..
import random def wrapper(): print("=" * 60) print("=" * 60) def logo(): print("*" * 60) print("MIPYTHON.com | Dungeons and Dragons Random Combat Bot") print("*" * 60) class character(object): def __init__(self,name,intro,initiative,movement,attack,defense,damage,hitpoints): self.name = name self.intro = intro self.initiative = initiative self.movement = movement self.attack = attack self.defense = defense self.damage = damage self.hitpoints = hitpoints def main(self): pass def initiative_roll(self): space = " " self.initiative = self.initiative + random.randint(1,10) print(self.name + space + "Initative Roll:") print("Rolls: % for Initiative") % self.initiative return self.initiative def move_roll(self): space = " " self.movement = (self.movement) + random.randint(1,10) print(self.name + space + "Move Roll:") print(self.name + "Rolls: " + space + str(self.movement)) #print(self.movement) #% self.movement #return str(self.name) + " Moves : " return self.movement def attack_roll(self): space = " " self.attack = self.attack + random.randint(1,99) #print("\n Rolls a % To Attack!") % int(self.attack) + random.randint(0,10) #return int(self.attack) + random.randint(0,10) #print(self.name + "Moves : " + self.movement ) #print(self.name + "Rolls For Attack:") print(self.name + space + "Attack Roll:") print(self.name) print("Rolls: %" + space + " for Attack") % self.attack return self.attack def defense_roll(self): space = " " self.defense = self.defense + random.randint(1,99) print(self.name + space + "Defense Roll:") print(self.name) print("Rolls: % for Defense") % self.defense #print(self.defense) return self.defense def damage_roll(self): return self.damage class roll_system(object): def __init__(self): pass #self.combat_resolving = combat_resolving #self.wound_handeling = wound_handeling def main(self): pass def combat_system(self): #print(wrapper()) print(logo()) #print(wrapper()) if player.initiative_roll() >= enemy.initiative_roll(): #player.attack_roll() METHOD FROM CHARACTER CLASS #enemy.defense_roll() METHOD FROM CHARACTER CLASS if player.attack_roll() >= enemy.defense_roll(): #print(wrapper()) print("Player hits Enemy For: ") print(player.damage_roll()) print(enemy.name) #print(enemy.hitpoints - player.damage_roll()) enemy_damage_taken = enemy.hitpoints - player.damage_roll() print(enemy_damage_taken) return enemy_damage_taken #return enemy.hitpoints - player.damage_roll() else: print("Player misses Enemy") else: #enemy.attack_roll() #player.defense_roll() if enemy.attack_roll() >= player.defense_roll(): #print(wrapper()) print("Enemy hits Player For:") print(enemy.damage_roll()) print(player.name) #print(player.hitpoints - enemy.damage_roll()) player_damage_taken = player.hitpoints - enemy.damage_roll() print(player_damage_taken) return player_damage_taken #return player.hitpoints - enemy.damage_roll() else: print("Enemy Misses Player") ### INSTANTIATE CHARACTER CLASSES ### name,intro,initiative,movement,attack,defense,damage,hitpoints BONUSES player = character("Player","Player Intro",3,5,3,3,random.randint(1,10),30) enemy = character("Enemy","Enemy Intro",3,5,3,3,random.randint(1,10),30) ### INSTANTIATE ROLL_SYSTEM CLASS TO HANDLE RANDOM ROLLS #combat = roll_system((player.attack_roll(),enemy.attack_roll()),()) combat = roll_system() combat.combat_system() ### RUNS TWICE combat.combat_system() """run = True while run == True: #combat.combat_system() combat = input("Combat Y or N ?>>>") combat.combat_system() if combat == "N": run = False else: combat.combat_system()""" """while player.hitpoints >= 0 : combat.combat_system() go_again = input("Continue Y or N?>>> ") if go_again == "Y" or go_again == "y": combat.combat_system() else: print("YOU ARE DEAD") else: print("You are Dead")""" #print(player.intro) #print(enemy.intro) #player.initiative_roll() #player.move_roll() #player.attack_roll() #player.defense_roll() #player.initiative_roll() #enemy.initiative_roll() #player.initiative_roll() #enemy.initiative_roll() #print(player.move()) #print(player.movement) #if __name__ == '__main__': # main()