# flex 联机游戏开发 - 四国军棋游戏:(二)棋盘棋子

public function createBoard():void
{

for (var row:int = 0; row <=xsize; row++) {
var tempArray:Array=new Array(ysize);
gameControl.boardArray[row] =tempArray;
}
//y 轴的线条
for (var i:int=0;i<=ysize;i++)
{
var line:Line=new Line();
line.stroke=DEFAULT_STROKE;
}
//x 轴的线条
for (var j:int=0;j<=xsize;j++)
{
var line2:Line=new Line();
line2.stroke=DEFAULT_STROKE;
}
//营里的线条
for (var x1:int=0;x1<=xsize;x1++)
{
for (var y1:int=0;y1<=ysize;y1++)
{
if ((x1==1&&y1==1)||(x1==3&&y1==3)||(x1==2&&y1==2)||(x1==1&&y1==3)||(x1==3&&y1==1))
{
//画四个方向的线
}
}
}
//默认的棋盘填充，
for (var x:int=0;x<=xsize;x++)
{
for (var y:int=0;y<=ysize;y++)
{
if ((x==1&&y==5)||(x==3&&y==5))
//画大本营
else if ((x==1&&y==1)||(x==3&&y==3)||(x==2&&y==2)||(x==1&&y==3)||(x==3&&y==1))
//画营
else
//其它
}
}

}

[img]http://www.rainfu.net/sites/files/net_rainfu/sg2.jpg[/img]

//默认的棋盘填充，
for (var x:int=0;x<=xsize;x++)
{
for (var y:int=0;y<=ysize;y++)
{
if ((x==1&&y==5)||(x==3&&y==5))
//画大本营
else if ((x==1&&y==1)||(x==3&&y==3)||(x==2&&y==2)||(x==1&&y==3)||(x==3&&y==1))
//画营
else
//其它

//放一个默认的棋子
}
}

//默认的棋盘填充，
for (var x:int=0;x<=xsize;x++)
{
for (var y:int=0;y<=ysize;y++)
{
if ((x==1&&y==5)||(x==3&&y==5))
//画大本营
else if ((x==1&&y==1)||(x==3&&y==3)||(x==2&&y==2)||(x==1&&y==3)||(x==3&&y==1))
//画营
else
//其它

//放一个默认的棋子
}
}

//玩家填充
private const TURNARRAY:Array=[new SolidColor(0xff0000,1),new SolidColor(0x00ff00,1),new SolidColor(0x0000ff,1),new SolidColor(0xffcc00,1),new SolidColor(0xffffff,0)];

<s:Group width="660" height="660" left="20" top="20">
<ns1:Layout x="425" y="220" rotation="180">
</ns1:Layout>
<ns1:Layout x="220" y="235" rotation="90">
</ns1:Layout>
<ns1:Layout x="235" y="440">
</ns1:Layout>
<ns1:Layout x="440" y="425" rotation="-90">
</ns1:Layout>
<ns1:CenterGroup x="220" y="220">
</ns1:CenterGroup>
</s:Group>

protected function init(event:FlexEvent):void
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
//y 轴的线条

BOARD_IMG.source=BoardChess;
BOARD_IMG.fillMode = BitmapFillMode.REPEAT;

for (var i:int=0;i<=2;i++)
{
var line:Line=new Line();
line.xFrom=0;
line.xTo=center.width;
line.stroke=DEFAULT_TEDAO_STROKE;
}
//x 轴的线条
for (var j:int=0;j<=2;j++)
{
var line2:Line=new Line();
line2.yFrom=0;
line2.yTo=center.height;
line2.stroke=DEFAULT_TEDAO_STROKE;

}

//边角的弧

//填充，
for (var x:int=0;x<=2;x++)
{
for (var y:int=0;y<=2;y++)
{

var rect:Rect=new Rect();
rect.width=15;
rect.height=15;
rect.stroke=DEFAULT_STROKE;
rect.fill=BOARD_IMG;
}
}
}

[img] http://www.rainfu.net/sites/files/net_rainfu/sg3_0.jpg[/img]

<s:BorderContainer id="board" width="880" height="670" top="20" left="150" horizontalCenter="0">
<ns1:CenterGroup x="320" y="198">
</ns1:CenterGroup>
<ns1:Layout x="530" y="219" rotation="180">
</ns1:Layout>
<ns1:Layout x="341" y="218" rotation="90">
</ns1:Layout>
<ns1:Layout x="340" y="407">
</ns1:Layout>
<ns1:Layout x="529" y="408" rotation="-90">
</ns1:Layout>
<ns1:UserInfo x="221" y="17">
</ns1:UserInfo>
<ns1:UserInfo x="550" y="433">
</ns1:UserInfo>
<ns1:UserInfo x="10" y="228">
</ns1:UserInfo>
<mx:Button id="btnlose" label="投降" enabled="false" x="669" y="465" width="70" height="21"/>
<mx:Button id="btnstart" label="开始" enabled="true" x="669" y="435" width="70" height="21"/>
<mx:Button id="btnsave" label="调入布局" enabled="true" x="669" y="525" width="70" height="21"/>
<mx:Button id="btnopen" label="保存布局" enabled="true" x="669" y="495" width="70" height="21"/>
<ns1:UserInfo x="763" y="228">
</ns1:UserInfo>

</s:BorderContainer>

[img]http://www.rainfu.net/sites/files/net_rainfu/sg5_0.JPG[/img]