home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / eolica.swf / scripts / frame_4 / DoAction.as
Encoding:
Text File  |  2005-07-26  |  3.0 KB  |  123 lines

  1. function Grid(width, height, cellWidth, cellHeight, display_mc)
  2. {
  3.    this.gridWidth = width;
  4.    this.gridHeight = height;
  5.    this.xUnitsPerCell = cellWidth;
  6.    this.yUnitsPerCell = cellHeight;
  7.    var _loc7_ = 100 / width;
  8.    var _loc8_ = 100 / height;
  9.    this.cells = new Array(width);
  10.    this.allCells = new Array();
  11.    this.allContents = new Array();
  12.    var _loc4_ = 0;
  13.    while(_loc4_ < this.cells.length)
  14.    {
  15.       this.cells[_loc4_] = new Array(height);
  16.       var _loc3_ = 0;
  17.       while(_loc3_ < this.cells[_loc4_].length)
  18.       {
  19.          var _loc5_ = new Grid.Cell(_loc4_,_loc3_);
  20.          this.cells[_loc4_][_loc3_] = _loc5_;
  21.          var _loc6_ = this.allCells.push(_loc5_);
  22.          _loc5_.id = _loc6_;
  23.          display_mc.attachMovie("grid_cell","grid_cell_" + _loc6_,_loc6_);
  24.          var _loc2_ = display_mc["grid_cell_" + _loc6_];
  25.          _loc2_._x = _loc4_ * _loc7_;
  26.          _loc2_._y = _loc3_ * _loc8_;
  27.          _loc2_._width = _loc7_;
  28.          _loc2_._height = _loc8_;
  29.          _loc2_.gridCell = _loc5_;
  30.          _loc2_.text = _loc4_ + "," + _loc3_;
  31.          _loc5_.display_mc = _loc2_;
  32.          _loc3_ = _loc3_ + 1;
  33.       }
  34.       _loc4_ = _loc4_ + 1;
  35.    }
  36. }
  37. var t = Grid.prototype;
  38. t.mc = false;
  39. t.getCell = function(x, y)
  40. {
  41.    return this.cells[x][y];
  42. };
  43. t.mapCell = function(x, y)
  44. {
  45.    var _loc3_ = Math.floor(x / this.xUnitsPerCell);
  46.    var _loc2_ = Math.floor(y / this.yUnitsPerCell);
  47.    var _loc4_ = this.cells[_loc3_][_loc2_];
  48.    return _loc4_;
  49. };
  50. t.placeInGrid = function(obj, x, y)
  51. {
  52.    var _loc2_ = this.mapCell(x,y);
  53.    if(obj.curGridCell == _loc2_)
  54.    {
  55.       return false;
  56.    }
  57.    obj.curGridCell.removeContent(obj);
  58.    _loc2_.addContent(obj);
  59.    this.allContents[obj.id] = _loc2_;
  60. };
  61. t.removeFromGrid = function(obj)
  62. {
  63.    var _loc2_ = this.allContents[obj.id];
  64.    _loc2_.removeContent(obj);
  65. };
  66. t.totalCells = 0;
  67. t.cells = false;
  68. t.allCells = false;
  69. t.allContents = false;
  70. t.xUnitsPerCell = 0;
  71. t.yUnitsPerCell = 0;
  72. t.gridWidth = 0;
  73. t.gridHeight = 0;
  74. Grid.Cell = function(x, y)
  75. {
  76.    this.x = x;
  77.    this.y = y;
  78.    this.contents = new Array();
  79. };
  80. var t = Grid.Cell.prototype;
  81. t.x = 0;
  82. t.y = 0;
  83. t.id = 0;
  84. t.addContent = function(obj)
  85. {
  86.    this.contents[obj.id] = this.contents.push(obj) - 1;
  87.    obj.curGridCell = this;
  88.    this.display_mc.nextFrame();
  89. };
  90. t.removeContent = function(obj)
  91. {
  92.    var _loc2_ = 0;
  93.    while(_loc2_ < this.contents.length)
  94.    {
  95.       if(this.contents[_loc2_] == obj)
  96.       {
  97.          this.contents.splice(_loc2_,1);
  98.          break;
  99.       }
  100.       _loc2_ = _loc2_ + 1;
  101.    }
  102.    if(this.contents.length <= 0)
  103.    {
  104.       this.display_mc.prevFrame();
  105.    }
  106. };
  107. t.contentsAsString = function()
  108. {
  109.    var _loc3_ = "";
  110.    var _loc2_ = 0;
  111.    while(_loc2_ < this.contents.length)
  112.    {
  113.       _loc3_ += this.contents[_loc2_].id + ", ";
  114.       _loc2_ = _loc2_ + 1;
  115.    }
  116.    return _loc3_;
  117. };
  118. t.contents = false;
  119. t.toString = function()
  120. {
  121.    return "[Cell " + this.x + "," + this.y + "]";
  122. };
  123.