【问题标题】:Two Dice game of pig can't get score to reset猪的两个骰子游戏无法重置分数
【发布时间】:2015-02-03 04:30:19
【问题描述】:

这是我在网上找到的代码。我将其修改为掷两个骰子而不是一个,但是当蛇眼滚动时,我无法将分数重置为 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]))

【问题讨论】:

    标签: python if-statement return-value dice


    【解决方案1】:

    好吧,我想这就是它需要修复的方式。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 2013-12-29
      • 2014-02-12
      相关资源
      最近更新 更多