猪的两个骰子游戏不能得分重置

时间:2014-12-05 03:58:13

标签: python if-statement return-value dice

这是我在网上找到的代码。我修改了它来滚动两个骰子而不是一个,但是当蛇眼滚动时,我很难将得分重置为0。我尝试过一些事情,例如从顶部重新分配我的原始值,将分数重置为0但不起作用。我不知所措。

from random import randint

playercount = 2
maxscore = 100
safescore = [0] * playercount
player = 0
score=0

while max(safescore) < maxscore:
    if player == 0:
        rolling = 0
        if score < 17 and score + safescore[player] < maxscore:
            rolling = 1
    else:
        rolling = input("Player %i: (%i, %i) Rolling? (Y) "
            % (player, safescore[player], score)).strip().lower() in {'yes', 'y', ''}
    if rolling:
        rolled = randint(1, 6)
        rolled2 = randint(1, 6)
        print('  Rolled %i' % rolled)
        print('  Rolled %i' % rolled2)
        if rolled ==1 and rolled2 ==1:
                print('  Snake Eyes!! your score is set to 0')

                score, player = 0, (player + 1) % playercount
        elif rolled == 1:
            print('  Bust! you lose %i but still keep your previous %i'
                  % (score, safescore[player]))
            score, player = 0, (player + 1) % playercount
        elif rolled2 == 1:
            print('  Bust! you lose %i but still keep your previous %i'
                  % (score, safescore[player]))
            score, player = 0, (player + 1) % playercount


        else:
            score += rolled + rolled2
    else:
        safescore[player] += score
        if safescore[player] >= maxscore:
            break
        print('  Sticking with %i' % safescore[player])
        score, player = 0, (player + 1) % playercount

print('\nPlayer %i wins with a score of %i' %(player, safescore[player]))

1 个答案:

答案 0 :(得分:0)

我发现这就是需要修复的方法。

if rolled ==1 and rolled2 ==1:
                print('  Snake Eyes!! your score is set to 0')
                safescore[player] = 0    
                player = (player + 1) % playercount