home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / DSS150 / DSS150_02 / DSS150_02.swf / scripts / dss150 / Memo.as
Text File  |  2012-12-19  |  4KB  |  163 lines

  1. package dss150
  2. {
  3.    import com.milanpresse.engineaddons.facades.GameEngine;
  4.    import flash.net.SharedObject;
  5.    
  6.    public class Memo
  7.    {
  8.       
  9.       public static var NEW_GAME:String = "NEW_GAME";
  10.       
  11.       public static var SAVED_GAME:String = "SAVED_GAME";
  12.       
  13.       public static var ATTENTE:String = "ATTENTE";
  14.        
  15.       
  16.       private var _so:SharedObject;
  17.       
  18.       private var _name:String;
  19.       
  20.       private var game:GameEngine;
  21.       
  22.       private var _savePoint:Object;
  23.       
  24.       public var modules:Array;
  25.       
  26.       public function Memo(game:GameEngine)
  27.       {
  28.          this.modules = [{
  29.             "no":0,
  30.             "succes":false,
  31.             "vu":true
  32.          },{
  33.             "no":1,
  34.             "succes":false,
  35.             "vu":false
  36.          },{
  37.             "no":2,
  38.             "succes":false,
  39.             "vu":false
  40.          },{
  41.             "no":3,
  42.             "succes":false,
  43.             "vu":false
  44.          },{
  45.             "no":4,
  46.             "succes":false,
  47.             "vu":false
  48.          }];
  49.          super();
  50.          this.game = game;
  51.          this._name = game.config.rubriqueName;
  52.          this._so = SharedObject.getLocal(this._name,"/");
  53.          if(this._so.data._savePoint == undefined)
  54.          {
  55.             this._savePoint = {
  56.                "moduleNum":this.module.no,
  57.                "status":NEW_GAME
  58.             };
  59.             this.save();
  60.          }
  61.          else
  62.          {
  63.             this.load();
  64.          }
  65.       }
  66.       
  67.       public function clear() : void
  68.       {
  69.          this._so.clear();
  70.          this.modules = [{
  71.             "no":0,
  72.             "succes":false,
  73.             "vu":true
  74.          },{
  75.             "no":1,
  76.             "succes":false,
  77.             "vu":false
  78.          },{
  79.             "no":2,
  80.             "succes":false,
  81.             "vu":false
  82.          },{
  83.             "no":3,
  84.             "succes":false,
  85.             "vu":false
  86.          },{
  87.             "no":4,
  88.             "succes":false,
  89.             "vu":false
  90.          }];
  91.          this._savePoint = {
  92.             "moduleNum":this.module.no,
  93.             "status":NEW_GAME
  94.          };
  95.          this.save();
  96.       }
  97.       
  98.       public function save() : void
  99.       {
  100.          this._so.data._savePoint = this._savePoint;
  101.          this._so.data.modules = this.modules;
  102.          this._so.flush();
  103.       }
  104.       
  105.       public function load() : void
  106.       {
  107.          this._savePoint = this._so.data._savePoint;
  108.          this.modules = this._so.data.modules;
  109.       }
  110.       
  111.       public function get allModulesFinished() : Boolean
  112.       {
  113.          for(var i:int = 0; i < this.modules.length; i++)
  114.          {
  115.             if(this.modules[i].vu == false)
  116.             {
  117.                return false;
  118.             }
  119.          }
  120.          return true;
  121.       }
  122.       
  123.       public function get nbModulesFinished() : int
  124.       {
  125.          var nb:int = 0;
  126.          for(var i:int = 0; i < this.modules.length; i++)
  127.          {
  128.             if(this.modules[i].vu == true)
  129.             {
  130.                nb++;
  131.             }
  132.          }
  133.          return nb;
  134.       }
  135.       
  136.       public function get module() : Object
  137.       {
  138.          return this.modules[this.game.config.moduleNum];
  139.       }
  140.       
  141.       public function set savePoint(value:Object) : void
  142.       {
  143.          value.moduleNum = value.moduleNum == undefined ? this.module.no : value.moduleNum;
  144.          this._savePoint = value;
  145.       }
  146.       
  147.       public function get savePoint() : Object
  148.       {
  149.          return this._savePoint;
  150.       }
  151.       
  152.       public function toString() : String
  153.       {
  154.          var str:String = "";
  155.          for(var i:int = 0; i < this.modules.length; i++)
  156.          {
  157.             str += "\r\n" + i + " : " + this.modules[i].vu;
  158.          }
  159.          return str;
  160.       }
  161.    }
  162. }
  163.