Python Forum
Need help with a few things as a beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a few things as a beginner
#1
Well being new to coding I'm having quite a rough time, I followed a tutorial on how to make an EXTREMELY simple text based game, which is the only game I've ever coded, let alone almost the only thing I've coded.

I gained quite a lot of experience from following the tutorial even though some parts where not efficent or even needed in the code. For that reason I decided to recode a new text based game with my gained experience, and so far so good. I got to almost where I left of on the first game.


This is how far I've gotten:

from random import randint

#Characters
player = {"name": 'temp', 'hp': 50, 'dmg_min': 0, 'dmg_max': 3, 'heal_min': 5, 'heal_max': 25}
boss = {'name': 'Kanashi', 'hp': 100, 'dmg_min': 5, 'dmg_max': 15}


#All weapons in the game
weapons = {'barehands': 0, 'knife': 5, 'sword': 10}

## if player gets a sword
#player['weapon'] += weapons['sword']
#damage = player['attack'] + player['weapon']
#monster['health'] -= damage
#print(f'Damage done = {damage} Monster stats:{monster}')


##Player abilities
def player_attack():
    return randint(player['dmg_min'], player['dmg_max'])
def player_heal():
    return randint(player['heal_min'], player['heal_max'])

##Boss abilities
def boss_attack():
    return randint(boss['dmg_min'], boss['dmg_max'])


##Win conditions
player_won = False
boss_won = False


#print('Game Started')
##Choose name or enter Highscores

##The interactive part of the game
while not (player_won or boss_won):
    print('---' * 10)
    print('What will you do:')
    print('1). Attack Target\n2). Use Heal')
    print('---' * 10)
    print(player["name"] + "'s HP: " + str(player["hp"]))
    print(boss["name"] + "'s HP: " + str(boss['hp']))

    player_choice = input()

    if player_choice == '1':
        boss['hp'] = boss['hp'] - player_attack()
        if boss['hp'] <= 0:
            player_won = True
        else:
            player['hp'] = player['hp'] - boss_attack()
            if player['hp'] <= 0:
                boss_won = True

    if player_choice == '2':
        player['hp'] = player['hp'] + player_heal()
        player
    else:
        print('Invalid Input')
I'm sorry if I'm asking for too much from you instead of looking it up. It's at this point I understood this was too complicated and I should continue with small projects. If that's the case, there is only one thing I want help with, and that is to implement my first thing on the todo list, the text's after every option. This is the part I'm going to spend the most time on and have the most fun with, kind of like writing a book, but in a video game, right?

The things I need help with are listed below, in order from what I want the most to least ( Tips, or if you actually want to take your free time and implement a code from the "Todo list" into my codes I couldn't thank you enough, even if it's simple for you :D ):

Todo list:
1. Add messages after selecting an option. Such as, after I enter "1" (attack) it would print a message like"The boss spews fire towards me, I quickly roll forward and thrust my "weapon" into his leg blablabla" and below the message I want to add how much damage I dealt and took "player['name] dealt 7 damage". I want the printed text to be randomly chosen between a select amount of already written messages, so the player doesn't always get the same one.

2. Add "run further into cave" (This will cancel the boss's attack and there will be 3 types of rooms with different encounter chance).

3. Add an encounter chance for the rooms. Example: Weapons room has a chance of 10%, Damage room 25%, Nothing room 65%

4. Add Weapons chance. Example: The chance of discovering a rusty_sword when encounter Weapons room is 90%, legendary_sword 10%

5. Add "Pick up weapon from groud" when encounter Weapons room
It will first display a text eg "You see something behind the rock"
Afterwards, an option to "check" the item.
When player chose "check", a new text appears telling player what weapon it is "You found a Legendary Sword", and two new options:
"Equip weapon" and "Don't equip weapon"

(this part is where I can imagine it getting complicated, if it already isn't and honestly you don't need to write the rest of the code)

If player already has a weapon equipped, a new option will appear:
"Unequip current 'weapon' and equip the weapon on the ground"
Unequipping the current weapon, will remove that weapons value and a unique message will appear:
"You throw away your current weapon and pick up the weapon on the ground"

6. Make the healing ability have a cast time (which would be 1 round), when casting, the Boss will attack you once, however if you

7. Max hp, making the player's hp not go above the set amount "50hp" when using the heal ability
Reply
#2
Some notes to get you started:

1) Make a variable like player, but assign a list of messages to it. Use random.choice() to pick one of the messages. Use the format method of strings to insert the values into the strings, like damage done. Note that you will need to save that. Currently you just subtract it on line 49. You'll want assign the result of player_attack to a variable, subtract that from the enemy's hit points, and then use it with the format method to display the string.

2) First you need to add the option to line 41. Then, note that line 57 should be elif, not if. This will connect the else on line 60 to the if on line 48. As it is currently selecting 1 will do the attack and print 'Invalid input'. This will fix that. Then you will need to add another elif to handle choice '3' before the else on line 60. At this point you are getting into moving through rooms and picking up items. For that, read through my text adventure tutorial.

6) for this I would have a flag (a variable with a boolean variable) called heal_next_round or something. Before checking for the choices, you check that, and if it's true you do the healing and set the flag to false. Then if they choose to heal you set the flag to true and do the bad guy's attack.

7) To add y to x with a maximum of z, I usually use min: foo = min(x + y, z).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020