简体   繁体   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.

I have this code which is right now complete. 我已经完成了这段代码。 One thing i wanted to add is a round system to the game. 我想添加的一件事是游戏中的圆形系统。 Where the user chooses between 1-10 rounds and depending oh the choice the game will cycle that many rounds before hitting the play again statement. 用户在1-10个回合之间进行选择,然后根据选择进行选择,游戏将循环多次回合,然后再次按下播放语句。 I tried to use a input() statement but then i ran into the problem of having n int statement when running a while or for loops. 我试图使用input()语句,但是随后在运行whilefor循环时遇到了n个int语句的问题。 Thank you 谢谢

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

There ya go I changed the input() to raw_input() in some parts and fixed some spelling mistakes. 在某些地方,我将input()更改为raw_input()并修复了一些拼写错误。 See if it works for you 看看是否适合您

暂无
暂无

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

相关问题 如何在我的石头剪刀布游戏中再添加一轮 - How can I add another round to my Rock Paper Scissors game 如何用更少的代码行制作我的基本的 Rock/Paper/Scissors 游戏? - How do I make my basic Rock/Paper/Scissors game with fewer lines of code? 如何使我的Rock,Paper和剪刀游戏的代码不那么多余? - How can I make my code for a game of Rock, Paper, and scissors less redundant? 尝试使用 tkinter 编写“剪刀石头布”游戏。 但是我的编码没有给出我想要的,并且没有发生错误 - Trying to code 'rock paper scissors' game with tkinter. But my coding doesn't give what i want, and no error has occured 我的部分代码在 vscode 中无法访问,我正在尝试构建基本的剪刀石头布游戏 - part of my code is unreachable in vscode, Iam trying to build basic rock paper scissors game 我正在使用 python 3.9,但我不知道如何在我的 Windows 10 中安装 pyaudio - I am using python 3.9 and I can't figure out how to install pyaudio in my Windows 10 如何纠正我在石头剪刀布游戏中的错误 - How to correct my errors in my Rock, Paper, Scissors game 我能做些什么来修复我的石头剪刀布代码以保持分数并结束游戏 - What can I do to fix my Rock, Paper, Scissors code to keep score and to end the game 我正在使用 Tkinter 在 Python 中制作剪刀石头布游戏。 我的分数工作不正常 - I'm Making a Rock Paper Scissors game in Python with Tkinter. My Score isn't Working Properly python - 我在哪里检查我的石头剪刀布游戏中的有效输入 - python - Where do I check for valid input in my rock paper scissors game
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM