简体   繁体   中英

Python coding for online Game - Pizzeria chose story Game.

I am stayed in getting the right coding. If you happen to run this code, please correct what you see fit. I have searched and there continues to be bugs here and there. Here is the game coding. There may be some issues in the definition terms and I'm still learning the Python vocabulary to defined new items and am not finding right answers. Here is the code that you can run and try. Thank you:

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()

Thank you.

Mostly Syntax errors, I would suggest reading some Python documentation. Especially in regards to Types, and Comparison Operators. But below will run;

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM