我是新来的动作。我试图做的是模拟2车道交叉口附近的交通流量,遵循Wolfram的规则184.首先,我试图创建一个网格(8x8的交叉点在中间两排和中间两条之间列,就像一个加号),其细胞具有以下属性:动态网格使用FlashDevelop&Actionscript 2.0
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循环中的每个单元制作影片剪辑?我认为用给定的属性来创建对象的网格会更容易,但我不知道该怎么做。如果有人帮助我,我会很感激。