岩纸剪刀2球员

时间:2016-07-29 15:03:14

标签: python

这是我的2人游戏的代码。我遇到麻烦的是无论如何,玩家2总是赢得并给予玩家2分。有人可以帮助我做到这一点,所以玩家1也可以获胜并获得积分。

def vshuman():

score = [0,0]
    while True:

        while True:
            user1_choice = input("Player 1 choose a weapon (1,2,3,4)")
            user2_choice = input("Player 2 choose a weapon(1,2,3,4)")
            if user1_choice == "1":
                user1_choice == 1
                break
            if user2_choice == "1":
                user2_choice == 1
                break
            elif user1_choice == "2":
                user1_choice == 2
                break
            elif user2_choice == "2":
                user1_choice == 2
                break
            elif user1_choice == "3":
                user1_choice == 3
                break
            elif user2_choice == "3":
                user2_choice == 3
                break
            elif user1_choice == "4":
                user1_choice == 4
                main()
            elif user2_choice == "4":
                user1_choice == 4
                main()

        if user1_choice == user2_choice:
            print("Tie")
            score[0] = score[0] + 1
            score[1] = score[1] + 1
        elif (user1_choice == 1 and user2_choice == 3):
            print("Player 1 won")
            score[0] = score[0] + 1
        elif(user1_choice == 2 and user2_choice == 1):
            print("Player 1 won")
            score[0] = score[0] + 1
        elif(user1_choice == 3 and user2_choice == 2): 
            print("Player 1 won")
            score[0] = score[0] + 1
        elif(user2_choice == 1 and user1_choice == 3): 
            print("Player 2 won")
            score[1] = score[1] + 1
        elif(user2_choice == 2 and user1_choice == 1): 
            print("Player 2 won")
            score[1] = score[1] + 1
        elif(user2_choice == 3 and user1_choice == 2): 
            print("Player 2 won")
            score[1] = score[1] + 1



        while True:
            answer = input("Play another Round")
            if answer == "y" or "Y":
                print(" score: Player 1 -",score[0]," Player 2 -",score[1])

                break
            elif answer == "n" or "N":
                print("I hope you enjoyed! Final score Player 1 -",score[0]," Player 2 -",score[1])

                break
            else:
                print("y or n")

1 个答案:

答案 0 :(得分:0)

score = [0,0]
while 1:
    c1 = int(input("Player 1 choose a weapon (1,2,3) : "))
    c2 = int(input("Player 2 choose a weapon (1,2,3) : "))
    if c1 == c2:
        print('tie')
        score[0] += 1
        score[1] += 1
    elif (c1 - 1) % 3 == c2 % 3:
        print('Player 1 won')
        score[0] += 1
    else :
        print('Player 2 won')
        score[1] += 1
    print(" score: Player 1 -",score[0]," Player 2 -",score[1])
    answer = input("Play another Round (y / n) : ")
    if answer.lower() != "y":
        break