提问者:小点点

同时运行同一类的2个实例[已关闭]


class Cell():
    y, x = random_pos()
    while True:
        curses.napms(1000)
        scr.clear()
        move = random_dir()
        if move == "up":
            y -= 1
        if move == "down":
            y += 1
        if move == "left":
            x -= 1
        if move == "right":
            x += 1
        scr.addstr(y, x, "o")
        scr.refresh()
        
cell = Cell()
cell()
cell()

我希望它能够同时创建to实例,所以它同时创建to单元格。 这是一个生活模拟。


共1个答案

匿名用户

不是100%地实现您想要实现的目标,但是这会创建同一个类的两个单独的实例。

cell1 = Cell()
cell2 = Cell()