我是动作脚本的新手。我想做的是模拟 2 车道交叉口附近的交通流量,遵循 Wolfram 的规则 184。首先,我试图创建一个网格(8x8 的交叉口位于中间两行和中间两行之间列,如加号),其单元格具有以下属性:
color = white;
car = false;
when clicked:
color = red;
car = true (a car is present);
因此,在用户单击单元格以最初定位汽车并按下开始按钮后,模拟将开始。
到目前为止,这是我的代码(对不正确的格式表示歉意):
class Main
{
private var parent:MovieClip;
public static function main(mc:MovieClip)
{
var app = new Main(mc);
}
public function Main(mc:MovieClip)
{
this.parent = mc;
//grid settings
var Cell:MovieClip = mc.createEmptyMovieClip("cell", mc.getNextHighestDepth());
var x:Number = 0;
var y:Number = 0;
var color:Number = 0xffffff;
var car:Boolean = false;
for (y = 0; y < 3 * Stage.height / 8; y += Stage.height / 8)
{
for (x = 3*Stage.width/8; x < 5*Stage.width/8; x+=Stage.width/8)
{
UI.drawRect(Cell, x, y, (Stage.width / 8) - 5, (Stage.height / 8) - 5, color, 100);
}
}
for (y = 3*Stage.height/8; y < 5 * Stage.height / 8; y += Stage.height / 8)
{
for (x = 0; x < Stage.width; x+=Stage.width/8)
{
UI.drawRect(Cell, x, y, (Stage.width / 8)-5, (Stage.height / 8)-5, color, 100);
}
}
for (y = 5*Stage.height/8; y < Stage.height; y += Stage.height / 8)
{
for (x = 3*Stage.width/8; x < 5*Stage.width/8; x+=Stage.width/8)
{
UI.drawRect(Cell, x, y, (Stage.width / 8)-5, (Stage.height / 8)-5, color, 100);
}
}
Cell.onMouseDown()
{
Cell.color = UI.RED;
Cell.car = true;
}
}
}
我知道这里出了很多问题。首先,鼠标按下时单元格颜色不会改变。我需要为 for 循环中的每个单元格制作影片剪辑吗?我认为制作具有给定属性的对象网格会更容易,但我不知道该怎么做。如果有人帮助我,我将不胜感激。