Pandemic on 2011-2-6
/**
* Copyright k2syndrome_g ( http://wonderfl.net/user/k2syndrome_g )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5hxy
*/
package {
import flash.events.Event;
import flash.display.SimpleButton;
import flash.trace.Trace;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var count:int=0;//count
private var file:int=0;//試行回数
private var dead:int=0;//死亡回数
private var ave:int=0;//平均死亡レス数
private var alive:int=0;//生存回数
private var tf1_0:TextField=new TextField();
private var tf1:TextField=new TextField();
private var tf2:TextField=new TextField();
private var tf3:TextField=new TextField();
private var tf4:TextField=new TextField();
private var tf5:TextField=new TextField();
public function FlashTest() {
// write as3 code here..
initTxt2(this,tf1_0,0,0,"");
initTxt1(this,tf1,0,15,70,400);
//
var tf2_0:TextField=new TextField();
initTxt2(this,tf2_0,110,0,"ALIVE");
initTxt1(this,tf2,110,15,150,200);
//
var tf3_0:TextField=new TextField();
initTxt2(this,tf3_0,300,0,"DEAD");
initTxt1(this,tf3,300,15,150,200);
//
var tf4_0:TextField=new TextField();
initTxt2(this,tf4_0,150,300,"DEAD RATE");
initTxt1(this,tf4,150,315,100,15);
//
var tf5_0:TextField=new TextField();
initTxt2(this,tf5_0,300,300,"DEAD AVERAGE");
initTxt1(this,tf5,300,315,100,15);
//
this.addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event):void{
if(count==1){
file++;//試行回数増やす
exam();
tf4.text=String(dead/file*100);
tf5.text=String(int(ave/file))+"res";
count=0;
}
count++;
}
private function initTxt1(p:Sprite,tf:TextField,xx:Number,yy:Number,w:Number,h:Number):void{
tf.x=xx;
tf.y=yy;
tf.height=h;
tf.width=w;
tf.mouseWheelEnabled = true;
tf.border = true;
p.addChild(tf);
}
private function initTxt2(p:Sprite,tf:TextField,xx:Number,yy:Number,t:String):void{
tf.x=xx;
tf.y=yy;
tf.text=t;
p.addChild(tf);
}
private function exam():void{
var virus:int=0;//ウイルス数
var rand:int;//0-99のランダム
tf1_0.text="case"+file;
tf1.text="";
for(var i:int=0;i<1000;i++){//1000レス
rand=Math.floor(Math.random()*100);//0-99
if(rand<=virus){//randがウィルス数以下なら
tf1.appendText(String(i)+"\tby ."+rand+"\n");
tf1.scrollV=virus;
virus++;//ウイルス増殖
}
if(virus==100){//ウイルスが100に達したら
dead++;
ave+=i;
tf1.appendText("dead!\n");
tf1.scrollV=virus;
tf3.appendText("case"+file+"\tres= "+i+"\n");
tf3.scrollV=dead;
return;
}
}
//1000レス以内にウィルスが100いかなかったら
tf1.appendText("alive!\n");
tf1.scrollV=virus;
alive++;
tf2.appendText("case"+file+"\tinfected="+virus+"\n");
tf2.scrollV=alive;
}
//
}
}