簡體   English   中英

我試圖弄清楚如何在我的Rock Paper Python游戲中的代碼中添加1-10的舍入系統。

[英]I am trying to figure out how to add a round system of 1-10 on my Rock Paper Python game in my code.

我已經完成了這段代碼。 我想添加的一件事是游戲中的圓形系統。 用戶在1-10個回合之間進行選擇,然后根據選擇進行選擇,游戲將循環多次回合,然后再次按下播放語句。 我試圖使用input()語句,但是隨后在運行whilefor循環時遇到了n個int語句的問題。 謝謝

stored_users = {'jason': 'oeros', 'nicole': 'chance'}
# goes through the funtions in order
def main():

    check_sign_in()

    login()or add_user()

    RockPaperPython()

#asks if you have an account already
def check_sign_in():

    print('Do you want to sign in or create a new user?')

    user_choice = input( 'Create User or Sign In')
    if user_choice == 'Create User':
        add_user()
    if user_choice == 'Sign In':
        login()


# Adds a username and password to the database   
def add_user():
    print('Creating user, \n please create username and password')
    username = input('Username: ')
    password = input('Password: ')
    if stored_users.get(username):
        print('Username already exiss')
        add_user()
    else:
        stored_users[username] = password
        login()

#trails = a counter to see how many tries the user has used to find his info        
trials=0 

# Lets a user sign in, but he has only three attempts
def login():
    global stored_users
    global trials
    print('Please sign in')

    while trials < 3: 
        print('Logging in')
        username = input('Username: ')
        password = input('Password: ')
        if stored_users.get(username) == password:
           print ('Welcome to Rock Paper Python')
           RockPaperPython()
           return True

        else:
            trials += 1
            print ('Wrong username or password')
        if trials >=2 and trials <3 :
            print('if username and password if entered wrong one more time, program will exit')
        if trials >=3:
            exit()

#point system for rock paper python
computer_points=0
user_points=0

#Rock Paper Python the game 
def RockPaperPython():
    print('\nReady to Play Rock Paper Python')




    user_choice = input("\nEnter rock, paper, or python:\n")
    global computer_points
    global user_points
    import random
    my_list = ['rock','paper','python']
    computer_choice = random.choice(my_list)
    print(computer_choice)
    if user_choice == computer_choice:
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('TIE')
    elif user_choice == 'rock' and computer_choice == 'python':
        user_points +=1
        print('User points =', user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    elif user_choice == 'paper' and computer_choice == 'rock':
        user_points +=1
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    elif user_choice == 'python' and computer_choice == 'paper':
        user_points +=1
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    else:
        print('You lose :( Computer wins :D')
        computer_points += 1
        print('User points =',user_points)
        print('Computer Points=',computer_points)


        Play_Again= input('Play Again? Yes or NO')
    if Play_Again == 'Yes':
        RockPaperPython()

    else:
        print('Thanks for Playing')
        main()

main()
stored_users = {'jason': 'oreos', 'nicole': 'chance'}
# goes through the funtions in order
def main():

    check_sign_in()

    login()or add_user()

    RockPaperPython()

#asks if you have an account already
def check_sign_in():

    print('Do you want to sign in or create a new user?')

    user_choice = raw_input( 'Create User or Sign In? ')
    if user_choice == 'Create User':
        add_user()
    if user_choice == 'Sign In':
        login()


# Adds a username and password to the database   
def add_user():
    print('Creating user, \n please create username and password')
    username = input('Username: ')
    password = input('Password: ')
    if stored_users.get(username):
        print('Username already exist')
        add_user()
    else:
        stored_users[username] = password
        login()

#trails = a counter to see how many tries the user has used to find his info        
trials=0 

# Lets a user sign in, but he has only three attempts
def login():
    global stored_users
    global trials
    print('Please sign in')

    while trials < 3: 
        print('Logging in')
        username = raw_input('Username: ')
        password = raw_input('Password: ')
        if stored_users.get(username) == password:
           print ('Welcome to Rock Paper Python')
           RockPaperPython()
           return True

        else:
            trials += 1
            print ('Wrong username or password')
        if trials >=2 and trials <3 :
            print('if username and password if entered wrong one more time, program will exit')
        if trials >=3:
            exit()

#point system for rock paper python
computer_points=0
user_points=0

#Rock Paper Python the game 
def RockPaperPython():
    print('\nReady to Play Rock Paper Python')


    cycles = int(raw_input("Enter how many rounds you want to play: "))
    for i in range(1, cycles):
        user_choice = raw_input("\nEnter rock, paper, or python:\n")
        global computer_points
        global user_points
        import random
        my_list = ['rock','paper','python']
        computer_choice = random.choice(my_list)
        print(computer_choice)
        if user_choice == computer_choice:
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('TIE')
        elif user_choice == 'rock' and computer_choice == 'python':
            user_points +=1
            print('User points =', user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        elif user_choice == 'paper' and computer_choice == 'rock':
            user_points +=1
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        elif user_choice == 'python' and computer_choice == 'paper':
            user_points +=1
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        else:
            print('You lose :( Computer wins :D')
            computer_points += 1
            print('User points =',user_points)
            print('Computer Points=',computer_points)

    Play_Again= input('Play Again? Yes or NO')
    if Play_Again == 'Yes':
        RockPaperPython()

    else:
        print('Thanks for Playing')
        main()

main()

在某些地方,我將input()更改為raw_input()並修復了一些拼寫錯誤。 看看是否適合您

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM