【发布时间】:2018-07-06 22:33:36
【问题描述】:
self.cell 没有更新..
当我在cell_in 中输入值时,update_cell 方法不会列出单元格。
并返回['-','-','-','-','-','-','-','-','-']
class board():
def __init__(self):
self.cell=['-','-','-','-','-','-','-','-','-']
def display(self):
x=0
c= self.cell
for i in range(0,3):
for j in range(0,3):
if(j is 0):
print(' ',end='')
print(c[x],end='')
x+=1
if(j<2):
print(' | ',end='')
if(i<2):
print('\n-----------')
print()
def update_cell(self,cell_in,player):
self.cell[(cell_in-1)]= player
def header():
print("-TicTacToe-")
def ref_scr():
cls()
header()
board().display()
while True:
ref_scr()
cell_in = int(input("enter cell between 1 and 9: "))
player= 'X'
board().update_cell(cell_in,player)
【问题讨论】:
-
board()创建一个新的 board 实例,board().update_cell(cell_in,player)创建一个新实例,更新它,然后将其丢弃。
标签: python python-3.x list class oop