使用python的游戏分数



我需要帮助为我的井字游戏的每轮计分板,我希望它,所以每当一个回合结束它更新cscore(计算机得分)或pscore(玩家得分)1。

任何对我的代码的反馈将是非常感激的,因为我是一个相当新的python。

我已经把分数相关的代码放在

下面
import random
def main():
global cscore
cscore = 0
global pscore
pscore = 0
if turn == 'player':
drawBoard(theBoard)
move = getPlayerMove(theBoard)
makeMove(theBoard, playerLetter, move)
if isWinner(theBoard, playerLetter):
drawBoard(theBoard)
print('Hooray! You have won the game!')
pscore += 1
print(main)

gameIsPlaying = False
else:
if isBoardFull(theBoard):
drawBoard(theBoard)
print('The game is a tie!')
print(main)

break
else:
turn = 'computer'
else:
move = getComputerMove(theBoard, computerLetter)
makeMove(theBoard, computerLetter, move)
if isWinner(theBoard, computerLetter):
drawBoard(theBoard)
print('The computer has beaten you! You lose.')
cscore += 1
print(main)

gameIsPlaying = False
else:
if isBoardFull(theBoard):
drawBoard(theBoard)
print('The game is a tie!')
print(main)

break
else:
turn = 'player'
if not playAgain():
break
main()

在游戏的循环函数开始时,这个循环不会停止,你需要添加

global cscore, pscore

main()函数一样。如果你没有-这是它不会更新给你的方式。

顺便说一句,更好的方法是为玩家创建一个class(我知道你是python的新手,所以这个- https://www.youtube.com/watch?v=ZDa-Z5JzLYM可能会帮助你),类看起来有点像:

class Player():
def __init__(self, is_human):
self.score = 0
self.is_human = is_human

相关内容

  • 没有找到相关文章

最新更新