基于文本的RPG的攻击阶段

时间:2016-11-25 02:07:03

标签: python python-3.x

我正试图测试我对编码的不足,并试图学习如何制作基于文本的游戏。这是我的攻击阶段的文本片段,目前我已调试到第36行,其中我收到错误说菜单=输入(">>>")应该缩进,可能我得到一些帮助推过这个,我不明白为什么我收到这个错误。

#-*-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!!!!!!!!!!")

最初的问题已经解决,我修补了代码以配合建议,目前游戏正在循环到else语句抱歉,尚未编程,我输入1,2或任何其他击键。

1 个答案:

答案 0 :(得分:1)

人类和寄养中缺少等号

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

Python从0开始计数,(如C)然后是怪物[3]和人类[3]给出一个IndexError。

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

你不是在改变怪物和人类的生命!

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

小心这个! 只有当它完全等于0才会退出。

if human[1] <= 0:   #Now 

您不检查退出的变量菜单,而是检查人类[1]

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

当然,加入一些roguelike的开发比制作一个新的更好。

相关问题