I almost like easter eggs more than moustaches

Sometimes I like to pretend that in every website I do, I have and easter egg.
Sometimes I share it with friends and sometimes I dont. Its a kind of therapy that helps me keep excited about a project. Weird I know.

So, this is how I usually do it.

Somewhere in your Application, you should have this code

package
{	
	import flash.display.Sprite;
	import love.utils.Cheats;
 
	public class Main extends Sprite
	{
		public function Main()
		{		
			var cheats:Cheats = Cheats.getInstance();
			cheats.addWord("lorem ipsum", cheat1);
			cheats.addWord("user has no moustache", cheat2);
			cheats.enable(true);
		}
 
		public function cheat1():void
		{
			trace("do some shit");
		}	
 
		public function cheat2():void
		{
			trace("close website, user is lamme!");
		}
	}
}

So, if the user for some reason type in the sentence “LOREM IPSUM” it automatically call the cheat1 function. This adds a lot of creative possibilities.

package love.utils
{	
	import flash.events.KeyboardEvent;
 
	import love.core.debug.TheDebugger;//this class Is just for debugging, you can change the TheDebugger.lot() to trace().
	import love.core.setup.StageDefinition;//This class stores the stage reference, you can change the StageDefinition.STAGE to Stage.
 
	public class Cheats
	{
		protected static var instance:Cheats;
		private var words:Array = [];
		private var possible:Array = [];
		private var currentChar:uint = 0;
		public function Cheats()
		{
			if(instance != null)TheDebugger.error("Cheats Singleton already constructed!");
			instance = this;
		}
 
		public static function getInstance():Cheats 
		{
			if(instance == null)instance = new Cheats();
			return instance;
		}
 
		public function addWord(word:String, func:Function):void
		{
			var obj:Object	= new Object();
			obj.word	= word;
			obj.func	= func;
			words.push(obj);
		}
 
		public function enable(value:Boolean):void
		{
			if(value)
			{
				StageDefinition.STAGE.addEventListener(KeyboardEvent.KEY_DOWN, checkForSequence);
			}
		}
 
		private function checkForSequence(e:KeyboardEvent):void
		{
			var valid:Boolean = false;
			for(var i:uint = 0; i<words.length;++i)
			{
				if(checkLetterInWord(e.charCode, words[i].word))
				{
					possible.push(words[i]);
					valid = true;
				}
			}
 
			//var char:String = String.fromCharCode(e.charCode);
			checkValidWord(valid);
			possible =[];
		}
 
		private function checkValidWord(valid:Boolean):void
		{
			if(valid)
			{
				currentChar++;
 
				if(currentChar == possible[0].word.length)
				{
					possible[0].func();
					resetCharCount();
				}
			}
			else
			{
				resetCharCount()
			}
		}
 
		private function resetCharCount():void
		{
			currentChar = 0;
		}
 
 
		private function checkLetterInWord(code:Number, word:String):Boolean
		{
			return code == word.charCodeAt(currentChar) ? true : false;
		}
	}
}

Now, lets take this baby for a ride

Get Adobe Flash player

You can download the source here.

Comments are closed.