home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.display.Sprite;
- import flash.display.StageQuality;
- import flash.events.Event;
- import flash.events.KeyboardEvent;
- import flash.net.SharedObject;
- import flash.net.URLRequest;
-
- public class Game extends Sprite
- {
-
- private static var soundBar:SoundBar;
-
- public static var kongregate:*;
-
- public static var background:Background;
-
- public static const MIDX:Number = 200;
-
- public static var colorBlind:Boolean = false;
-
- public static var cookie:SharedObject;
-
- public static var cheatHasBeenFound:Boolean = false;
-
- public static var quality:int;
-
-
- private var level:Level;
-
- private var black:Sprite;
-
- private var titleScreen:TitleScreen;
-
- public function Game()
- {
- super();
- addEventListener(Event.ADDED_TO_STAGE,addedToStage,false,0,true);
- }
-
- public static function completeLevel(param1:int, param2:int, param3:int) : void
- {
- if(param1 > 0)
- {
- setLevelComplete(param1,true);
- submitLevelsCompleted();
- }
- else if(param1 == Level.BASIC_RANDOM)
- {
- if(kongregate)
- {
- trace("Size",param2,"in",param3,"seconds.");
- kongregate.stats.submit("Random Size " + param2,param3);
- }
- }
- }
-
- public static function nextQuality() : void
- {
- setQuality((quality + 1) % 6);
- }
-
- public static function setLevelComplete(param1:int, param2:Boolean) : void
- {
- if(!param2)
- {
- cookie.data.levelsComplete[param1] = 0;
- return;
- }
- RandomNumber.initialize(cookie.data.levelsComplete[0]);
- var _loc3_:int = 0;
- while(_loc3_ < param1)
- {
- RandomNumber.random();
- _loc3_++;
- }
- cookie.data.levelsComplete[param1] = (int(RandomNumber.random() * 1111) % 13 + 3) * param1;
- cookie.flush();
- }
-
- public static function getLevelComplete(param1:int) : Boolean
- {
- RandomNumber.initialize(cookie.data.levelsComplete[0]);
- var _loc2_:int = 0;
- while(_loc2_ < param1)
- {
- RandomNumber.random();
- _loc2_++;
- }
- return cookie.data.levelsComplete[param1] / param1 == int(RandomNumber.random() * 1111) % 13 + 3;
- }
-
- public static function submitLevelsCompleted() : void
- {
- var _loc1_:int = 0;
- var _loc2_:int = 0;
- if(kongregate)
- {
- _loc1_ = 0;
- _loc2_ = 1;
- while(_loc2_ <= 40)
- {
- if(getLevelComplete(_loc2_))
- {
- _loc1_++;
- }
- _loc2_++;
- }
- trace("Completed:",_loc1_);
- kongregate.stats.submit("Levels Completed",_loc1_);
- }
- }
-
- public static function cheatFound() : void
- {
- if(cheatHasBeenFound)
- {
- return;
- }
- trace("Cheat Found");
- cheatHasBeenFound = true;
- }
-
- public static function setColorBlind(param1:Boolean) : void
- {
- colorBlind = param1;
- cookie.data.colorBlind = param1;
- }
-
- public static function checkClocking() : Boolean
- {
- if(cookie.data.clocked)
- {
- return false;
- }
- var _loc1_:int = 1;
- while(_loc1_ <= 40)
- {
- if(!getLevelComplete(_loc1_))
- {
- return false;
- }
- _loc1_++;
- }
- cookie.data.clocked = true;
- return true;
- }
-
- private static function setQuality(param1:int) : void
- {
- quality = param1;
- background.playing = param1 >= 3;
- if(param1 % 3 == 0)
- {
- background.stage.quality = StageQuality.LOW;
- }
- if(param1 % 3 == 1)
- {
- background.stage.quality = StageQuality.MEDIUM;
- }
- if(param1 % 3 == 2)
- {
- background.stage.quality = StageQuality.HIGH;
- }
- cookie.data.quality = param1;
- }
-
- private function removeLevel() : void
- {
- if(!level)
- {
- return;
- }
- if(level.parent == this)
- {
- removeChild(level);
- }
- level.removeEventListener(HexEvent.MENU,showMenu);
- level.removeEventListener(HexEvent.NEXT_LEVEL,showMenu);
- level.removeEventListener(HexEvent.NEXT_LEVEL,nextRandom);
- level.removeEventListener(HexEvent.NEXT_LEVEL,play);
- level = null;
- }
-
- private function keyUp(param1:KeyboardEvent) : void
- {
- if(param1.keyCode == 81)
- {
- nextQuality();
- }
- }
-
- public function addedToStage(param1:Event) : void
- {
- var _loc2_:Object = null;
- var _loc3_:String = null;
- var _loc4_:URLRequest = null;
- var _loc5_:Loader = null;
- removeEventListener(Event.ADDED_TO_STAGE,addedToStage);
- if(Factory.ON_KONG)
- {
- _loc2_ = LoaderInfo(root.loaderInfo).parameters;
- _loc3_ = String(String(_loc2_.api_path) || "http://www.kongregate.com/flash/API_AS3_Local.swf");
- _loc4_ = new URLRequest(_loc3_);
- (_loc5_ = new Loader()).contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
- _loc5_.load(_loc4_);
- this.addChild(_loc5_);
- }
- stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
- Input.init(stage);
- if(!background)
- {
- background = new Background();
- }
- addChild(background);
- cookie = SharedObject.getLocal("Hexiom");
- if(!cookie.data.levelsComplete)
- {
- cookie.data.levelsComplete = new Array(41);
- cookie.data.levelsComplete[0] = int(Math.random() * 900) + 3;
- }
- if(cookie.data.quality == undefined)
- {
- setQuality(5);
- }
- else
- {
- setQuality(cookie.data.quality);
- }
- colorBlind = cookie.data.colorBlind;
- titleScreen = new TitleScreen();
- titleScreen.addEventListener(HexEvent.EDIT,edit,false,0,true);
- titleScreen.addEventListener(HexEvent.PLAY,play,false,0,true);
- titleScreen.addEventListener(HexEvent.LOAD,load,false,0,true);
- titleScreen.addEventListener(HexEvent.RANDOM,random,false,0,true);
- if(!soundBar)
- {
- soundBar = new SoundBar();
- }
- addChild(soundBar);
- showMenu();
- titleScreen.stopTitle();
- black = new Sprite();
- black.graphics.beginFill(0);
- black.graphics.drawRect(0,0,400,400);
- black.graphics.endFill();
- addChild(black);
- addEventListener(Event.ENTER_FRAME,fadeBlack,false,0,true);
- MochiBot.track(this,"2db7052f");
- }
-
- private function fadeBlack(param1:Event) : void
- {
- var _loc2_:Number = 1 / 30;
- black.alpha -= _loc2_;
- if(black.alpha < _loc2_)
- {
- removeEventListener(Event.ENTER_FRAME,fadeBlack);
- removeChild(black);
- black = null;
- titleScreen.flashTitle();
- SoundBar.playMusic();
- }
- }
-
- private function load(param1:HexEvent) : void
- {
- if(!param1.board)
- {
- return;
- }
- if(titleScreen.parent == this)
- {
- removeChild(titleScreen);
- }
- level = new Level(param1.board,Level.CUSTOM);
- level.addEventListener(HexEvent.MENU,showMenu,false,0,true);
- level.addEventListener(HexEvent.NEXT_LEVEL,showMenu,false,0,true);
- addChild(level);
- Game.background.setColor(Background.ORANGE);
- }
-
- private function playLevel(param1:int) : void
- {
- level = new Level(Board.loadFromText(Levels.getBoardString(param1)),param1);
- level.addEventListener(HexEvent.MENU,showMenu,false,0,true);
- level.addEventListener(HexEvent.NEXT_LEVEL,play,false,0,true);
- addChild(level);
- Game.background.setDifficulty(param1 / 40);
- }
-
- private function edit(param1:HexEvent = null) : void
- {
- if(titleScreen.parent == this)
- {
- removeChild(titleScreen);
- }
- level = new Editor();
- level.addEventListener(HexEvent.MENU,showMenu,false,0,true);
- addChild(level);
- }
-
- private function random(param1:HexEvent) : void
- {
- if(!param1.board)
- {
- return;
- }
- if(titleScreen.parent == this)
- {
- removeChild(titleScreen);
- }
- level = new Level(param1.board,param1.level,true);
- level.addEventListener(HexEvent.MENU,showMenu,false,0,true);
- level.addEventListener(HexEvent.NEXT_LEVEL,nextRandom,false,0,true);
- addChild(level);
- Game.background.setDifficulty((param1.board.size - 3) / 3);
- }
-
- private function play(param1:HexEvent) : void
- {
- removeLevel();
- if(titleScreen.parent == this)
- {
- removeChild(titleScreen);
- }
- var _loc2_:int = param1.level;
- if(_loc2_ == 0)
- {
- _loc2_ = 1;
- }
- if(_loc2_ > 40)
- {
- showMenu();
- }
- else
- {
- playLevel(_loc2_);
- }
- }
-
- private function nextRandom(param1:HexEvent) : void
- {
- if(!param1.board)
- {
- return;
- }
- removeLevel();
- param1.board.redoRandomFill();
- level = new Level(param1.board,param1.level,true);
- level.addEventListener(HexEvent.MENU,showMenu,false,0,true);
- level.addEventListener(HexEvent.NEXT_LEVEL,nextRandom,false,0,true);
- addChild(level);
- }
-
- private function showMenu(param1:HexEvent = null) : void
- {
- removeLevel();
- titleScreen.update();
- addChild(titleScreen);
- titleScreen.flashTitle();
- }
-
- private function loadComplete(param1:Event) : void
- {
- kongregate = param1.target.content;
- kongregate.services.connect();
- trace("Connected - Submitting levels completed");
- submitLevelsCompleted();
- }
- }
- }
-