【问题标题】:Python coding for online Game - Pizzeria chose story Game.在线游戏的 Python 编码 - Pizzeria 选择了故事游戏。
【发布时间】:2023-03-04 04:21:01
【问题描述】:

我一直在获取正确的编码。如果您碰巧运行此代码,请更正您认为合适的内容。我已经搜索过了,这里和那里仍然存在错误。这里是游戏编码。定义术语中可能存在一些问题,我仍在学习 Python 词汇来定义新项目,但没有找到正确的答案。这是您可以运行和尝试的代码。谢谢:

import random
import time

def displayIntro():
    print("You are in a city. In front of you,")
    print("you see two restraunts. In one pizzeria, the service is friendly")
    print("and will share thier free pizza with you. The other pizzeria")
    print("is very unpredictable and will hire you to wash the dishes in the back quick.!")
    print()

def choosePizzeria():
    pizzeria=""
    while((pizzeria != "1") and (pizzeria != "2")):
        print("Which pizzeria will you go into? (1 or 2) ")
        pizzeria = input()

    return pizzeria

def checkPizzeria(level,(pizzeria != "1") or (pizzeria != "2")):
    print("You approach the pizzeria and see people hustling in and out quickly...")
    time.sleep(2)
    print("It really crowded with people waiting in line, playing arcade games and just having a good time dancing...")
    time.sleep(2)
    print("A little manager with a suit steps in in front of you! He quickly slips his arm behind his back...")
    print()
    time.sleep(2)

    friendlypizzeria = random.randint(1, 3)
    overworkPizzeria = friendlypizzeria + 1
    if overworkPizzeria > 3:
      overworkPizzeria -= 3

    if chosenPizzeria == str(friendlyPizzeria):
        print("Hand you a slip of paper for two free pizzas!")
    elif chosenPizzeria == str(overworkPizzeria):
          print("He hands you a slip of paper telling you to watch the dishes in the back for a while since you stared at him too long!")
    else:
          level += 1
    if level < 3:
        print("You quickly hid behind some customes and head out to 3 more pizzerias")
    else:
        print("Congratulations you win two free pizzas and")
        print("you get to go to the manager's weekend party!!!! ")

    return level

playAgain = "yes"
while playAgain == "yes" or playAgain == "y":

    displayIntro()
    level = 0

    pizzeriaNumber = choosePizzeria()

    level = checkPizzeria(level,pizzeriaNumber)

    if level == 1:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)

    if level == 2:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)


    print('Do you want to play again? (yes or no)')
    playAgain = input()

谢谢。

【问题讨论】:

  • Stack Overflow 不是调试服务。尝试将您的问题分解为更小的问题,并详细说明您尝试解决的方法。

标签: python python-3.x social-gaming


【解决方案1】:

主要是语法错误,我建议阅读一些 Python 文档。特别是关于类型和比较运算符。但下面会运行;

import random
import time

def displayIntro():
    print("You are in a city. In front of you,")
    print("you see two restraunts. In one pizzeria, the service is friendly")
    print("and will share thier free pizza with you. The other pizzeria")
    print("is very unpredictable and will hire you to wash the dishes in the back quick.!")
    print()

def choosePizzeria():
    pizzeria=""
    while((pizzeria != 1) and (pizzeria != 2)):
        print("Which pizzeria will you go into? (1 or 2) ")
        pizzeria = input()

    return pizzeria

def checkPizzeria(level, pizzariaNumber):
    print("You approach the pizzeria and see people hustling in and out quickly...")
    time.sleep(2)
    print("It really crowded with people waiting in line, playing arcade games and just having a good time dancing...")
    time.sleep(2)
    print("A little manager with a suit steps in in front of you! He quickly slips his arm behind his back...")
    print()
    time.sleep(2)

    chosenPizzeria = pizzariaNumber
    friendlypizzeria = random.randint(1, 3)
    overworkPizzeria = friendlypizzeria + 1
    if overworkPizzeria > 3:
      overworkPizzeria -= 3

    if chosenPizzeria == friendlypizzeria:
        print("Hand you a slip of paper for two free pizzas!")
    elif chosenPizzeria == overworkPizzeria:
          print("He hands you a slip of paper telling you to watch the dishes in the back for a while since you stared at him too long!")
    else:
          level += 1
    if level < 3:
        print("You quickly hid behind some customes and head out to 3 more pizzerias")
    else:
        print("Congratulations you win two free pizzas and")
        print("you get to go to the manager's weekend party!!!! ")

    return level



playAgain = "yes"
while playAgain == "yes" or playAgain == "y":

    displayIntro()
    level = 0

    pizzeriaNumber = choosePizzeria()

    level = checkPizzeria(level,pizzeriaNumber)

    if level == 1:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)

    if level == 2:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)


    print('Do you want to play again? (yes or no)')
    playAgain = raw_input()

【讨论】:

  • 谢谢。为人们完成这些工作很匆忙,对于 Python 的真正简单、易于理解的内容,并没有太多的文档。我会为今天仍然申请的游戏制造商提供好的建议。
  • 杰西,我肯定在查你的资料。
猜你喜欢
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-14
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多