forked from: タイピング アルファベット順
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/pE4o
*/
// forked from tepe's タイピング アルファベット順
// forked from irfankazi's forked from: AtoZ Typing
// forked from h6k's AtoZ Typing
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.getTimer;
public class FlashTest extends Sprite {
private var az:Array = new Array(29);
private var codes:Array = new Array(29);
private var format:TextFormat = new TextFormat();
private var CODE:int;
private var cnt:int = 0;
private var S:int = 5; // 最小サイズ
private var R:int = 200; // 半径
private var time:uint;
private var score:int;
public function FlashTest() {
// write as3 code here..
init();
onGameStart();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
//アルファベット移動
private function moveAZ(kc:int):void {
var degree:Number;
az[cnt].border = false;//ボーダー解除
cnt++;
for (var i:int = 0; i < 26; i++) {
//回転処理
degree = (90 + (360 / 26 * (cnt))) - ((360 / 26) * i);
setPos(i, degree);
}
cnt %= 26;
CODE = codes[cnt];
az[cnt].border = true;//ボーダー設定
}
//キー入力
private function onKeyDown(e:KeyboardEvent):void {
var code:int;
az[27].text ="k"+e.keyCode+" c"+e.charCode+" CODE"+CODE;
//大文字
if(64<CODE && CODE<91){
if(e.shiftKey == true && e.keyCode == CODE){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//小文字
else if(96<CODE && CODE<123){
if(e.keyCode+32 == CODE && e.shiftKey == false){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//数字
else if(47<CODE && CODE<58){
if(e.charCode == CODE){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//記号1
else if(32<CODE && CODE<48){
if(CODE == 33 && e.shiftKey==true)code=49;// !
else if(CODE == 34 && e.shiftKey==true)code=50;// "
else if(CODE == 35 && e.shiftKey==true)code=51;// #
else if(CODE == 36 && e.shiftKey==true)code=52;// $
else if(CODE == 37 && e.shiftKey==true)code=53;// %
else if(CODE == 38 && e.shiftKey==true)code=54;// &
else if(CODE == 39 && e.shiftKey==true)code=55;// '
else if(CODE == 40 && e.shiftKey==true)code=56;// (
else if(CODE == 41 && e.shiftKey==true)code=57;// )
else if(CODE == 42 && e.shiftKey==true)code=186;// *
else if(CODE == 43 && e.shiftKey==true)code=187;// +
else if(CODE == 44 && e.shiftKey==false)code=188;// ,
else if(CODE == 45 && e.shiftKey==false)code=189;// -
else if(CODE == 46 && e.shiftKey==false)code=190;// .
else if(CODE == 47 && e.shiftKey==false)code=191;// /
if(e.keyCode == code){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//記号2
else if(57<CODE && CODE<65){
if(CODE == 58)code=186;// :
if(CODE == 59)code=187;// ;
if(CODE == 60)code=188;// <
if(CODE == 61)code=189;// =
if(CODE == 62)code=190;// >
if(CODE == 63)code=191;// ?
if(CODE == 64)code=192;// @
if(e.keyCode == code){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//記号3
else if(90<CODE && CODE<97){
if(CODE == 95 && e.shiftKey == true)code=226;// _
if(CODE == 92 && e.shiftKey == false)code=226;// \
if(CODE == 91 && e.shiftKey == false)code=219;// [
if(CODE == 93 && e.shiftKey == false)code=221;// ]
if(CODE == 94 && e.shiftKey == false)code=222;// ^
if(CODE == 96)code=192;// `
if(e.keyCode == code){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//記号4
else if(122<CODE && CODE<127){
if(CODE == 123 && e.shiftKey == true)code=219// {
if(CODE == 124 && e.shiftKey == true)code=220// |
if(CODE == 125 && e.shiftKey == true)code=221// }
if(CODE == 126 && e.shiftKey == true)code=222// ~
if(e.keyCode == code){
changeChar(cnt);
//アルファベット移動
moveAZ(e.keyCode);
score ++;
az[26].text = String(score);
}
return;
}
//スペース
if (e.charCode == 32) {
onGameStart();//スタート画面へ遷移
}
return;
}
//位置設定
private function setPos(i:int, degree:Number):void {
var sin:Number = Math.sin(Math.PI / 180 * degree);
format.size = (sin + 1) * 10 + S;
az[i].setTextFormat(format);
az[i].x = R * Math.cos(Math.PI / 180 * degree) + (stage.stageWidth / 2);
az[i].y = R * sin / 2 + (stage.stageHeight / 2);
}
private function onGameStart():void {
var degree:Number;
shuffle();
CODE = codes[0];
cnt = 0;
for (var i:int = 0; i < 26; i++) {
az[i].border = false;
az[i].textColor = 1;
degree = 90 - ((360 / 26) * i);
setPos(i, degree);
}
az[0].textColor = 0xff0000;
az[0].border = az[26].border = true;
az[26].text = " ";
az[27].text = "Push Space Key to Restart ";
}
//アルファベット配列シャッフル
private function shuffle():void{
//アルファベット配列設定
for(var i:int = 0; i < 28; i++) {
//コード番号登録
//codes[i] = Math.random()*(126-33)+33;;
codes[i] = Math.random()*26+97;
az[i].text = String.fromCharCode(codes[i]);
az[i].autoSize = TextFieldAutoSize.LEFT;
az[i].mouseEnabled = false;
}
}
//文字変更
private function changeChar(cnt:int):void{
//文字設定
var rnd:int =Math.random()*5;
if(200<score){//全文字出題
codes[cnt] = Math.random()*(126-33)+33;
az[cnt].textColor = 0x000000;
}
else if(150<score && rnd<1){
rnd = Math.random()*4;
if(rnd == 0) codes[cnt] = Math.random()*15+33;//記号1
else if(rnd == 1)codes[cnt] = Math.random()*7+58;//記号2
else if(rnd == 2)codes[cnt] = Math.random()*6+91;//記号3
else codes[cnt] = Math.random()*4+123;//記号4
az[cnt].textColor = 0xaa5500;
}
else if(80<score && rnd<2){
codes[cnt] = Math.random()*10+48;//数字
az[cnt].textColor = 0x007733;
}
else if(30<score && rnd<2){
codes[cnt] = Math.random()*26+65;//大文字
az[cnt].textColor = 0x3333aa;
}
else{
codes[cnt] = Math.random()*26+97;//小文字
az[cnt].textColor = 0x000000;
}
//経過時間による点数
var time2:int = getTimer() - time;
if(time2 < 250){
score+=5;
az[27].text = "+5 "
}
else if(time2 < 500){
score+=2;
az[27].text = "+2 "
}
else if(time2 <1000){
score+=1;
az[27].text = "+1 "
}
az[27].text += String(time2/1000);
time = getTimer();
az[cnt].text = String.fromCharCode(codes[cnt]);//文字設定
//if(cnt==0)az[cnt].textColor = Math.random() * 0xffffff;
}
//タイマー
private function onEnterFrame(e:Event):void {
az[26].text = (String)((getTimer() - time) / 1000) + " sec";
}
//初期化
private function init():void {
//アルファベット配列設定
for(var i:int = 0; i < 28; i++) {
az[i] = new TextField();
//コード番号登録
//az[i].text = String.fromCharCode(i + 33);
az[i].autoSize = TextFieldAutoSize.LEFT;
az[i].mouseEnabled = false;
stage.addChild(az[i]);
}
shuffle();
az[26].x = stage.stageWidth / 2 - 10;
az[26].y = stage.stageHeight / 2 + 20;
az[26].background = true;//背景塗り
az[26].backgroundColor = 0x000000;//黒
az[26].textColor = 0xFFFFFF;//白
az[27].x = stage.stageWidth / 2 - 50;
az[27].y = stage.stageHeight / 2;
}
}
}
import flash.display.*;
class key extends Sprite{
private var exp:int;//経験値
public var posx:int;
public var posy:int;
public var Label:String;
public var level:int;//レベル
public function key():void{
level = 1;
}
public function draw():void{
}
//採点
public function addPt(time:uint):void{
if(level == 5){
if(time<250) exp+=50;
}
else if(level == 4){
if(time<500) exp+=20;
if(5000<exp)level++;//レベルアップ
}
else if(level == 3){
if(time<1000) exp+=10;
if(1000<exp)level++;
}
else if(level == 2){
if(time<2000) exp+=5;
if(300<exp)level++;
}
else if(level ==1){
if(time<4000) exp+=2;
if(100<exp)level++;
}
}
}