我正在制作纸牌游戏,当它结束时,我希望人们能够玩更多的回合,但是当它重播时,它必须再次通过变量..重置分数。我正在寻找一种方法来修复它,而无需使用全新的复杂代码块,我希望我只是错过了一个非常简单的修复。
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Imports
import time
def play_game():
# Variables
acard = int()
bcard = int()
apoints = int()
bpoints = int()
# Repeat
repeat = True
# Hand out cards
print 'Cards have been served'
input('\nPress Enter to Reveal')
# Cards Turn
time.sleep(0.5)
t = time.time()
acard = int(str(t - int(t))[2:]) % 13
print '\nYour card value is ' + str(acard)
time.sleep(0.1)
t = time.time()
bcard = int(str(t - int(t))[2:]) % 13
# Number Check & Point Assign
time.sleep(2)
if acard > 5:
apoints += 1
print '\nYour points have increased by one, your total is now ' \
+ str(apoints)
if acard < 5:
apoints -= 1
print '\nYour points have decreased by one, your total is now ' \
+ str(apoints)
if bcard > 5:
bpoints += 1
print '\nYour opponent got ' + str(bcard) \
+ ', their points have increased by one,\ntheir total is now ' \
+ str(bpoints)
if bcard < 5:
bpoints -= 1
print '\nYour opponent got ' + str(bcard) \
+ ', their points have decreased by one,\ntheir total is now ' \
+ str(bpoints)
# Card Reset
bcard = 0
acard = 0
# Shuffle
input('\nPress enter to shuffle deck')
print '\nCards being shuffled'
time.sleep(1)
print '.'
time.sleep(1)
print '.'
time.sleep(1)
print '.'
print 'Cards have been shuffled'
global enda
global endb
enda = apoints
endb = bpoints
# Loop
time.sleep(1)
answer = 'y'
while answer.lower() == 'y':
play_game()
answer = input('\nDo you wish to play again? (Y/N)')
# Scores
if enda > endb:
print '\nYou Win!'
print '\nScores'
print 'You: ' + str(enda) + ' Opponent: ' + str(endb)
if endb > enda:
print '\nYou Lost!'
print '\nScores'
print 'You: ' + str(enda) + ' Opponent: ' + str(endb)