简体   繁体   English

我不知道如何在我的游戏中显示可供用户选择的课程列表?

[英]I don't know how to show a list of classes for user to choose from in my game?

I'm making a text-adventure game called Glaux.我正在制作一款名为 Glaux 的文字冒险游戏。 This game is an RPG game, but it's on text.这个游戏是一个RPG游戏,但它是文字。 my problem is how to show the user 3 classes that he can choose from by typing an option but I don't know how.(code provided below).我的问题是如何向用户显示他可以通过键入一个选项来选择的 3 个类,但我不知道如何。(下面提供了代码)。

import random
class Warrior:
    def __init__(self, name, health, steel_armor, healing_potion, attack, rage):
        self.name = input(print("Enter your name, Warrior!"))
        self.health = health
        self.steel_armor = steel_armor
        self.healing_potion = healing_potion
        self.attack = attack
        self.rage = rage
class Mage:
    def __init__(self, name, health_magic, magic_armor, magic_heal, magic_attack, mana):
        self.name = input(print("Enter your name, Mage!"))
        self.health = health_magic
        self.magic_armor = magic_armor
        self.magic_heal = magic_heal
        self.magic_attack = magic_attack
        self.mana = mana
class Archer:
    def __init__(self, name, health_spirit, elevens_armor, spiritual_heal, spiritual_attack, spirit):
        self.name = input(print("Enter your name, Archer!"))
        self.health = health_spirit
        self.elevens_armor = elevens_armor
        self.spiritual_heal = spiritual_heal
        self.spiritual_attack = spiritual_attack
        self.spirit = spirit
def Classes(Warrior, Mage, Archer):
        Classes = (Warrior, Mage, Archer)
Play = input

run = True


main_menu = True
while run:
    while main_menu:
        question = input("To play enter [Play]: ")
        if question != 'Play':
                print("Please enter a valid option")
                continue
        else:
            break
    print("you were a....."), # here i want to begin the part after main_menu the game will ask the user to choose between 3 classes so how to show the user those 3 classes ?
    print("Choose your class!")
    input(Classes('Warrior', 'Mage', 'Archer'))

    break

You can do it like that:你可以这样做:

You define a method Classes that is doing some weird stuff which I don't know what your intention was but you should change:你定义了一个方法 Classes ,它正在做一些奇怪的事情,我不知道你的意图是什么,但你应该改变:

def Classes(Warrior, Mage, Archer):
    Classes = (Warrior, Mage, Archer)

into something like this:变成这样:

classes = ["Warrior", "Mage", "Archer"]

A list with all available classes.包含所有可用类的列表。

After that you can let the player choose his class like this:之后,您可以让玩家像这样选择他的职业:

player_class = input(classes)
    while player_class not in classes:
        player_class = input(classes)
    print("You are: {}".format(player_class))

You should probably make the output a bit more beautiful but it works with this.您可能应该使输出更漂亮一点,但它适用于此。

Output:输出:

To play enter [Play]: Play
Choose your class!
['Warrior', 'Mage', 'Archer']Warrior
You are: Warrior

Add the following function添加以下功能

def get_input(*names):
    while True:
        try:
            for i, name in enumerate(names, 1):
                print('[{:>2}] {}'.format(i, name))
            choice = int(input()) - 1
            if choice >= 0 and choice < len(names):
                return names[choice]
        except Exception:
            print('Bad choice, try again...')

Use it like this - get_input('Warrior', 'Mage', 'Archer')像这样使用它 - get_input('Warrior', 'Mage', 'Archer')

Output example:输出示例:

To play enter [Play]: Play
you were a.....
Choose your class!
[ 1] Warrior
[ 2] Mage
[ 3] Archer
4
[ 1] Warrior
[ 2] Mage
[ 3] Archer

Bad choice, try again...
[ 1] Warrior
[ 2] Mage
[ 3] Archer
dd
Bad choice, try again...
[ 1] Warrior
[ 2] Mage
[ 3] Archer
fdsg
Bad choice, try again...
[ 1] Warrior
[ 2] Mage
[ 3] Archer
1
Warrior

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hangman Game - IndexError: list index out of range - 这是因为我在第 89 行的 for 循环,但我不知道如何修复它 - Hangman Game - IndexError: list index out of range - It's because of my for loop on line 89 but I don't know how to fix it 我不知道如何让用户选择一个选项和 output 在 Tkinter 上的好结果 - I don't know how to make a user choose an option and output the good result on Tkinter 当我不知道要花多长时间时,如何显示QProgressDialog? - How do I get my QProgressDialog to show up when I don't know how long it will take? 我正在努力从叶子上盖起霍夫曼树。 我有我的排序列表,但不知道如何进行 - I am struggling to build a Huffman tree from the leaves up. I have my sorted list, but don't know how to proceed 我不知道如何用我的 Python 语句只显示一次错误消息 - I don't know how to only show error message once with my Python statement 我的清单中包含重复的元素,我不知道为什么 - My list is taking repeat elements and I don't know why 我想清理 Python 中的列表,但我不知道该怎么做 - I want to clean my list in Python but I don't know how to do 我正在尝试制作 2 人 tron 游戏,但我不知道如何进行游戏开始倒计时 - I'm trying to make a 2 player tron game, and I don't know how to make a countdown to start the game 我不知道如何以相同的形式显示我的customuser和user - I don't know how to display my customuser and user in same form 我需要在我的游戏中生成一些随机图像,但我现在不知道 - I need some random image spawn in my game but i just don't know now
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM