Cameron Locke
Cameron Locke

Reputation: 13

attack phase for text based rpg

I am trying to just test my undersanding of coding and trying to learn how to make a textbased game. This is a snippet of text for my attack phase, currently i have debugged to line 36 in which i get an error saying menu = input(">>>") should be indented, might i get some help to push past this, i dont get why I am recieving that error.

#-*-coding:utf8;-*-
#qpy:3
#qpy:console
#basic attack for an rpg text based game
from random import randint
#dice function
def die(sides):
    return (randint(1, sides))
# the two object fighting created as lists, later to be used as classes
human = [2, 25, 5]
monster = [1, 20, 2]
#setting the input bar
menu = 0
#attack and defence phase for the game
def attackphase():
    while menu != 2:
        menu == 0
        x = (human[0] + die(20)) - monster[2]  #calulations for damage
        y = (monster[0] + die(20)) - human[2]
        print("You dealt", x, "to the monster")
        monster[1] -= x
        if monster[1] > 0: #monster returns attack
            print("Monster dealt", y, "to you.")
            human[1] -= y
        else:
            print("You killed the monster")
            print("Congrats your game works")
            menu == 2
        if human[1] <= 0:   #to end game state
            menu == 2
#game state
while menu!= 2:
    print("What would you like to do")
    print('''1. Attack
    2. Quit''')
    menu = input(">>>")
    if menu == 1:
        attackphase()
    else:
        print("sorry, that has not yet been programed")
print("Wooot, Wooot, Wooot!!!!!!!!!!")

The initial issue was solved, I patched code to match with advice, presently the game is looping to the else statement sorry, that has not yet been programmed, wether i enter 1, 2, or any other keystroke.

Upvotes: 0

Views: 475

Answers (1)

Lucas
Lucas

Reputation: 7341

The equals are missing in human and moster

human = [2, 25, 5]
monster = [1, 20, 2]

Python starts counting from 0, (like C) then monster [3] and human [3] give an IndexError.

 x = (human[0] + die(20)) - monster[2]  #you can use moster[-1] too!
 y = (monster[0] + die(20)) - human[2]

You are not changing the life of the monster and the human!

    monster[1] -= x # This is equal to
    human[1] -= y   # >>>human[1] = human[1] - y

Beware of this! Only if it is exactly equal to 0 will exit.

if human[1] <= 0:   #Now 

You do not check the variable menu to exit, but human [1]

while menu != 2: #instead of >>>while human[1] > 0:

Surely it is better to join the development of some roguelike than to make a new one.

Upvotes: 1

Related Questions