【发布时间】:2013-02-28 04:54:58
【问题描述】:
我正在尝试使用 PBE-Lighoutgame 作为我的参考创建一个迷宫,而没有鼠标单击事件 我有 2 节课
这两个类都是 RectangleMorph 的子类
VisibleSquare>>initialize
"Visible borders with Some Color"
其他类
InvisbleSquare>>initialize
"Everything is transparent Including Borders"
实现 Maze 类,它是 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 一起制成表格,以便它们可以随机添加到网格中(或)有没有其他方法可以做到这一点??
【问题讨论】:
-
用可见和不可见的正方形制表矩阵,我不知道我该怎么做