Metroid Code Breaker

NES password generator in AS3

Metroid Code Breaker

src/nu/xero/flex/theCode.mxml


<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas horizontalScrollPolicy="off" verticalScrollPolicy="off" xmlns:mx="http://www.adobe.com/2006/mxml" width="364" height="86" backgroundColor="#000000" color="#FFFFFF">
<mx:Script>
	<![CDATA[
		public  var hasFocus		:Boolean = false;
		public  var cursorPos		:Number;
		private var thepass			:String;
		private var pass			:Array;
		private var fontLower		:String = "<font color=\"#3cbcfc\">";
		private var fontUpper		:String = "<font color=\"#4cdc48\">";
		private var fontEnd			:String = "</font>";
		private var blink			:Number = 1;
		private var i				:Number;
	
		public function setPass(password:Array):void {
			looseCodeFocus();
			thePassword.htmlText = "";
			thepass = "";
			i = 0;
			while(i < 24)
			{
				//spacing
				if(i == 6 || i == 18){
					thePassword.htmlText += " ";
				} else if(i == 12){
					thePassword.htmlText += "\n";
				}
				switch (password[i]) {
					case 0:
						thePassword.htmlText += fontUpper + "0" + fontEnd;
					break;
					case 1:
						thePassword.htmlText += fontUpper + "1" + fontEnd;
					break;
					case 2:
						thePassword.htmlText += fontUpper + "2" + fontEnd;
					break;
					case 3:
						thePassword.htmlText += fontUpper + "3" + fontEnd;
					break;
					case 4:
						thePassword.htmlText += fontUpper + "4" + fontEnd;
					break;
					case 5:
						thePassword.htmlText += fontUpper + "5" + fontEnd;
					break;
					case 6:
						thePassword.htmlText += fontUpper + "6" + fontEnd;
					break;
					case 7:
						thePassword.htmlText += fontUpper + "7" + fontEnd;
					break;
					case 8:
						thePassword.htmlText += fontUpper + "8" + fontEnd;
					break;
					case 9:
						thePassword.htmlText += fontUpper + "9" + fontEnd;
					break;
					case 10:
						thePassword.htmlText += fontUpper + "A" + fontEnd;
					break;
					case 11:
						thePassword.htmlText += fontUpper + "B" + fontEnd;
					break;
					case 12:
						thePassword.htmlText += fontUpper + "C" + fontEnd;
					break;
					case 13:
						thePassword.htmlText += fontUpper + "D" + fontEnd;
					break;
					case 14:
						thePassword.htmlText += fontUpper + "E" + fontEnd;
					break;
					case 15:
						thePassword.htmlText += fontUpper + "F" + fontEnd;
					break;
					case 16:
						thePassword.htmlText += fontUpper + "G" + fontEnd;
					break;
					case 17:
						thePassword.htmlText += fontUpper + "H" + fontEnd;
					break;
					case 18:
						thePassword.htmlText += fontUpper + "I" + fontEnd;
					break;
					case 19:
						thePassword.htmlText += fontUpper + "J" + fontEnd;
					break;
					case 20:
						thePassword.htmlText += fontUpper + "K" + fontEnd;
					break;
					case 21:
						thePassword.htmlText += fontUpper + "L" + fontEnd;
					break;
					case 22:
						thePassword.htmlText += fontUpper + "M" + fontEnd;
					break;
					case 23:
						thePassword.htmlText += fontUpper + "N" + fontEnd;
					break;
					case 24:
						thePassword.htmlText += fontUpper + "O" + fontEnd;
					break;
					case 25:
						thePassword.htmlText += fontUpper + "P" + fontEnd;
					break;
					case 26:
						thePassword.htmlText += fontUpper + "Q" + fontEnd;
					break;
					case 27:
						thePassword.htmlText += fontUpper + "R" + fontEnd;
					break;
					case 28:
						thePassword.htmlText += fontUpper + "S" + fontEnd;
					break;
					case 29:
						thePassword.htmlText += fontUpper + "T" + fontEnd;
					break;
					case 30:
						thePassword.htmlText += fontUpper + "U" + fontEnd;
					break;
					case 31:
						thePassword.htmlText += fontUpper + "V" + fontEnd;
					break;
					case 32:
						thePassword.htmlText += fontUpper + "W" + fontEnd;
					break;
					case 33:
						thePassword.htmlText += fontUpper + "X" + fontEnd;
					break;
					case 34:
						thePassword.htmlText += fontUpper + "Y" + fontEnd;
					break;
					case 35:
						thePassword.htmlText += fontUpper + "Z" + fontEnd;
					break;
					case 36:
						thePassword.htmlText += fontLower+ "a" + fontEnd;
					break;
					case 37:
						thePassword.htmlText += fontLower+ "b" + fontEnd;
					break;
					case 38:
						thePassword.htmlText += fontLower+ "c" + fontEnd;
					break;
					case 39:
						thePassword.htmlText += fontLower+ "d" + fontEnd;
					break;
					case 40:
						thePassword.htmlText += fontLower+ "e" + fontEnd;
					break;
					case 41:
						thePassword.htmlText += fontLower+ "f" + fontEnd;
					break;
					case 42:
						thePassword.htmlText += fontLower+ "g" + fontEnd;
					break;
					case 43:
						thePassword.htmlText += fontLower+ "h" + fontEnd;
					break;
					case 44:
						thePassword.htmlText += fontLower+ "i" + fontEnd;
					break;
					case 45:
						thePassword.htmlText += fontLower+ "j" + fontEnd;
					break;
					case 46:
						thePassword.htmlText += fontLower+ "k" + fontEnd;
					break;
					case 47:
						thePassword.htmlText += fontLower+ "l" + fontEnd;
					break;
					case 48:
						thePassword.htmlText += fontLower+ "m" + fontEnd;
					break;
					case 49:
						thePassword.htmlText += fontLower+ "n" + fontEnd;
					break;
					case 50:
						thePassword.htmlText += fontLower+ "o" + fontEnd;
					break;
					case 51:
						thePassword.htmlText += fontLower+ "p" + fontEnd;
					break;
					case 52:
						thePassword.htmlText += fontLower+ "q" + fontEnd;
					break;
					case 53:
						thePassword.htmlText += fontLower+ "r" + fontEnd;
					break;
					case 54:
						thePassword.htmlText += fontLower+ "s" + fontEnd;
					break;
					case 55:
						thePassword.htmlText += fontLower+ "t" + fontEnd;
					break;
					case 56:
						thePassword.htmlText += fontLower+ "u" + fontEnd;
					break;
					case 57:
						thePassword.htmlText += fontLower+ "v" + fontEnd;
					break;
					case 58:
						thePassword.htmlText += fontLower+ "w" + fontEnd;
					break;
					case 59:
						thePassword.htmlText += fontLower+ "x" + fontEnd;
					break;
					case 60:
						thePassword.htmlText += fontLower+ "y" + fontEnd;
					break;
					case 61:
						thePassword.htmlText += fontLower+ "z" + fontEnd;
					break;
					case 62:
						thePassword.htmlText += fontLower+ "?" + fontEnd;
					break;
					case 63:
						thePassword.htmlText += fontLower+ "-" + fontEnd;
					break;
				}
				thepass += password[i].toString();
				i++;
			}
		}
		public function getPass():Array {
			pass = new Array();
			i = 0;
			while(i < 24) {
				pass[i] = thepass.substr(i, 1);
				i++;
			}
			return pass;
		}
		public function looseCodeFocus():void {
			hasFocus = false;
			theCursor.visible = false;			
			blink = 1;
		}
		public function getCodeFocus():void {
			if(hasFocus == false){
				hasFocus = true;
				cursorPos = 1;
				theCursor.x = 0;
				theCursor.y = 6;
			}
		}
		public function moveLeft():void {
			if((cursorPos > 1 && cursorPos < 7) || (cursorPos > 7 && cursorPos < 13) || (cursorPos > 13 && cursorPos < 19) || (cursorPos > 19 && cursorPos < 25)){
				theCursor.x -= 27.5;
			} else if(cursorPos == 7 || cursorPos == 19) {
				theCursor.x -= 55;
			} else if(cursorPos == 13) {
				theCursor.y -= 36;
				theCursor.x += 330;
			} else if(cursorPos == 1) {
				theCursor.y += 36;
				theCursor.x += 330;
				cursorPos = 25;
			}
			cursorPos--;
		}
		public function moveRight():void {
			if((cursorPos > 0 && cursorPos < 6) || (cursorPos > 6 && cursorPos < 12) || (cursorPos > 12 && cursorPos < 18) || (cursorPos > 18 && cursorPos < 24)) {
				theCursor.x += 27.5;
			} else if(cursorPos == 6 || cursorPos == 18) {
				theCursor.x += 55;
			} else if(cursorPos == 12) {
				theCursor.y += 36;
				theCursor.x -= 330;
			} else if(cursorPos == 24) {
				theCursor.y -= 36;
				theCursor.x -= 330;
				cursorPos = 0;
			}
			cursorPos++;
		}
		private function blinker():void {
			if(hasFocus){
				if(blink == 1){
					theCursor.visible = true;
				} else if(blink == 5) {
					theCursor.visible = false;
				} else if(blink == 10){
					blink = 0;
				}
				blink++;
			}
		}
	]]>
</mx:Script>
	<mx:Label toolTip="" id="thePassword" text="000000 000000" x="0" y="0" letterSpacing="5" styleName="NARPASSWORD" height="86" width="364" textAlign="center" fontGridFitType="pixel" fontAntiAliasType="advanced" fontSharpness="200"/>
	<mx:Image x="0" y="6" source="@Embed('assets/cursor.png')" id="theCursor" enterFrame="blinker()" visible="false"/>
</mx:Canvas>

Download

raw zip tar