LIVE CODING 一日でタイピングゲーム作る on 2010-3-29

by shohei909
Live Coding  2010/3/29 mon  AM 10:17~ 翌AM 0:35
as3初心者だけど今日一日でタイピングゲーム作る。
今日のところはこれで完成
Live Codingを見に来てくださった方々ありがとうございました。
まだちょっと修正したいところがあるので
明日以降forkしてもうちょっと作りこんでいきたいと思ってます。
3/30 バグがあったので一行だけ修正
3/31 バグがあったので一部修正
♥0 | Line 812 | Modified 2010-03-31 12:25:04 | MIT License
play

ActionScript3 source code

/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7fL6
 */

//Live Coding  2010/3/29 mon  AM 10:17~ 翌AM 0:35
//as3初心者だけど今日一日でタイピングゲーム作る。
//
//
//今日のところはこれで完成
//Live Codingを見に来てくださった方々ありがとうございました。
//
//まだちょっと修正したいところがあるので
//明日以降forkしてもうちょっと作りこんでいきたいと思ってます。

//3/30 バグがあったので一行だけ修正
//3/31 バグがあったので一部修正
package{
    import flash.display.Sprite;
	import flash.text.*;
	import flash.events.*;
	import flash.utils.*;
	
	[SWF(width=465, height=465, backgroundColor = 0xDDDDFF, frameRate = 60)]
	public class Main extends Sprite{
	    	public var timeCheck2:Timer = new Timer(30);
	    	public var timeCheck:Timer = new Timer(5000);
	    	
        	public var typing:Typing = new Typing();
        	public var time:int = 6000;
        	public var countDown:int;
		public var test:TextField = new TextField();
		
		public var mesField:TextField = new TextField();
		public var mesFormat:TextFormat = new TextFormat();
		public var mesField2:TextField = new TextField();
		public var mesFormat2:TextFormat = new TextFormat();

		public var countField:TextField = new TextField();
		public var countFormat:TextFormat = new TextFormat();
		
		public var touchField:TextField = new TextField();
		public var touchFormat:TextFormat = new TextFormat();

		public var missField:TextField = new TextField();
		public var missFormat:TextFormat = new TextFormat();

		public var finField:TextField = new TextField();
		public var finFormat:TextFormat = new TextFormat();
		
        	public function Main() {
          	typing.wordList = [
            		{word:"カピバラ",			kana:"かぴばら"},
            		{word:"なしくずし",			kana:"なしくずし"},
            		{word:"江戸っ子",			kana:"えどっこ"},
            		{word:"情状酌量",			kana:"じょうじょうしゃくりょう"},
            		{word:"マチュピチュ",		kana:"まちゅぴちゅ"},
            		{word:"なれのはて",		kana:"なれのはて"},
            		{word:"ダブルラリアット",		kana:"だぶるらりあっと"},
				{word:"アルファルファ" , 	kana:"あるふぁるふぁ" },
            		{word:"ちょんまげ",		kana:"ちょんまげ"},
            		{word:"もやしっ子",		kana:"もやしっこ"},
            		{word:"あっけらかん",		kana:"あっけらかん"},
            		{word:"ヤンバルクイナ",		kana:"やんばるくいな"},
            		{word:"老若男女",			kana:"ろうにゃくなんにょ"},
            		{word:"マカロン",			kana:"まかろん"},
            		{word:"小腹",			kana:"こばら"},
            		{word:"ざっくばらん",		kana:"ざっくばらん"},
            		{word:"真人間",			kana:"まにんげん"},
            		{word:"オコジョ",			kana:"おこじょ"},
            		{word:"チチンプイプイ",		kana:"ちちんぷいぷい"},
            		{word:"チョモランマ",		kana:"ちょもらんま"},
            		{word:"プルコギ",			kana:"ぷるこぎ"},
            		{word:"アルパカ",			kana:"あるぱか"},
            		{word:"トンチンカン",		kana:"とんちんかん"},
            		{word:"タクラマカン砂漠",	kana:"たくらまかんさばく"}
            	] ;
            	
            	
			/*typing.addTarget(3);*/
			
			test.autoSize = TextFieldAutoSize.CENTER;
			addChild(test);
			
			with(countFormat){
				size = 50;
				font = "メイリオ";
				bold = true;
			}
			with(countField){
				text = "制限時間";
				x=50;
				y=10;
				alpha=0.4;
				autoSize = TextFieldAutoSize.CENTER;
			}
			countField.setTextFormat(countFormat);
			
			with(finFormat){
				size = 88;
				color=0x000000;
				font = "メイリオ";
				bold = true;
			}
			with(finField){
				text = "単語数";
				x=320;
				y=130;
				alpha=0.6;
				autoSize = TextFieldAutoSize.CENTER;
			}
			finField.setTextFormat(finFormat);
			
			
			with(touchFormat){
				size = 108;
				color=0xFF0000;
				font = "メイリオ";
				bold = true;
			}
			with(touchField){
				text = "タイプ数";
				x=290;
				y=-30;
				alpha=0.6;
				autoSize = TextFieldAutoSize.CENTER;
			}
			touchField.setTextFormat(touchFormat);
			
			
			with(missFormat){
				size = 38;
				color=0xFF6600;
				font = "メイリオ";
				bold = true;
			}
			with(missField){
				text = "ミスタイプ数";
				x=120;
				y=200;
				alpha=0.7;
				autoSize = TextFieldAutoSize.CENTER;
			}
			missField.setTextFormat(missFormat);
			
		
			with(mesFormat){
				size = 20;
				color=0xFFAA00;
				font = "メイリオ";
				bold = true;
			}
			with(mesField){
				text = "Escキーを押すと始まります。";
				x=220;
				y=380;
				alpha=0.6;
				autoSize = TextFieldAutoSize.CENTER;
			}
			mesField.setTextFormat(mesFormat);
			
			addChild(mesField);
			with(mesFormat2){
				size = 20;
				color=0xFECC00;
				font = "メイリオ";
				bold = true;
			}
			with(mesField2){
				text = "入力は半角英数で行ってください";
				x=150;
				y=340;
				alpha=0.6;
				autoSize = TextFieldAutoSize.CENTER;
			}
			mesField2.setTextFormat(mesFormat2);
			addChild(mesField2);
			
			
			addChildAt(touchField,0);
			addChildAt(missField,0);
			addChildAt(countField,0);
			addChildAt(finField,0);
			
			addChild(typing);
    			stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
        }
        public function start():void{
			mesField.visible = false;
			
			touchField.visible = true;
			missField.visible = true;
			countField.visible = true;
			finField.visible = true;
			
			finField.text = "0";
			missField.text = "0";
			touchField.text = "0";
			
			missField.setTextFormat(missFormat);
			touchField.setTextFormat(touchFormat);
			finField.setTextFormat(finFormat);
			
			
            	typing.play = true;
        		countDown = time;
	    		timeCheck2.addEventListener(TimerEvent.TIMER, count);
			timeCheck2.start();
	    		
			timeCheck.addEventListener(TimerEvent.TIMER, add);
			timeCheck.start();
        }
        public function stop():void{
			mesField.visible = true;
			
            	typing.play = false;
			timeCheck2.stop();
			timeCheck.stop();
        }
        
        public function add(e:Event):void{
        		typing.addTarget(1);
        }
        public function count(e:Event):void{
        		countField.text =""+ countDown;
        		countField.setTextFormat(countFormat);
        		
        		
	        		
	        	finField.text =""+ typing.finWord;
	        	finField.setTextFormat(finFormat);
	        		
        		countDown-=3;
        		if(countDown<0){
        			stop();		//3/30 ここになぜかstart();が入っていたので修正
        			countDown=0;
        		}
        }
        public function KeyDown(e:KeyboardEvent):void{
        		if(e.keyCode==27){
        			stop();start();
        		}else{
	        		typing.typed += String.fromCharCode(e.charCode);

	        		touchField.text =""+ typing.touch;
	        		touchField.setTextFormat(touchFormat);
	        		
	        		missField.text =""+ typing.missTouch;
	        		missField.setTextFormat(missFormat);
	        	}
        }
    }
    
}

import flash.display.Sprite;
import flash.text.*;
import flash.events.*;


class TypingWindow extends Sprite{
	private var _width:int = 200;
	private var _height:int = 90;
	
	
	public function set kana(t:String):void{
		kanaField.text = t;
		kanaField.setTextFormat(kanaFormat);
	}
	public function set word(t:String):void{
		typeField.text = t;
		typeField.setTextFormat(typeFormat);
	}
	public function set typedRoman(t:String):void{
		var l:int = t.length;				
		if (l >= romanField.text.length){		
			l = romanField.text.length-1;
		}
		romanField.setTextFormat(typingFormat,-1,l);
		
	}
	public function set roman(t:String):void{
		romanField.text = t;
		romanField.setTextFormat(romanFormat);
	}
	
	
	private var kanaField:TextField = new TextField();
	private var typeField:TextField = new TextField();
	private var romanField:TextField = new TextField();
	
	private var typeFormat:TextFormat = new TextFormat();
	private var typingFormat:TextFormat = new TextFormat();
	private var kanaFormat:TextFormat = new TextFormat();
	private var romanFormat:TextFormat = new TextFormat();
	
	
	public function TypingWindow(){
		x = 225*Math.random();
		y = 375*Math.random();
		drow();
		with(kanaFormat){
			size = 13;
			font = "MS ゴシック";
			bold = true;
		}
		with(kanaField){
			autoSize = TextFieldAutoSize.CENTER;
		}
		kanaField.y = 10;
		kanaField.x = width/2 - kanaField.width/2;
		addChild(kanaField);
		
		
		with(typingFormat){
			color = 0x666666;
		}
		with(typeFormat){
			size = 20;
			font = "メイリオ";
			bold = true;
		}
		with(typeField){
			autoSize = TextFieldAutoSize.CENTER;
			setTextFormat(typeFormat);
		}
		
		typeField.y = 25;
		typeField.x = width/2 - typeField.width/2;
		addChild(typeField);
		
		
		with(romanFormat){
			size = 18;
		}
		with(romanField){
			autoSize = TextFieldAutoSize.CENTER;
		}
		romanField.y = 55;
		romanField.x = width/2 - romanField.width/2;
		addChild(romanField);
	}

	public function drow():void{
		graphics.lineStyle (4, 0x000000, 0.9);	// 線のスタイル指定
		graphics.beginFill (0xAAAACC, 0.7);	// 面のスタイル設定
		graphics.drawRoundRect  (0, 0, _width, _height , 20 , 20);
	}
}





class Typing extends Sprite{
	public var _typed:String ="";
	public function set typed(s:String):void{setTyped(s);}
	public function setTyped(s:String):void{
		var miss:Boolean=true;
		for(var i:int=0;i<target.length;i++){
			if(match(wordList[target[i]].kana,s) == s.length){
				_typed=s;
				var preffered:String = preferredRoman(wordList[target[i]].kana,s);
				if(_typed==preffered){
					finWord++;
					clear(i);
				}
				typingWindows[i].roman = preffered;
				typingWindows[i].typedRoman=_typed;
				miss = false;
			}else{
				typingWindows[i].roman = firstRoman(wordList[target[i]].kana);
			}
		}
		if(miss){
			setTyped(_typed);
			touch--;
			missTouch++;
		}else{
			touch++;
		}
	}
	public function get typed():String{return _typed;}
	
	
	
	public var _play:Boolean =false;
	public function set play(b:Boolean):void{
		if(_play!=b){// 3/31 修正
			_play=b;
			if(b){
				touch=0;
				missTouch=0;
				finWord=0;
				addTarget(3);
			}else{
				while(numChildren > 0){  
	  				removeChildAt(0);  
	  			}  
				typingWindows.splice(0);
				target.splice(0);
				typed="";	
			}
		}
	}
	public function get play():Boolean{return _play;}
	
	
	public var touch:int = 0;
	public var missTouch:int = 0;
	public var finWord:int = 0;
	
	public var typingWindows:Array = new Array();
	private var romanList:Array = new Array();
	
	private var _wordList:Array = new Array(); //単語表
	public function set wordList(list:Array):void{
		_wordList = list;
		unused.splice(0);
		for(var i:int=0;i<_wordList.length;i++){
			unused[i] = i;
		}
	}
	public function get wordList():Array{return _wordList;}

	private var target:Array = new Array();//現在タイプ可能な候補
	private var hint:Array = new Array();//次以降の候補
	
	private var unused:Array = new Array();	//未使用の単語の表
	private var usedNum:int;	//単語表の単語のうちいくつが使用済みか?
		
	public function addTarget(n:int):void{//nだけ候補に単語を追加
		if(_wordList.length < 1){return;}
		for(var i:int=0;i<n;i++){
			if(unused.length==0){
				for(var j:int=0;j<_wordList.length;j++){
					unused[j] = j;
					usedNum=0;
				}
			}
			
			var w:Object;
			var rand:int = Math.random() * unused.length;
			var k:int = unused.splice(rand,1);

			target.push(k);
			typingWindows.push(new TypingWindow());
			
			typingWindows[typingWindows.length-1].kana = wordList[k].kana;
			typingWindows[typingWindows.length-1].word = wordList[k].word;
			typingWindows[typingWindows.length-1].roman = firstRoman(wordList[k].kana);

			addChildAt(typingWindows[typingWindows.length-1],0);
		}
	}
	public function clear(n:int):void{
		removeChild(typingWindows[n]);
		typingWindows.splice(n,1);
		target.splice(n,1);
		if(target.length == 0 && play){addTarget(1);}
		typed="";
	}
	
	public function match(kana:String,roman:String):int{
		//与えられたかなの先頭にromanが最大何文字マッチするかの判定用
		//返り値 == roman.lengthでromanすべてが一致
		var matchLength:int = 0;
		var longest:int = 0;
		var unreaded:String = kana;
		var unreadedRoman:String = roman;
		while(unreaded.length != 0){
			loop1:for(var n:int=4;n>0;n--){//文字数
				for(var m:int=0;m<3;m++){//候補番号
					if(romanList[m][unreaded.substring(0,n)] != undefined){
						var term:String = romanList[m][unreaded.substring(0,n)]
						if(term == unreadedRoman.substring(0,term.length)){
							unreaded = unreaded.substring(n);
							unreadedRoman = unreadedRoman.substring(term.length);
							matchLength += term.length;
							longest = matchLength;
							break loop1;
						}else{
							while(term.length > 1){
								term = term.substring(0,term.length - 1);
								if(term == unreadedRoman.substring(0,term.length)){
									if(longest < matchLength + term.length){longest = matchLength + term.length;}
									break;
								}
							}
						}
					}
				}
			}
			if(n==0){break;}
		}
		return longest;
	}
	
	public function preferredRoman(kana:String,roman:String):String{
		//romanがタイプされているときの最適なローマ字の振り方を返す
		var matchLength:int = 0;
		var longest:int = 0;
		var preferred:String = "";
		var unreaded:String = kana;
		var unreadedRoman:String = roman;
		while(unreaded.length != 0){
			loop1:for(var n:int=4;n>0;n--){//文字数
				for(var m:int=0;m<4;m++){//候補番号
					if(romanList[m][unreaded.substring(0,n)] != undefined){
						var term:String = romanList[m][unreaded.substring(0,n)]
						if(term == unreadedRoman.substring(0,term.length)){
							preferred += term;
							unreaded = unreaded.substring(n);
							unreadedRoman = unreadedRoman.substring(term.length);
							matchLength += term.length;
							longest = matchLength;
							if(roman.length==longest){return preferred + firstRoman(unreaded);}
							break loop1;
						}else{
							var bterm:String = term;
							while(term.length > 1){
								term = term.substring(0,term.length - 1);
								if(term == unreadedRoman.substring(0,term.length)){
									longest = matchLength+term.length;
									if(roman.length==longest){
											preferred += bterm;
											unreaded = unreaded.substring(n);
											unreadedRoman = unreadedRoman.substring(term.length);
											matchLength += term.length;
											longest = matchLength;
											return preferred + firstRoman(unreaded);
									}
									break;
								}
							}
						}
					}
				}
			}
			if(n==0){
				preferred += firstRoman(unreaded);
				break;
			}
		}
		return preferred;
	}
	
	public function firstRoman(kana:String):String{		
		//kanaのもっとも簡単なローマ字の振り方を返す
		var unreaded:String = kana;
		var preferred:String = "";
		while(unreaded.length != 0){
			loop1:for(var n:int=4;n>0;n--){//文字数
				for(var m:int=0;m<4;m++){//候補番号
					
					if(romanList[m][unreaded.substring(0,n)] != undefined){
						preferred += romanList[m][unreaded.substring(0,n)];						
						unreaded = unreaded.substring(n);
						break loop1;
					}
				}
			}
			if(n==0){
				break;
			}
		}
		return preferred;
	}
	
    public function Typing(){

    		romanList = new Array(4); //かなとローマ字の変換表
	   	//候補1------------------------------------------------------------
		romanList[0] = new Array();
		
		romanList[0]["ー"] = "-";
		romanList[0]["。"] = ".";
		romanList[0]["、"] = ",";
		romanList[0]["?"] = "?";
		romanList[0]["!"] = "!";
		romanList[0][" "] = " ";
		romanList[0]["あ"] = "a";
		romanList[0]["い"] = "i";
		romanList[0]["う"] = "u";
		romanList[0]["え"] = "e";
		romanList[0]["お"] = "o";
		romanList[0]["か"] = "ka";
		romanList[0]["き"] = "ki";
		romanList[0]["く"] = "ku";
		romanList[0]["け"] = "ke";
		romanList[0]["こ"] = "ko";
		romanList[0]["さ"] = "sa";
		romanList[0]["し"] = "si";
		romanList[0]["す"] = "su";
		romanList[0]["せ"] = "se";
		romanList[0]["そ"] = "so";
		romanList[0]["な"] = "na";
		romanList[0]["に"] = "ni";
		romanList[0]["ぬ"] = "nu";
		romanList[0]["ね"] = "ne";
		romanList[0]["の"] = "no";
		romanList[0]["た"] = "ta";
		romanList[0]["ち"] = "ti";
		romanList[0]["つ"] = "tu";
		romanList[0]["て"] = "te";
		romanList[0]["と"] = "to";
		romanList[0]["は"] = "ha";
		romanList[0]["ひ"] = "hi";
		romanList[0]["ふ"] = "fu";
		romanList[0]["へ"] = "he";
		romanList[0]["ほ"] = "ho";
		romanList[0]["ま"] = "ma";
		romanList[0]["み"] = "mi";
		romanList[0]["む"] = "mu";
		romanList[0]["め"] = "me";
		romanList[0]["も"] = "mo";
		romanList[0]["や"] = "ya";
		romanList[0]["ゆ"] = "yu";
		romanList[0]["いぇ"] = "ye";
		romanList[0]["よ"] = "yo";
		romanList[0]["ら"] = "ra";
		romanList[0]["り"] = "ri";
		romanList[0]["る"] = "ru";
		romanList[0]["れ"] = "re";
		romanList[0]["ろ"] = "ro";
		romanList[0]["わ"] = "wa";
		romanList[0]["ゐ"] = "wi";
		romanList[0]["ゑ"] = "we";
		romanList[0]["を"] = "wo";
		romanList[0]["が"] = "ga";
		romanList[0]["ぎ"] = "gi";
		romanList[0]["ぐ"] = "gu";
		romanList[0]["げ"] = "ge";
		romanList[0]["ご"] = "go";
		romanList[0]["ざ"] = "za";
		romanList[0]["じ"] = "ji";
		romanList[0]["ず"] = "zu";
		romanList[0]["ぜ"] = "ze";
		romanList[0]["ぞ"] = "zo";
		romanList[0]["だ"] = "da";
		romanList[0]["ぢ"] = "di";
		romanList[0]["づ"] = "du";
		romanList[0]["で"] = "de";
		romanList[0]["ど"] = "do";
		romanList[0]["ば"] = "ba";
		romanList[0]["び"] = "bi";
		romanList[0]["ぶ"] = "bu";
		romanList[0]["べ"] = "be";
		romanList[0]["ぼ"] = "bo";
		romanList[0]["ぱ"] = "pa";
		romanList[0]["ぴ"] = "pi";
		romanList[0]["ぷ"] = "pu";
		romanList[0]["ぺ"] = "pe";
		romanList[0]["ぽ"] = "po";
		romanList[0]["ぁ"] = "la";
		romanList[0]["ぃ"] = "li";
		romanList[0]["ぅ"] = "lu";
		romanList[0]["ぇ"] = "le";
		romanList[0]["ぉ"] = "lo";
		romanList[0]["ゃ"] = "lya";
		romanList[0]["ゅ"] = "lyu";
		romanList[0]["ょ"] = "lyo";
		romanList[0]["ゎ"] = "lwa";
		romanList[0]["っ"] = "ltu";
		romanList[0]["きゃ"] = "kya";
		romanList[0]["きぃ"] = "kyi";
		romanList[0]["きゅ"] = "kyu";
		romanList[0]["きぇ"] = "kye";
		romanList[0]["きょ"] = "kyo";
		romanList[0]["しゃ"] = "sya";
		romanList[0]["しぃ"] = "syi";
		romanList[0]["しゅ"] = "syu";
		romanList[0]["しぇ"] = "sye";
		romanList[0]["しょ"] = "syo";
		romanList[0]["ちゃ"] = "tya";
		romanList[0]["ちぃ"] = "tyi";
		romanList[0]["ちゅ"] = "tyu";
		romanList[0]["ちぇ"] = "tye";
		romanList[0]["ちょ"] = "tyo";
		romanList[0]["にゃ"] = "nya";
		romanList[0]["にぃ"] = "nyi";
		romanList[0]["にゅ"] = "nyu";
		romanList[0]["にぇ"] = "nye";
		romanList[0]["にょ"] = "nyo";
		romanList[0]["ひゃ"] = "hya";
		romanList[0]["ひぃ"] = "hyi";
		romanList[0]["ひゅ"] = "hyu";
		romanList[0]["ひぇ"] = "hye";
		romanList[0]["ひょ"] = "hyo";
		romanList[0]["みゃ"] = "mya";
		romanList[0]["みぃ"] = "myi";
		romanList[0]["みゅ"] = "myu";
		romanList[0]["みぇ"] = "mye";
		romanList[0]["みょ"] = "myo";
		romanList[0]["りゃ"] = "rya";
		romanList[0]["りぃ"] = "ryi";
		romanList[0]["りゅ"] = "ryu";
		romanList[0]["りぇ"] = "rye";
		romanList[0]["りょ"] = "ryo";
		romanList[0]["ぎゃ"] = "gya";
		romanList[0]["ぎぃ"] = "gyi";
		romanList[0]["ぎゅ"] = "gyu";
		romanList[0]["ぎぇ"] = "gye";
		romanList[0]["ぎょ"] = "gyo";
		romanList[0]["じゃ"] = "ja";
		romanList[0]["じぃ"] = "zyi";
		romanList[0]["じゅ"] = "ju";
		romanList[0]["じぇ"] = "je";
		romanList[0]["じょ"] = "jo";
		romanList[0]["ぢゃ"] = "dya";
		romanList[0]["ぢぃ"] = "dyi";
		romanList[0]["ぢゅ"] = "dyu";
		romanList[0]["ぢぇ"] = "dye";
		romanList[0]["ぢょ"] = "dyo";
		romanList[0]["びゃ"] = "bya";
		romanList[0]["びぃ"] = "byi";
		romanList[0]["びゅ"] = "byu";
		romanList[0]["びぇ"] = "bye";
		romanList[0]["びょ"] = "byo";
		romanList[0]["ぴゃ"] = "pya";
		romanList[0]["ぴぃ"] = "pyi";
		romanList[0]["ぴゅ"] = "pyu";
		romanList[0]["ぴぇ"] = "pye";
		romanList[0]["ぴょ"] = "pyo";
		romanList[0]["うぁ"] = "wa";
		romanList[0]["うぃ"] = "wi";
		romanList[0]["うぇ"] = "we";
		romanList[0]["うぉ"] = "wo";
		romanList[0]["ヴぁ"] = "va";
		romanList[0]["ヴぃ"] = "vi";
		romanList[0]["ヴ"] = "vu";
		romanList[0]["ヴぇ"] = "ve";
		romanList[0]["ヴぉ"] = "vo";
		romanList[0]["ヴゃ"] = "vya";
		romanList[0]["ヴゅ"] = "vyu";
		romanList[0]["ヴょ"] = "vyo";
		romanList[0]["てゃ"] = "tha";
		romanList[0]["てぃ"] = "thi";
		romanList[0]["てゅ"] = "thu";
		romanList[0]["てぇ"] = "the";
		romanList[0]["てょ"] = "tho";
		romanList[0]["ふぁ"] = "fa";
		romanList[0]["ふぃ"] = "fi";
		romanList[0]["ふぅ"] = "fwu";
		romanList[0]["ふぇ"] = "fe";
		romanList[0]["ふぉ"] = "fo";
		romanList[0]["ふゃ"] = "fya";
		romanList[0]["ふゅ"] = "fyu";
		romanList[0]["ふょ"] = "fyo";
		romanList[0]["でゃ"] = "dha";
		romanList[0]["でぃ"] = "dhi";
		romanList[0]["でゅ"] = "dhu";
		romanList[0]["でぇ"] = "dhe";
		romanList[0]["でょ"] = "dho";
		romanList[0]["くぁ"] = "qa";
		romanList[0]["くぃ"] = "qi";
		romanList[0]["くぅ"] = "qwu";
		romanList[0]["くぇ"] = "qe";
		romanList[0]["くぉ"] = "qo";
		romanList[0]["くゃ"] = "qya";//何て読むんだよ,これ。
		romanList[0]["くゅ"] = "qyu";
		romanList[0]["くょ"] = "qyo";
		romanList[0]["すぁ"] = "swa";
		romanList[0]["すぃ"] = "swi";
		romanList[0]["すぅ"] = "swu";
		romanList[0]["すぇ"] = "swe";
		romanList[0]["すぉ"] = "swo";
		romanList[0]["ぐぁ"] = "gwa";
		romanList[0]["ぐぃ"] = "gwi";
		romanList[0]["ぐぅ"] = "gwu";
		romanList[0]["ぐぇ"] = "gwe";
		romanList[0]["ぐぉ"] = "gwo";
		romanList[0]["どぁ"] = "dwa";
		romanList[0]["どぃ"] = "dwi";
		romanList[0]["どぅ"] = "dwu";
		romanList[0]["どぇ"] = "dwe";
		romanList[0]["どぉ"] = "dwo";
		romanList[0]["とぁ"] = "twa";
		romanList[0]["とぃ"] = "twi";
		romanList[0]["とぅ"] = "twu";
		romanList[0]["とぇ"] = "twe";
		romanList[0]["とぉ"] = "two";
		romanList[0]["つぁ"] = "tsa";
		romanList[0]["つぃ"] = "tsi";
		romanList[0]["つぇ"] = "tse";
		romanList[0]["つぉ"] = "tso";
		romanList[0]["ん"] = "nn";
	//候補2------------------------------------------------------------
		romanList[1] = new Array();
		
		romanList[1]["い"] = "yi";
		romanList[1]["う"] = "wu";
		romanList[1]["うぁ"] = "wha";
		romanList[1]["うぃ"] = "whi";
		romanList[1]["うぇ"] = "whe";
		romanList[1]["うぉ"] = "who";
		romanList[1]["う"] = "wu";
		romanList[1]["か"] = "ca";
		romanList[1]["く"] = "cu";
		romanList[1]["こ"] = "co";
		romanList[1]["くぃ"] = "qwi";
		romanList[1]["くぅ"] = "qwu";
		romanList[1]["くぇ"] = "qwe";
		romanList[1]["くぉ"] = "qwo";
		romanList[1]["くぁ"] = "kwa";
		romanList[1]["くぃ"] = "qwi";
		romanList[1]["くぅ"] = "qwu";
		romanList[1]["くぇ"] = "qwe";
		romanList[1]["くぉ"] = "qwo";
		romanList[1]["しゃ"] = "sha";
		romanList[1]["し"] = "shi";
		romanList[1]["しゅ"] = "shu";
		romanList[1]["しぇ"] = "she";
		romanList[1]["しょ"] = "sho";
		romanList[1]["せ"] = "ce";
		romanList[1]["じ"] = "zi";
		romanList[1]["じゃ"] = "zya";
		romanList[1]["じぃ"] = "jyi";
		romanList[1]["じゅ"] = "zyu";
		romanList[1]["じぇ"] = "zye";
		romanList[1]["じょ"] = "zyo";
		romanList[1]["ちゃ"] = "cha";
		romanList[1]["ち"] = "chi";
		romanList[1]["ちぃ"] = "cyi";
		romanList[1]["ちゅ"] = "chu";
		romanList[1]["ちぇ"] = "che";
		romanList[1]["ちょ"] = "cho";
		romanList[1]["つ"] = "tsu";
		romanList[1]["ふ"] = "hu";
		romanList[1]["ふぁ"] = "fwa";
		romanList[1]["ふぃ"] = "fwi";
		romanList[1]["ふぇ"] = "fwe";
		romanList[1]["ふぉ"] = "fwo";
		romanList[1]["ぁ"] = "xa";
		romanList[1]["ぃ"] = "xi";
		romanList[1]["ぅ"] = "xu";
		romanList[1]["ぇ"] = "xe";
		romanList[1]["ぉ"] = "xo";
		romanList[1]["ゃ"] = "xya";
		romanList[1]["ゅ"] = "xyi";
		romanList[1]["ょ"] = "xyu";
		romanList[1]["ゎ"] = "xwa";
		romanList[1]["っ"] = "ltsu";
	//候補3------------------------------------------------------------
		romanList[2] = new Array();
		romanList[2]["う"] = "whu";
		romanList[2]["し"] = "ci";
		romanList[2]["くぁ"] = "qwa";
		romanList[2]["くぃ"] = "qyi";
		romanList[2]["くぇ"] = "qye";
		romanList[2]["じゃ"] = "jya";
		romanList[2]["じゅ"] = "jyu";
		romanList[2]["じぇ"] = "jye";
		romanList[2]["じょ"] = "jyo";
		romanList[2]["ちゃ"] = "cya";
		romanList[2]["ちゅ"] = "cyu";
		romanList[2]["ちぇ"] = "cye";
		romanList[2]["ちょ"] = "cyo";
		romanList[2]["ふぃ"] = "fyi";
		romanList[2]["ふぇ"] = "fye";
		romanList[2]["ふぉ"] = "fwo";
		romanList[2]["ぃ"] = "lyi";
		romanList[2]["ぇ"] = "lye";
	//候補4------------------------------------------------------------
		romanList[3] = new Array();
		romanList[3]["ぃ"] = "xyi";
		romanList[3]["ぇ"] = "xye";
		
		//一文字目になるひらがな表
		var beforetse1:Array = [
				"あ","い","う","え","お",
				"か","き","く","け","こ",
				"さ","し","す","せ","そ",
				"た","ち","つ","て","と",
				"は","ひ","ふ","へ","ほ",
				"ま","み","む","め","も",
				"や","ゆ","よ",
				"わ","ゐ","う","ヱ","を","ん",
				"ら","り","る","れ","ろ",
				"が","ぎ","ぐ","げ","ご",
				"ざ","じ","ず","ぜ","ぞ",
				"だ","ぢ","づ","で","ど",
				"ば","び","ぶ","べ","ぼ",
				"ぱ","ぴ","ぷ","ぺ","ぽ","ヴ",
				"ゃ","ゅ","ょ","ゎ",
				"ぁ","ぃ","ぅ","ぇ","ぉ",
				"!","?",".",","," "
				];

		var beforetse2:Array = ["","ゃ","ゅ","ょ",
				"ぁ","ぃ","ぅ","ぇ","ぉ"
				];
		
		//連続すると「っ」になるアルファベット 
		var tse:Array =["q","w","r","t","y","p","s","d","f","g","h","j","k","l","z","x","c","v","b","m"];
		
	
		//直前にn 1つで「ん」になるアルファベット
		var nn:Array =["q","w","r","t","p","s","d","f","g","h","j","k","l","z","x","c","v","b","m","!","?",".",","," "];
 
 		//「っ」の付く候補作成
		for(var i:int = 0;i < beforetse1.length;i++){	
			for(var j:int = 0;j < beforetse2.length;j++){
				for(var k:int = 0;k < 4;k++){
					var ok1:Boolean = false;
					if( romanList[k][ beforetse1[i]+beforetse2[j] ] !=undefined){
						for(var n:int=0;n<tse.length;n++){
							if(romanList[k][ beforetse1[i]+beforetse2[j] ].substring(0,1) == tse[n]){ok1 = true;}
						}
					}
					if( ok1 ){
						romanList[k][ "っ"+beforetse1[i]+beforetse2[j] ] = romanList[k][ beforetse1[i]+beforetse2[j] ].substr(0,1) + romanList[k][ beforetse1[i]+beforetse2[j] ];
					}
		
					var ok2:Boolean = false;
					if( romanList[k][ beforetse1[i]+beforetse2[j] ] !=undefined){
						for(n=0;n<tse.length;n++){
							if(romanList[k][ beforetse1[i]+beforetse2[j] ].substring(0,1) == nn[n]){ok2 = true;}
						}
					}
					if( ok2 ){
						romanList[k][ "ん"+beforetse1[i]+beforetse2[j] ] = "n" + romanList[k][ beforetse1[i]+beforetse2[j] ];
					}
					if( ok1 && ok2 ){
						romanList[k][ "ん"+"っ"+beforetse1[i]+beforetse2[j] ] = "n" + romanList[k][ beforetse1[i]+beforetse2[j] ].substr(0,1) + romanList[k][ beforetse1[i]+beforetse2[j] ];
					}
				}
			}
		}
    	}
}

Forked