私はカードゲームを作成しています。最後に到達したら、より多くのラウンドをプレイできるようにしたいのですが、リプレイすると、変数を再度通過する必要があります..スコアをリセットします。複雑なコードのまったく新しいブロックなしで修正する方法を探しています。本当に簡単な修正が欠けていることを願っています。
#!/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)