我的问题是,当我在 if 语句中更改变量“XO”的内容时,If 语句的条件中的那个变得未定义。
from ursina import *
import time
app = Ursina()
window.title = "Game"
window.borderless = False
window.exit_button_visible = False
XO = "X"
class Tile(Button):
def __init__(self, position = (-5, -5, 0), texture = "assets/tile.png"):
super().__init__(
parent = scene,
model = "quad",
color = color.lime,
position = position,
texture = texture
)
def input(self, key):
if self.hovered:
if key == "left mouse down":
if XO == "X":
Tile(position = self.position, texture = "assets/tile_x")
XO = "O"
else:
Tile(position = self.position, texture = "assets/tile_0")
XO = "X"
time.sleep(.005)
destroy(self)
for x in range(3):
for y in range(3):
block = Tile((x-1, y-1))
app.run()