package com.Tutorial 
{
    import com.adamatomic.flixel.*;
	/**
	 * ...
	 * @author Stephen Lavelle
	 */
	public class CalculateState extends FlxState
	{
		private var _introTimer:Number;
		private var _pressed:Boolean;
		private var _gameOver:Boolean;
		private var _text:FlxText;
		public static var mode:int;
		
		private var _talk:Array =  [
				["Now, what does one get if one calculates the square root of minus one, I wonder?", "Let's try and find out!"],
				["What does one get if one divides one by zero?", "Let's look and see!"],
				["What does one get if one adds one to one ot one to one and never stop?", "Let's try out!"],
				["One thing I've always wondered is: what's zero to the power of zero?","Only one way to know for sure: to calculate!"]
				]
		private var _curline:int = 0;
		
		public function CalculateState():void
		{
			_introTimer = 2;
			_pressed = false;
			_text = new FlxText(0, 10, FlxG.width, FlxG.height, "", 0xffc35752, null, 32, "left");
			_curline = -1;
			updatetext();
			this.add(_text);			
		
		}
		
		private function updatetext():Boolean
		{
			_curline++;
			if (_curline < 2)
			{
				_text.setText(_talk[mode][_curline] , true);
				return false;
			}
			else if(_curline==2)
			{
				var val:int;
				switch (mode)
				{
					case 0:
						_text.setText("The answer is ".concat(Math.sqrt(-1).toString()).concat(".\n\n Hurrah!!!"));
					break;
					case 1:
						_text.setText("The answer is ".concat((1/0).toString()).concat(".\n\n Hurrah!!!"));
					break;
					case 2:
						var i:int;
						for (var j:int = 0; true; j++)
						{
							i += 1;
						}
						_text.setText("The answer is ".concat(i).toString().concat(".\n\n Hurrah!!!"));
					break;
					case 3:
						_text.setText("The answer is ".concat(Math.pow(0, 0).toString()).concat(".\n\n Hurrah!!!"));
					break;
				}
				return false;
			}
			else return true;
		}
        override public function update():void
		{			
			if (FlxG.justPressed(FlxG.A || FlxG.B))
			{
				if (updatetext())
					FlxG.switchState(WalkState);
			}

			super.update();
		}		
	}
}