Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

wolfman456

New Coder
HI,
This is my first post, I have read several post at this point and it looks like you are all a very helpful group and I hope you all are able to assist me and that I will be able to help others in the future. The following project is my first attempt to right a project completely from scratch and it has gotten a bit out of hand.

This code started as a choose your own adventure, but I wanted to added some elements based on D&D to it, which has resulted in it spanning three self created modules now. As I don't want to give a wall of code, I will try to do this piece meal but if I am not giving enough information please let me know.

[CODE lang="python" title="gamefuction.py"]from character import Monster, character
import random
from random import randint
import items

#Combat Function
class Die:
# a class to represent rolls

def __init__(self, sides=20):
self.sides = sides

def roll(self):
#roll the dice
return random.randint(1, self.sides)


def PlayerAttack():
roll= Die(20) + items.wBonus
if roll >= character.Monster.ac:
print('You Hit')
items.weapons.damage - Monster.hp
else:
print('You missed')

def MonsterAttack():
roll= Die(20)
if roll >= character.adventurer.ac:
print('You were hit')
character.Monster.damage - character.adventurer.hp
else:
print('That was close')
[/CODE]

Above is the combat function for this game, I have two issues hear, one I don't know how to implement it in to the main game when a player chooses a path that would result in combat. The second having to do with how to pull the right monster or monster, for the combat for that particular round. The final issue is more on the character side so to try and not ask to much at once I will leave this issues for another post, unless someone tells me they need the monster code as that is part of the same module as the character.

I am sorry for any rambling here, and will work to be more concise in the future. Thank you in advance for any assistance.
 
Last edited by a moderator:
Your project looks great!

I do not really understand your question? You could print out a menu and the player could choose from those options. If he chooses to figh a monster, you generate a monster and start the fight.

Example:
Python:
# *** Print the items of the menu ***
choice = input("Your choice: ")

# As long as the player does not want to quit.
while not choice == 6: # Let us assume the item number 6 is quitting the game.
    if choice == 2: # Let us assume the item number 6 is starting a fight.
        # You handle the fight. You may call a function for that.
    
    # *** Print the items of the menu ***
    choice = input("Your choice: ")
 
okay that helps. I didn't think about just printing a list of the inventory weapons and having selecting before the start of a fight. I guess I over thought the issue, in my head. Happens.... and the monster, I take it you are suggesting i just monster = before the battle to call the monster.
 

New Threads

Buy us a coffee!

Back
Top Bottom