Help with very basic game program

A forum for general discussion of the Python programming language.

Help with very basic game program

Postby bjh1414 » Tue Mar 25, 2014 6:12 pm

I need some help with a simple “dungeon crawl” game, in which the player encounters a series of random monsters, which they then fight and then collect treasure if they survive. Hear is what i have thusfar:

Code: Select all
#You need to import random module
import random
#Initialize all constants
ZOMBIE_HIT_POINTS = 5
ZOMBIE_MAX_DAMAGE = 3
ZOMBIE_TREASURE = 10

TROLL_HIT_POINTS = 10
TROLL_MAX_DAMAGE = 6
TROLL_TREASURE = 20

DRAGON_HIT_POINTS = 25
DRAGON_MAX_DAMAGE = 15
DRAGON_TREASURE = 100
#Do this for remaining monsters
#set initial hit points of player and treasure points
PLAYER_HIT_POINTS = 50
PLAYER_MAX_DAMAGE = 10
keep_playing = "yes"
dead = PLAYER_HIT_POINTS <= 0
           
#put condition for outer loop
while not dead and keep_playing == "yes":
#Generate monsters

    monster_type = random.random()
    if monster_type <= 0.5:
        print ("You have encountered a zombie")
        monster_points = ZOMBIE_HIT_POINTS
        monster_damage = ZOMBIE_MAX_DAMAGE
        monster_treasure = ZOMBIE_TREASURE
        monster_name = "zombie"
    elif monster_type > 0.5 <= 0.9:
        print ("You have encountered a troll")
        monster_points = TROLL_HIT_POINTS
        monster_damage = TROLL_MAX_DAMAGE
        monster_treasure = TROLL_TREASURE
        monster_name = "troll"
    elif monster_type:
        print ("You have encountered a dragon")
        monster_points = DRAGON_HIT_POINTS
        monster_damage = DRAGON_MAX_DAMAGE
        monster_treasure = DRAGON_TREASURE
        monster_name = "dragon"

       
   

     
    #Use the above logic for creating other monsters
#Create inner loop

           while monster_points > 0 and not dead > 0:
    #logic for battle between player  and monster
# update the hit points of monster and player
       

#check if  player and monster hit points are less than or equal to zero.
           if hit_points <= 0:
            dead = True
            print("Alas, you have fallen!")

#use same logic as above to check for monster hit points   
#prompt user if he wants to continue         
    if not dead:
        keep_playing = input("Do you wish to keep exploring (yes or no)? ")


Very basic stuff, just need help finishing the program. For some reason a dragon wont currently generate. Thanks for the help
Last edited by stranac on Tue Mar 25, 2014 6:16 pm, edited 1 time in total.
Reason: Added code tags. Locked.
bjh1414
 
Posts: 2
Joined: Tue Mar 25, 2014 6:07 pm

Re: Help with very basic game program

Postby stranac » Tue Mar 25, 2014 7:05 pm

The problem is your conditionals. Specifically, this line:
Code: Select all
    elif monster_type > 0.5 <= 0.9:

That's the same as:
Code: Select all
    elif monster_type > 0.5 and 0.5 <= 0.9:

The second part is always true, so this loop is executed whenever monster_type > 0.5.

You probably wanted:
Code: Select all
    elif 0.5 < monster_type <= 0.9:
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1109
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help with very basic game program

Postby bjh1414 » Wed Mar 26, 2014 12:59 am

OH yeah, duh. thanks for the help on that. anybody want to take a crack at making the problem function atleast slightly. i just started out and would love to toy with the ending parts after it is all set up. I know its some work, but i have too many questions. but once i have this code done as a base, i can work on much more. ex: blackjack, roulette, other odds games.
bjh1414
 
Posts: 2
Joined: Tue Mar 25, 2014 6:07 pm

Re: Help with very basic game program

Postby dboxall123 » Wed Mar 26, 2014 10:43 am

Change:

Code: Select all
elif monster_type:


to

Code: Select all
else:
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests