이상적으로 그것은 checker 필드의 임의의 위치에 5 개의 검은 색 사각형을 제공해야합니다. 그러나 사실 그것은 나에게 검은 색 사각형을 줄입니다.임의의 생성 문제 또는 스크립트 문제가 있습니까?
글자 그대로 답변을 찾을 수 없기 때문에 나는 이것에 정말로 집착했습니다.
PS 여기 컴파일 된 응용 프로그램입니다. http://dl.dropbox.com/u/9288177/CSE/images/Conquester.swf
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="800" minHeight="600" creationComplete="main()">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import flash.display.Shape;
import flash.display.Sprite;
import mx.core.UIComponent;
import spark.core.SpriteVisualElement;
private var rectangle:Sprite = new Sprite();
private var insterter:UIComponent = new UIComponent();
private var theme:SpriteVisualElement = new SpriteVisualElement();
private var yH:int;
private var xH:int;
private var grid:Array = new Array();
const WIDTH:int = 20;
const HEIGHT:int = 20;
private function main():void
{
var uic:UIComponent = new UIComponent();
uic.width = uic.height = 50;
uic.graphics.lineStyle(1,0x888888);
//uic.graphics.
//uic.graphics.drawRect(0,0,50,50);
canvas.rawChildren.addChild(uic);
const boxW:int = 20;
const boxH:int = 20;
const planetnumber:int = 5;
for(yH = 0; yH < HEIGHT; yH++) {
var row:Array = new Array();
for (xH = 0; xH < WIDTH; xH++) {
uic.graphics.drawRect(boxW*yH,boxH*xH,boxW,boxH);
row.push(0);
}
grid.push(row);
}
var currentplanet:int = 0;
var rw:int;
var clmn:int;
var counter:int = 0;
while (currentplanet < planetnumber)
{
clmn= (Math.random() * (WIDTH-5)) + 5;
rw = (Math.random() * (HEIGHT-5)) + 5;
if (fieldcheck(rw, clmn) == true)
{
grid[rw][clmn] = 1;
uic.graphics.beginFill(0x000000, 1);
uic.graphics.drawRect(boxW*clmn,boxH*rw,boxW,boxH);
uic.graphics.endFill();
currentplanet++;
if (counter == 4)
{
c4.text=clmn.toString();
r4.text=rw.toString();
}
if (counter == 3)
{
c3.text=clmn.toString();
r3.text=rw.toString();
counter++;
}
if (counter == 2)
{
c2.text=clmn.toString();
r2.text=rw.toString();
counter++;
}
if (counter == 1)
{
c1.text=clmn.toString();
r1.text=rw.toString();
counter++;
}
if (counter == 0)
{
c0.text=clmn.toString();
r0.text=rw.toString();
counter++;
}
}
}
}
private function fieldcheck(iRow:int, iColumn:int):Boolean
{
if (grid[iRow][iColumn]==0)
{
if ((iRow > 0)&&(iRow < HEIGHT))
{
if ((iColumn > 0) && (iColumn < WIDTH))
{
if ((grid[iRow-1][iColumn-1]==0)&&(grid[iRow][iColumn-1]==0)&&(grid[iRow+1][iColumn-1]==0)&&(grid[iRow-1][iColumn]==0)&&(grid[iRow+1][iColumn]==0)&&(grid[iRow-1][iColumn+1]==0)&&(grid[iRow][iColumn+1]==0)&&(grid[iRow+1][iColumn+1]==0))
{
return true;
}
}
}
}
return false;
}
//var rnd:int = (Math.random()* 41) + 10;
/*if (rnd >= 48) {
uic.graphics.beginFill(0x000000, 1);
uic.graphics.drawRect(boxW*y,boxH*x,boxW,boxH);
uic.graphics.endFill();
}
else
{
uic.graphics.drawRect(boxW*y,boxH*x,boxW,boxH);
}*/
]]>
</fx:Script>
<mx:Canvas id="canvas" x="34" y="10" width="90%" height="90%" textAlign="center">
</mx:Canvas>
<s:Label id="r1" x="34" y="565" width="84" height="11" text="Label"/>
<s:Label id="r2" x="34" y="575" width="84" height="11" text="Label"/>
<s:Label id="c2" x="126" y="575" width="77" height="11" text="Label"/>
<s:Label id="c1" x="126" y="565" width="77" height="11" text="Label"/>
<s:Label id="r3" x="34" y="585" width="84" height="11" text="Label"/>
<s:Label id="c3" x="126" y="585" width="77" height="11" text="Label"/>
<s:Label id="r4" x="215" y="555" width="84" height="11" text="Label"/>
<s:Label id="c4" x="307" y="555" width="77" height="11" text="Label"/>
<s:Label id="r0" x="34" y="555" width="84" height="11" text="Label"/>
<s:Label id="c0" x="126" y="555" width="77" height="11" text="Label"/>
</s:Application>
(거의) Firefox 3.6에서 작동합니다. (i) 네가 똑같은 장소에 떨어지지 않았는지 확인합니까? (ii) 너의 사각형이 들판을 벗어나지 않도록 비공개 오류를 확인합니까? –
그걸 확인해 봅니다. "(grid [iRow] [iColumn] == 0)"그리고 네가 필드 바깥으로 나가는 것을 확인하면 그렇지 않습니다. 왜냐하면 currentplanet ++; 내부에 if-check가 있습니다. 그래서 함수가 반복적으로 반복 될 때까지 (이론적으로) 필드 내부에있는 숫자를 얻을 때까지 – Smoke
잘 이미 고쳐졌습니다. 나 자신에게 묻자 - 거의 나 자신에게 대답했다. \t \t \t 전용 기능 곳 Fieldcheck (iRow : INT, iColumn : INT) 부울 { \t \t \t \t VAR의 X 좌표 : 배열 = -1,0,1, -1,1, -1,0,1] ; \t \t \t \t var yPos : Array = [-1, -1, -1,0,0,1,1,1]; \t \t \t \t var tmpX : int; \t \t \t \t var tmpY : int; 위한 \t \t \t \t \t \t \t \t (VAR I : INT = 0; i가 <4; I ++) \t \t \t \t \t { \t \t \t \t tmpX = iRow + X 좌표 [I]; \t \t \t \t \t tmpY = iColumn + yPos [i]; \t \t \t \t \t 경우 (tmpX < 0 || tmpX > = WIDTH || \t \t \t \t \t \t tmpY < 0 || tmpY > = HEIGHT) \t \t \t \t \t \t 계속; \t \t \t \t \t (! 격자 [tmpX] tmpY] = 0) \t \t \t \t \t \t 복귀 경우 false; \t \t \t \t} \t \t \t \t 반환 사실 \t \t \t} – Smoke