泣いて馬謖を斬る
inspired by http://twitter.com/javascripter/statuses/8367943818
/**
* Copyright hig_an ( http://wonderfl.net/user/hig_an )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6G88
*/
// forked from undo's 落ち着け・・・素数を数えて落ち着くんだ・・・
// forked from nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes)
// inspired by http://twitter.com/javascripter/statuses/8367943818
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class BashokuGame extends Sprite {
private var defaultText:String = "\n"+"また馬謖が失敗しました。馬謖を斬ってください。";
private var shogun:Array;
private var killedNum:int;
private var i:int;
private var ryuzenNum:int = 0;
private var tf:TextField;
private var sbtn:Button;
private var yes:Button;
private var no:Button;
public function BashokuGame() {
shogun = ["劉禅","馬謖","馬謖","馬謖","馬謖","馬謖","馬忠", "馬超","馬岱","馬良","馬騰","馬休","馬鉄","赤兎馬"];
tf = new TextField();
tf.autoSize = TextFieldAutoSize.CENTER;
var tform:TextFormat = new TextFormat();
tform.align = TextFormatAlign.CENTER;
tf.defaultTextFormat = tform;
tf.text = defaultText;
addChild(tf);
tf.x = stage.stageWidth/2 - tf.textWidth/2;
tf.y = 100;
sbtn = new Button("game start", 150);
//sbtn.width = 150;
sbtn.x = stage.stageWidth/2 - sbtn.width/2;
sbtn.y = 200;
sbtn.addEventListener(MouseEvent.CLICK, onClick);
addChild(sbtn);
yes = new Button("泣いて斬る", 100);
yes.x = stage.stageWidth/2 - yes.width - 10;
yes.y = 200;
yes.addEventListener(MouseEvent.CLICK, onYes);
addChild(yes);
no = new Button("斬らない", 100);
no.x = stage.stageWidth/2 + 10;
no.y = 200;
no.addEventListener(MouseEvent.CLICK, onNo);
addChild(no);
yes.visible = false;
no.visible = false;
}
private function onClick(evt:MouseEvent):void{
startGame();
}
private function startGame():void{
sbtn.visible = false;
yes.visible = true;
no.visible = true;
killedNum = 0;
i = Math.floor(Math.random() * shogun.length);
tf.text = "\n"+shogun[i];
}
private function onYes(evt:Event):void{
check(true);
}
private function onNo(evt:Event):void{
check(false);
}
private function check(b:Boolean):void {
if (b) {
if (shogun[i] == "馬謖"||shogun[i] == "劉禅") {
killedNum++;
i = Math.floor(Math.random() * shogun.length);
tf.text = "\n"+shogun[i];
}
else {
endGame();
}
}else {
if (shogun[i] != "馬謖" && shogun[i] != "劉禅") {
i = Math.floor(Math.random() * shogun.length);
tf.text = "\n"+shogun[i];
}
else {
endGame();
}
}
}
private function endGame():void {
sbtn.visible = true;
yes.visible = false;
no.visible = false;
tf.text = "\n"+"GAME OVER"+"\n"+String(killedNum)+"人の馬謖を斬りました";
}
}
}
import flash.display.*;
import flash.text.*;
class Button extends SimpleButton
{
public function Button(label:String, width:int = 0):void
{
var up:Sprite = _buildImage(label, 0x0, width);
var over:Sprite = _buildImage(label, 0x333333, width);
var down:Sprite = _buildImage(label, 0x333333, width);
down.y = 1;
super(up, over, down, up);
}
private static function _buildImage(label:String, color:int, width:int = 0):Sprite
{
var text:TextField = new TextField();
text.defaultTextFormat = new TextFormat('Verdana', 10, 0xffffff, true, null, null, null, null, TextFormatAlign.CENTER);
text.autoSize = TextFieldAutoSize.LEFT;
text.selectable = false;
text.text = label;
text.x = (width - text.width) >> 1;
text.y = 5;
var base:Shape = new Shape();
var g:Graphics = base.graphics;
g.beginFill(color);
g.drawRect(0, 0, width, text.height + 10);
g.endFill();
var sp:Sprite = new Sprite();
sp.addChild(base);
sp.addChild(text);
return sp;
}
}