Как получить доступ к элементу в методе моих классов?(Текстовая игра) - PullRequest
0 голосов
/ 09 марта 2019

Так что сейчас я делаю текстовую игру для школьного проекта, и у меня есть проблема, из-за которой я не могу получить доступ к местоположению моего игрока.Ошибка, которую я получаю:

playerInput = input("You are currently in", player.location, ".", player.location, "is", player.location.description)
builtins.TypeError: input expected at most 1 arguments, got 6

Я думал, что смогу решить эту проблему, просто передав один аргумент, но я не уверен, как это сделать.Хотя в моем коде есть другие проблемы, на данный момент это самая большая моя проблема.Зная это и глядя на следующий код, как я могу решить эту проблему?

# Pope Code--------------------------------------------------------------------------------------------------------------#



# Variables------------------------------------------------------------------------------------------------------------#
clock = 24.00

gameExit = False
gameTick = True

playername = "PlaceHolder"
playerbag = []
playerhealth = 10
playerlocation = "PlaceHolder"


# Functions------------------------------------------------------------------------------------------------------------#

def nextTurn(clock):
    gameTick = True
    if clock < 24.00:
        clock += 1.00

# Items----------------------------------------------------------------------------------------------------------------#
class item():

    def __init__ (self, name, description, effect):
        self.name = name
        self.description = description
        self.effect = effect
# Abilities ------------------------------------------------------------------------------------------------------------#
class ability():

    def __init__(self, name, description, usedescription, damage, accuracy, effect):
        self. name = name
        self.description = description
        self.usedescription = usedescription
        self.damage = damage
        self.accuracy = accuracy

Psywave = ability(
    "Psywave",
    "A psyonic move",
    "This move does nothing",
    "5",
    "70",
    "No additonal effect"
)

class entity:
    def __init__(self, name, description, bag, health, psyonics, abilities):
        self.name = name
        self.description = description
        self.bag = bag
        self.health = health
        self.psyonics = psyonics
        self.abilities = abilities

testMonster = entity(
    "Test Monster",
    "A monster used for Testing"
    [5],
    5,
    0.25,
    Psywave,
    Psywave
)
#Locations------------------------------------------------------------------------------------------------------------#

class Zone():
    def __init__(self, name, description, entities, nearby, actions):
        self.name = name
        self.description = description
        self.entities = entities
        self.nearby = nearby
        self.actions = actions

testZone = Zone(
    "Test Zone",
    "This is the placeholder description",
    testMonster,
    "Nothing is nearby",
    "These are the actions you may complete"
)

Forest = Zone(
    "Frenzied Forest",
    "This is the placeholder description",
    testMonster,
    "testZone",
    "These are the actions you may complete"

)

# Entities-------------------------------------------------------------------------------------------------------------#

class player:

    def __init__(self, name, description, bag, location, health, psyonics, abilities):
        self.name = name
        self.description = description
        self.bag = bag
        self.location = location
        self.health = health
        self.psyonics = psyonics
        self.abilities = abilities
player = player(
    "Default",
    "This is the lplayer description",
    [],
    testZone,
    20,
    0.05,
    Psywave
)



# Player Data----------------------------------------------------------------------------------------------------------#
playerInput = "This is the placeholder string"
playerBag = []
playerHealth = 10
placeHolder = ["Test"]

# Graphics-------------------------------------------------------------------------------------------------------------#

def startMenu():
    print("===================================================================")
    print("                                                                   ")
    print("                Welcome to The Shroud                              ")
    print("                                                                   ")
    print("                                                                   ")
    print("                  Enter Anything to continue                       ")
    print("                                                                   ")
    print("                                                                   ")
    playerInput = print("Type Here:                                           ")

# Game Loop------------------------------------------------------------------------------------------------------------#

if gameTick == True and gameExit == False:

    gameTick = False

    playerInput = input("You are currently in", player.location, ".", player.location, "is", player.location.description)

    if playerInput not in player.location.actions:
        print("You cannot perform that action")

    elif playerInput == "End Turn":
        nextTurn()

    elif playerInput == "Bag":
        print("You look into your black backpack. You see", player.bag)

    elif playerInput == "Observe":
        playerInput = print("What would you like to observe?")
        if playerInput == "My items":
            playerInput = print("Which of your items would you like to see? You may look at", player.bag)
            if playerInput in player.bag:
                print(playerInput.description)
            else:
                print("You do not have that item!")
        elif playerInput == "Surroundings":
            print("You use the Sight observe your surroundings. you see a", player.location.description)

    elif playerInput == "Explore":
        playerInput = print("Where would you like to explore?", player.location.nearby)
        if playerInput in player.location.nearby:
            playerlocation = playerInput

if gameExit == True:
    print("You have exited the game")

1 Ответ

2 голосов
/ 09 марта 2019

input принимает только один аргумент, приглашение ввода.Вы можете справиться с этим одним из двух способов.Самый простой - напечатать приглашение отдельно, , затем запросить ввод:

print("You are currently in", 
      player.location, ".", player.location,
      "is", player.location.description)
playerInput = input()

Другой способ - создать приглашение как одну строку, как того требует синтаксис.

playerInput = input("You are currently in" +
      str(player.location) + "." + str(player.location) +
      "is" + player.location.description)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...