Python:如何为纸牌游戏绘制一组新的不同牌?

问题描述 投票:0回答:1

我正在寻找一些关于我正在进行的简单纸牌游戏的帮助。前提是:

  • 30张牌在牌组中洗牌,其中包含红色,蓝色和黄色,每个牌都有数字1-10
  • 2名玩家从这个牌组的顶部收到一张牌
  • 某些颜色会击败另一种颜色
  • 获胜者将获得两张牌
  • 重复该过程,直到甲板上没有剩余的矿卡。

我的问题是,我无法找到一种方法,一旦第一次结束就有新牌。我的代码改为调用已经播放的卡片(这会导致错误)。有没有什么有效的方法我可以在使用我的代码时绘制新卡?谢谢。

import random

Deck = ['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'R10', 'Y1', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7', 'Y8', 'Y9', 'Y10', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10']
random.shuffle(Deck)
print(Deck)

Player1Card = Deck[0]
print("Player One, Your Card Is {0}" .format(Deck[0]))
Player2Card = Deck[1]
print("Player Two, Your Card Is {0}" .format(Deck[1]))

PlayerOneScore = 0
PlayerTwoScore = 0
GameCount = 0
PlayerOneCardList = list()
PlayerTwoCardList = list()


1 < 2
2 < 3
3 < 4
4 < 5
5 < 6
7 < 8
8 < 9
9 < 10

while GameCount == 0:

if "R" in Player1Card and "B" in Player2Card:
    print("Player One Wins")
    PlayerOneScore = PlayerOneScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))
    PlayerOneCardList.append(Player1Card)
    PlayerOneCardList.append(Player2Card)

    print("Player 1, These Are Your Currently Held Cards:")
    print(PlayerOneCardList)
    print("Player 2, These Are Your Currently Held Cards:")
    print(PlayerTwoCardList)

    Deck.remove(Player1Card)
    Deck.remove(Player2Card)


elif "R" in Player2Card and "B" in Player1Card:
    print("Player Two Wins")
    PlayerTwoScore = PlayerTwoScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))

elif "B" in Player1Card and "Y" in Player2Card:
    print("Player One Wins")
    PlayerOneScore = PlayerOneScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))

elif "B" in Player2Card and "Y" in Player1Card:
    print("Player Two Wins")
    PlayerTwoScore = PlayerTwoScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))

elif "Y" in Player1Card and "R" in Player2Card:
    print("Player One Wins")
    PlayerOneScore = PlayerOneScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))

elif "Y" in Player2Card and "R" in Player1Card:
    print("Player Two Wins")
    PlayerTwoScore = PlayerTwoScore+2
    print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))






elif "Y" in Player1Card and "Y" in Player2Card:
    if Player1Card > Player2Card:
        print("Player One Wins")
        PlayerOneScore = PlayerOneScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))
    elif Player1Card < Player2Card:
        print("Player Two Wins")
        PlayerTwoScore = PlayerTwoScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))







elif "B" in Player1Card and "B" in Player2Card:
    if Player1Card > Player2Card:
        print("Player One Wins")
        PlayerOneScore = PlayerOneScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))
    elif Player1Card < Player2Card:
        print("Player Two Wins")
        PlayerTwoScore = PlayerTwoScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))








elif "R" in Player1Card and "R" in Player2Card:
    if Player1Card > Player2Card:
        print("Player One Wins")
        PlayerOneScore = PlayerOneScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))
    elif Player1Card < Player2Card:
        print("Player Two Wins")
        PlayerTwoScore = PlayerTwoScore+2
        print("Player One, your score is {0} and Player Two, your score is {1}" . format(PlayerOneScore, PlayerTwoScore))



if PlayerOneScore + PlayerTwoScore == 30:
    if PlayerOneScore > PlayerTwoScore:
        print("Player One Wins")
        print("The game is over")
        gamecount = 1
    elif PlayerTwoScore > PlayerOneScore:
        print("Player Two Wins")
        print("The game is over")
        gamecount = 1
else:
    gamecont1  = input("Would you like to continue the game Y for yes or N for no?")
    if gamecont1 == "Y" or "y":
        gamecont = 0
    else:
        gamecont = 1
python
1个回答
0
投票

我建议您在画完这样的卡后立​​即使用.remove()声明

Player1Card = Deck[0]
print("Player One, Your Card Is {0}" .format(Deck[0]))
Player2Card = Deck[1]
print("Player Two, Your Card Is {0}" .format(Deck[1]))

Deck.remove(Player1Card)
Deck.remove(Player2Card)

这样可以确保当前的卡片不会被卡片挑选。

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.