我正在制作一个使用4x4棋盘的游戏,我想检查卡片是否已经被按下。
为此,我使用了两个棋盘。一个用于计算(要复制的变量),另一个用于在游戏中显示(称为状态的原始棋盘)。
我有以下一段代码,我希望将TreasureHuntGrid的状态变量复制并在同一类的另一个函数中使用。它应该独立于被复制的变量,因此状态变量的更改不会影响计算变量。
我认为这里的代码处理状态和计算变量是相同的。
如何使它们独立处理?
class TreasureHuntGrid(GridLayout):
Finish.shuffle()
status = ListProperty(Finish.board) #Return a random lists of lists with 1 and -1
calculations = status
def __init__(self, *args, **kwargs):
super(TreasureHuntGrid, self).__init__(*args, **kwargs)
def button_pressed(self, button):
if self.calculations[row][column] != 2: #Check if it is pressed or not
button.text = {-1: Finish.surrounded(row, column), 1: 'X'}[self.sta$
button.background_color = colours[self.status[row][column]]
self.calculations[row][column] = 2