エチカでやってた、頭が良くなる(らしい)計算
エチカの鏡で放送していた、頭が良くなる計算です。
制限時間は30秒。
@narutohyper
/**
* Copyright narutohyper ( http://wonderfl.net/user/narutohyper )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9kxY
*/
package
{
import flash.display.Sprite;
import flash.text.*;
import flash.system.System
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.net.*;
import flash.utils.escapeMultiByte;
/**
* エチカの鏡で放送していた、頭が良くなる計算です。
*
* 制限時間は30秒。
* @narutohyper
*/
[SWF(backgroundColor = 0x000000, frameRate = 40, width = 465, height = 465)]
public class main extends Sprite
{
public var textArea:Sprite
public function main() {
//a+b
for(var i:uint=0;i<100;i++) {
//trace(Math.ceil(Math.random()*8))
}
textArea=new Sprite()
textArea.y=50
addChild(textArea)
var format:TextFormat=new TextFormat();
var guide:TextField=setTextField(format,(464-100)/2,20,100,18)
guide.text='エチカの鏡でやっていた、頭の良くなる計算です。\nSTARTボタンを押すと、5問の計算問題が出ますので\n30秒以内に解いてください。'
var guide2:TextField=setTextField(format,(464-100)/2,300,100,18)
guide2.text=''
var q1:TextField=setTextField(format,(464-100)/2,0,100,18)
var q2:TextField=setTextField(format,(464-100)/2,50,100,18)
var q3:TextField=setTextField(format,(464-100)/2,100,100,18)
var q4:TextField=setTextField(format,(464-100)/2,150,100,18)
var q5:TextField=setTextField(format,(464-100)/2,200,100,18)
var a1:TextField=setTextField(format,(464-100)/2,20,100,18,1)
var a2:TextField=setTextField(format,(464-100)/2,70,100,18,1)
var a3:TextField=setTextField(format,(464-100)/2,120,100,18,1)
var a4:TextField=setTextField(format,(464-100)/2,170,100,18,1)
var a5:TextField=setTextField(format,(464-100)/2,220,100,18,1)
var timerStr:TextField=setTextField(format,(464-100)/2,270,100,30)
format.size=20;
timerStr.defaultTextFormat=format
timerStr.text=String(30)
var counter:uint=30
q1.visible=q2.visible=q3.visible=q4.visible=q5.visible=false
a1.visible=a2.visible=a3.visible=a4.visible=a5.visible=false
timerStr.visible=false
var answer1:uint
var answer2:uint
var answer3:uint
var answer4:uint
var answer5:uint
var bt:Button = new Button('START',150)
bt.x = stage.stageWidth/2 - bt.width/2;
bt.y = 200;
bt.addEventListener(MouseEvent.CLICK, init);
addChild(bt);
var bt2:Button = new Button('もう一度',150)
bt2.x = stage.stageWidth/2 - bt.width/2 +100;
bt2.y = 380;
bt2.addEventListener(MouseEvent.CLICK, init);
addChild(bt2);
bt2.visible=false
var bt3:Button = new Button('結果をTwitterに投稿する',150)
bt3.x = stage.stageWidth/2 - bt.width/2 -100;
bt3.y = 380;
bt3.addEventListener(MouseEvent.CLICK, post);
addChild(bt3);
bt3.visible=false
var result:String=''
var calcArray:Array=['たす','ひく'];
var timer:Timer=new Timer(1000, 30)
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);
function timerHandler(e:TimerEvent):void{
counter--;
timerStr.text=String(counter)
}
function completeHandler(e:TimerEvent):void{
a1.type=TextFieldType.DYNAMIC
a2.type=TextFieldType.DYNAMIC
a3.type=TextFieldType.DYNAMIC
a4.type=TextFieldType.DYNAMIC
a5.type=TextFieldType.DYNAMIC
var num:uint=0
if(String(answer1)==a1.text) {
a1.backgroundColor=0x9999FF
num++
} else {
a1.appendText('('+answer1+')')
a1.backgroundColor=0xFF9999
}
if(String(answer2)==a2.text) {
a2.backgroundColor=0x9999FF
num++
} else {
a2.appendText('('+answer2+')')
a2.backgroundColor=0xFF9999
}
if(String(answer3)==a3.text) {
a3.backgroundColor=0x9999FF
num++
} else {
a3.appendText('('+answer3+')')
a3.backgroundColor=0xFF9999
}
if(String(answer4)==a4.text) {
a4.backgroundColor=0x9999FF
num++
} else {
a4.appendText('('+answer4+')')
a4.backgroundColor=0xFF9999
}
if(String(answer5)==a5.text) {
a5.backgroundColor=0x9999FF
num++
} else {
a5.appendText('('+answer5+')')
a5.backgroundColor=0xFF9999
}
if (num) {
guide2.text=num+'問正解です。'
} else {
guide2.text='全問不正解でした。'
}
result=guide2.text
bt2.visible=true
bt3.visible=true
}
function post(evt:MouseEvent):void
{
var st:String;
var thisURL:String = " http://bit.ly/bLnPah %23wonderfl";
st = "http://twitter.com/home?status="+escapeMultiByte("頭のよくなる(らしい)計算。"+result) + thisURL;
navigateToURL(new URLRequest(st));
}
function init():void {
q1.visible=q2.visible=q3.visible=q4.visible=q5.visible=true
a1.visible=a2.visible=a3.visible=a4.visible=a5.visible=true
timerStr.visible=true;
guide.visible=false;
bt.visible=false;
bt2.visible=false;
bt3.visible=false;
counter=30
timer.reset()
timer.start()
timerStr.text=String(counter)
guide2.text=''
a1.type=TextFieldType.INPUT
a2.type=TextFieldType.INPUT
a3.type=TextFieldType.INPUT
a4.type=TextFieldType.INPUT
a5.type=TextFieldType.INPUT
a1.backgroundColor=0xFFFFFF
a2.backgroundColor=0xFFFFFF
a3.backgroundColor=0xFFFFFF
a4.backgroundColor=0xFFFFFF
a5.backgroundColor=0xFFFFFF
a1.text=''
a2.text=''
a3.text=''
a4.text=''
a5.text=''
answer1=Math.ceil(Math.random()*8)+1
answer2=Math.ceil(Math.random()*9)+10
answer3=Math.ceil(Math.random()*89)+10
answer4=Math.ceil(Math.random()*89)+10
var a:uint
var b:uint
var c:uint
var d:uint
a=Math.ceil(Math.random()*(answer1-1))
b=answer1-a
q1.text=numStr(a)+"たす"+numStr(b)+"は"
//a1.text=String(a+b)
a=Math.ceil(Math.random()*(answer2-1))
b=answer2-a
q2.text=numStr(a)+"たす"+numStr(b)+"は"
//a2.text=String(a+b)
a=Math.ceil(Math.random()*(answer3-1))
b=answer3-a
q3.text=numStr(a)+"たす"+numStr(b)+"は"
//a3.text=String(a+b)
a=Math.ceil(Math.random()*(answer4-2))
b=Math.ceil(Math.random()*((answer4-a)-1))
c=answer4-(a+b)
q4.text=numStr(a)+"たす"+numStr(b)+"たす"+numStr(c)+"は"
//a4.text=String(a+b+c)
a=Math.ceil(Math.random()*99)
answer5=a
var e:Array=[]
var f:Array=[]
for (var i:uint=0;i<2;i++) {
f[i]=Math.round(Math.random())
if (answer5>2 && f[i]) {
//引き算
e[i]=Math.ceil(Math.random()*((answer5<100)?answer5-2:98))
answer5-=e[i]
} else {
//足し算
f[i]=0
e[i]=Math.ceil(Math.random()*98)
answer5+=e[i]
}
}
q5.text=numStr(a)+calcStr(f[0])+numStr(e[0])+calcStr(f[1])+numStr(e[1])+"は"
//a5.text=String(answer5)
}
}
private function calcStr(num:uint=0):String {
var str:String="たす"
if (num) {
str="ひく"
}
return str
}
private function numStr(num:uint=0):String {
var numArray:Array=['','いち','に','さん','よん','ご','ろく','なな','はち','きゅう'];
var str:String=Array[0]
if(num>=20) {
str=String(numArray[Math.floor(num/10)])+'じゅう'+String(numArray[num%10])
} else if(num>10) {
str='じゅう'+numArray[num%10]
} else if(num==10) {
str='じゅう'
} else {
str=numArray[num]
}
return str
}
private function setTextField(_format:TextFormat,_x:uint=0,_y:uint=0,_w:uint=100,_h:uint=40,_type:uint=0):TextField {
_format.color=0x000000
_format.size=14;
_format.font='_等幅';
_format.leading = 10;
_format.align = "center"
var tbox:TextField=new TextField()
tbox.x=_x;
tbox.y=_y;
tbox.width=_w;
tbox.height=_h;
if (_type) {
tbox.type=TextFieldType.INPUT
tbox.background=true;
tbox.backgroundColor=0xFFFFFF
tbox.selectable=true;
tbox.mouseEnabled=true;
_format.color=0x000000
} else {
tbox.autoSize=TextFieldAutoSize.CENTER
tbox.selectable=false;
tbox.mouseEnabled=false;
_format.color=0xFFFFFF
}
tbox.defaultTextFormat=_format
textArea.addChild(tbox);
return tbox;
}
}
}
import flash.display.*;
import flash.text.*;
class Button extends SimpleButton
{
public function Button(label:String, width:int = 0):void
{
var up:Sprite = _buildImage(label, 0xCCCCCC, width);
var over:Sprite = _buildImage(label, 0xFFCCCC, width);
var down:Sprite = _buildImage(label, 0xCC9999, 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, 0x000000, true, null, null, null, null, TextFormatAlign.CENTER);
text.autoSize = TextFieldAutoSize.CENTER;
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;
}
}