Lispハッカーならできるはず!
Lispハッカーなら括弧の数が合ってないのが一瞬で分かると聞いたので
いきなり始まります。
Flashの上を一度クリックしないとキーが反応しないかも
/**
* Copyright tana ( http://wonderfl.net/user/tana )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/feEw
*/
//Lispハッカーなら括弧の数が合ってないのが一瞬で分かると聞いたので
//いきなり始まります。
//Flashの上を一度クリックしないとキーが反応しないかも
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.text.TextFieldAutoSize;
import net.wonderfl.score.basic.*;
public class FlashTest extends Sprite {
private var field:TextField;
private var message:TextField;
private var timer:Timer;
private var timecount:Number;
private var validflag:Boolean;
private var failcount:Number;
private var successcount:Number;
public function FlashTest() {
// write as3 code here..
failcount = 0;
successcount = 0;
field = new TextField();
addChild(field);
field.text = "hoge!";
message = new TextField();
message.x = 0;
message.y = field.height + 1;
addChild(message);
message.text = "";
var help:TextField = new TextField();
help.x = 0;
help.y = field.height + 1 + message.height + 1;
//help.width = message.width * 2 + 20;
help.autoSize = TextFieldAutoSize.LEFT;
addChild(help);
help.text = "括弧の数が正しい時は「y」を押して、\n";
help.appendText("括弧の数が間違っている時は「n」を押します。\n");
help.appendText("一定時間以内に答えられなかった時や間違った時は失敗になります。\n");
help.appendText("6回失敗するとゲームオーバーです。");
addEventListener(KeyboardEvent.KEY_DOWN, keydown);
startQuestion();
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, refleshText);
timer.start();
}
private function refleshText(e:TimerEvent):void {
if (timecount == -1) {
message.text = "時間切れ" + "\n" + message.text;
failcount++;
startQuestion();
}
timecount--;
}
private function startQuestion():void {
if (failcount > 5) {
//ゲームオーバーの時の処理
message.text = "Game over.\n正解数は" + successcount + "です。\n" + message.text;
timer.stop();
removeEventListener(KeyboardEvent.KEY_DOWN, keydown);
var onClose:Function = function():void {
message.text = "hgoe";
new BasicScoreRecordViewer(this, 0, 0, "Ranking");
}
new BasicScoreForm(this, 0, 0, successcount, "Save score", onClose);
}
//timecount = 5;
timecount = 1;
var text:String = "";
if (Math.random() * 10 < 5) {
//valid
validflag = true;
var count:Number = int(Math.random() * 10) + 1;
for (var a:Number = 0; a < count; a++) {
text += "(";
}
for (var b:Number = 0; b < count; b++) {
text += ")";
}
}
else {
//invalid
validflag = false;
var count2:Number = int(Math.random() * 10) + 1;
for (var a2:Number = 0; a2 < count2; a2++) {
text += "(";
}
for (var b2:Number = 0; b2 < count2; b2++) {
text += ")";
}
text += ")";
}
field.text = text;
}
private function keydown(e:KeyboardEvent): void {
if (e.keyCode == 89) {
//「Y」が押されたら
if (validflag) {
message.text = "正解" + "\n" + message.text;
successcount++;
}
else {
message.text = "不正解" + "\n" + message.text;
failcount++;
}
}
if (e.keyCode == 78) {
//「N」が押されたら
if (!validflag) {
message.text = "正解" + "\n" + message.text;
successcount++;
}
else {
message.text = "不正解" + "\n" + message.text;
failcount++;
}
}
startQuestion();
}
}
}