0
我一直在修改骰子游戲豬的代碼。我將它修改爲滾動2個骰子而不是1個骰子的位置。當你擲出一個時,它會轉向下一個玩家,並且你的分數與你之前的分數沒有任何差異。那麼當你滾動兩個我需要它將分數重置爲0並打印出我的消息「蛇眼!你的分數設置爲0」。問題是兩條消息都會打印出蛇眼,並且當你滾動一個滾動條時滾動一條。此外,分數不會重置。我在這個遊戲中有衝突的代碼
編輯*我已經固定的代碼與衝突的打印消息,但仍然遇到麻煩分數時snakeyes被卷
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=0
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]))
還可以修好那個問題我還在用蛇皮卷時重設爲0的分數有問題 – itsthewendigo 2014-12-04 20:50:15