我正在尝试使用 PBE-Lighoutgame 创建一个没有鼠标点击事件的迷宫作为我的参考我有 2 个类
这两个类都是 RectangleMorph 的子类
VisibleSquare>>initialize
"Visible borders with Some Color"
其他类
InvisbleSquare>>initialize
"Everything is transparent Including Borders"
实现迷宫类,它是 BorderedMorph 的子类
Maze>>initialize
initialize
|sampleCell width height n sample|
super initialize.
self borderWidth: 0.
n := self cellsPerSide.
sampleCell := VisibleSquare new.
sample:= InvisibleSquare new.
width := sampleCell width.
height := sample height.
self bounds: (5@5 extent: ((width + n) @ (height + n)) + (2 * self borderWidth)).
cells := Matrix new: n tabulate: [:i :j | self newCellAt: i at: j].
其他方法
Maze>> newCellAt: i at: j
"Create a cell for position (i,j) and add it to my on-screen
representation at the appropriate screen position. Answer the new cell"
|c origin b |
c := VisibleSquare new.
origin := self innerBounds origin.
self addMorph: c.
c position: ((i - 1) * c width) @ ((j - 1) * c height) + origin.
^ c
我如何用 VisibleSquare 和 InvisibleSquare 将矩阵制成表格,以便它们可以随机添加到网格中(或)有没有其他方法可以做到这一点?