home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / MahJongSolitaire.swf / scripts / frame_4 / DoAction.as
Encoding:
Text File  |  2005-08-04  |  9.5 KB  |  431 lines

  1. function BuildMattrix()
  2. {
  3.    arrMatrix = new Array();
  4.    arrMatrix.push(new Array(0,1,1,1,1,1,1,1,1,1,1,0));
  5.    arrMatrix.push(new Array(1,1,1,1,1,1,1,1,1,1,1,1));
  6.    arrMatrix.push(new Array(1,1,1,1,1,1,1,1,1,1,1,1));
  7.    arrMatrix.push(new Array(1,1,1,1,1,1,1,1,1,1,1,1));
  8.    arrMatrix.push(new Array(1,1,1,1,1,1,1,1,1,1,1,1));
  9.    arrMatrix.push(new Array(0,1,1,1,1,1,1,1,1,1,1,0));
  10.    arrMatrix1 = new Array();
  11.    arrMatrix1.push(new Array(0,0,0,1,1,1,1,1,1,0,0,0));
  12.    arrMatrix1.push(new Array(0,0,1,1,1,1,1,1,1,1,0,0));
  13.    arrMatrix1.push(new Array(0,1,1,1,1,1,1,1,1,1,1,0));
  14.    arrMatrix1.push(new Array(0,1,1,1,1,1,1,1,1,1,1,0));
  15.    arrMatrix1.push(new Array(0,0,1,1,1,1,1,1,1,1,0,0));
  16.    arrMatrix1.push(new Array(0,0,0,1,1,1,1,1,1,0,0,0));
  17.    arrMatrix11 = new Array();
  18.    arrMatrix11.push(new Array(0,0,0,0,0,0,0,0,0,0,0,0));
  19.    arrMatrix11.push(new Array(0,0,0,1,1,1,1,1,1,0,0,0));
  20.    arrMatrix11.push(new Array(0,0,1,1,1,1,1,1,1,1,0,0));
  21.    arrMatrix11.push(new Array(0,0,1,1,1,1,1,1,1,1,0,0));
  22.    arrMatrix11.push(new Array(0,0,0,1,1,1,1,1,1,0,0,0));
  23.    arrMatrix11.push(new Array(0,0,0,0,0,0,0,0,0,0,0,0));
  24. }
  25. function loadEnd()
  26. {
  27.    loadMovie(endURL,endFeature);
  28.    blnLoad = true;
  29. }
  30. function Initialize()
  31. {
  32.    mcDialog._visible = false;
  33.    removeAll();
  34.    BuildMattrix();
  35.    firstTile = "empty";
  36.    arrTilesOnTeScreen = new Array();
  37.    arrTiles = new Array();
  38.    i = 1;
  39.    while(34 >= i)
  40.    {
  41.       n = 0;
  42.       while(n < 4)
  43.       {
  44.          arrTiles.push(String(i));
  45.          n++;
  46.       }
  47.       i++;
  48.    }
  49.    i = 35;
  50.    while(42 >= i)
  51.    {
  52.       arrTiles.push(String(i));
  53.       i++;
  54.    }
  55.    i = 0;
  56.    while(i < arrTiles.length)
  57.    {
  58.       saveTile = arrTiles[i];
  59.       numRandom = getRandomValue(arrTiles.length);
  60.       arrTiles[i] = arrTiles[numRandom];
  61.       arrTiles[numRandom] = saveTile;
  62.       i++;
  63.    }
  64.    x = 470;
  65.    y = 60;
  66.    count = 10;
  67.    f = 0;
  68.    PlaceTiles();
  69.    UpdateCount();
  70. }
  71. function PlaceTiles()
  72. {
  73.    i = 0;
  74.    while(i < 6)
  75.    {
  76.       n = 12;
  77.       while(n >= 0)
  78.       {
  79.          if(arrMatrix[i][n] == 1)
  80.          {
  81.             arrTilesOnTeScreen.push(String(f));
  82.             _root.attachMovie(arrTiles[f],String(f),count);
  83.             _root[String(f)]._x = x;
  84.             _root[String(f)]._y = y;
  85.             _root[String(f)].arr = "arrMatrix";
  86.             _root[String(f)].x = i;
  87.             _root[String(f)].y = n;
  88.             getValues(arrTiles[f],String(f));
  89.             var arrToDelete = new Array();
  90.             arrToDelete.push(new Array(i,n));
  91.             _root[String(f)].arrToDelete = arrToDelete;
  92.             count++;
  93.             f++;
  94.          }
  95.          x -= 37;
  96.          y += 12;
  97.          n--;
  98.       }
  99.       x = 470 + 22 * (i + 1);
  100.       y = 60 + 40 * (i + 1);
  101.       i++;
  102.    }
  103.    x = 473;
  104.    y = 48;
  105.    i = 0;
  106.    while(i < 6)
  107.    {
  108.       n = 12;
  109.       while(n >= 0)
  110.       {
  111.          if(arrMatrix1[i][n] == 1)
  112.          {
  113.             arrTilesOnTeScreen.push(String(f));
  114.             _root.attachMovie(arrTiles[f],String(f),count);
  115.             _root[String(f)]._x = x;
  116.             _root[String(f)]._y = y;
  117.             _root[String(f)].arr = "arrMatrix1";
  118.             _root[String(f)].x = i;
  119.             _root[String(f)].y = n;
  120.             getValues(arrTiles[f],String(f));
  121.             var arrToDelete = new Array();
  122.             arrToDelete.push(new Array(i,n));
  123.             _root[String(f)].arrToDelete = arrToDelete;
  124.             count++;
  125.             f++;
  126.          }
  127.          x -= 37;
  128.          y += 12;
  129.          n--;
  130.       }
  131.       x = 473 + 22 * (i + 1);
  132.       y = 48 + 40 * (i + 1);
  133.       i++;
  134.    }
  135.    x = 476;
  136.    y = 36;
  137.    i = 0;
  138.    while(i < 6)
  139.    {
  140.       n = 12;
  141.       while(n >= 0)
  142.       {
  143.          if(arrMatrix11[i][n] == 1)
  144.          {
  145.             arrTilesOnTeScreen.push(String(f));
  146.             _root.attachMovie(arrTiles[f],String(f),count);
  147.             _root[String(f)]._x = x;
  148.             _root[String(f)]._y = y;
  149.             _root[String(f)].arr = "arrMatrix11";
  150.             _root[String(f)].x = i;
  151.             _root[String(f)].y = n;
  152.             getValues(arrTiles[f],String(f));
  153.             var arrToDelete = new Array();
  154.             arrToDelete.push(new Array(i,n));
  155.             _root[String(f)].arrToDelete = arrToDelete;
  156.             count++;
  157.             f++;
  158.          }
  159.          x -= 37;
  160.          y += 12;
  161.          n--;
  162.       }
  163.       x = 476 + 22 * (i + 1);
  164.       y = 36 + 40 * (i + 1);
  165.       i++;
  166.    }
  167. }
  168. function getValues(tile, movie)
  169. {
  170.    var num = parseInt(tile);
  171.    if(num >= 35 && 38 >= num)
  172.    {
  173.       _root[movie].value = "flower";
  174.       _root[movie].score = 6;
  175.    }
  176.    else if(num >= 39 && 42 >= num)
  177.    {
  178.       _root[movie].value = "season";
  179.       _root[movie].score = 6;
  180.    }
  181.    else
  182.    {
  183.       _root[movie].value = tile;
  184.       if(num >= 1 && 9 >= num)
  185.       {
  186.          _root[movie].score = 3;
  187.       }
  188.       else if(num >= 10 && 18 >= num)
  189.       {
  190.          _root[movie].score = 1;
  191.       }
  192.       else if(num >= 19 && 27 >= num)
  193.       {
  194.          _root[movie].score = 2;
  195.       }
  196.       else if(num >= 28 && 30 >= num)
  197.       {
  198.          _root[movie].score = 5;
  199.       }
  200.       else if(num >= 31 && 34 >= num)
  201.       {
  202.          _root[movie].score = 4;
  203.       }
  204.    }
  205. }
  206. function RollOverTile(name)
  207. {
  208.    if(endGame == true)
  209.    {
  210.       return undefined;
  211.    }
  212.    if(_root[name]._currentframe < 3)
  213.    {
  214.       _root[name].gotoAndStop(2);
  215.    }
  216. }
  217. function RollOutTile(name)
  218. {
  219.    if(endGame == true)
  220.    {
  221.       return undefined;
  222.    }
  223.    if(_root[name]._currentframe < 3)
  224.    {
  225.       _root[name].gotoAndStop(1);
  226.    }
  227. }
  228. function PressTile(tile)
  229. {
  230.    if(endGame == true)
  231.    {
  232.       return undefined;
  233.    }
  234.    soundPress.start();
  235.    if(firstTile == tile)
  236.    {
  237.       firstTile = "empty";
  238.       _root[tile].gotoAndStop(1);
  239.    }
  240.    else if(firstTile == "empty")
  241.    {
  242.       if(CheckTile(tile) == 1)
  243.       {
  244.          _root[tile].gotoAndStop(3);
  245.          firstTile = tile;
  246.       }
  247.       else
  248.       {
  249.          soundWrong.start();
  250.       }
  251.    }
  252.    else if(CheckTile(tile) == 1)
  253.    {
  254.       if(_root[firstTile].value == _root[tile].value)
  255.       {
  256.          _root[tile].gotoAndStop(3);
  257.          mcRemover.tile1 = firstTile;
  258.          mcRemover.tile2 = tile;
  259.          soundCorrect.start();
  260.          AddScore();
  261.       }
  262.       else
  263.       {
  264.          _root[firstTile].gotoAndStop(1);
  265.          _root[tile].gotoAndStop(1);
  266.          firstTile = "empty";
  267.          soundWrong.start();
  268.       }
  269.    }
  270.    else
  271.    {
  272.       _root[firstTile].gotoAndStop(1);
  273.       _root[tile].gotoAndStop(1);
  274.       firstTile = "empty";
  275.       soundWrong.start();
  276.    }
  277. }
  278. function CheckTile(tile)
  279. {
  280.    if(CheckTop(tile) == 0)
  281.    {
  282.       if(CheckRight(tile) == 0)
  283.       {
  284.          _root[tile].course = "right";
  285.          return 1;
  286.       }
  287.       if(CheckLeft(tile) == 0)
  288.       {
  289.          _root[tile].course = "left";
  290.          return 1;
  291.       }
  292.       return 0;
  293.    }
  294. }
  295. function CheckTop(tile)
  296. {
  297.    var arr = _root[tile].arr;
  298.    var x = _root[tile].x;
  299.    var y = _root[tile].y;
  300.    if(_root[arr + "1"][x][y] == 0 || _root[arr + "1"][x][y] == undefined)
  301.    {
  302.       return 0;
  303.    }
  304.    return 1;
  305. }
  306. function CheckRight(tile)
  307. {
  308.    var arr = _root[tile].arr;
  309.    var x = _root[tile].x;
  310.    var y = _root[tile].y;
  311.    if(_root[arr][x][y + 1] == 0 || _root[arr][x][y + 1] == undefined)
  312.    {
  313.       return 0;
  314.    }
  315.    return 1;
  316. }
  317. function CheckLeft(tile)
  318. {
  319.    var arr = _root[tile].arr;
  320.    var x = _root[tile].x;
  321.    var y = _root[tile].y;
  322.    if(_root[arr][x][y - 1] == 0 || _root[arr][x][y - 1] == undefined)
  323.    {
  324.       return 0;
  325.    }
  326.    return 1;
  327. }
  328. function RemoveTile(tile)
  329. {
  330.    var arr = _root[tile].arr;
  331.    var arrToDelete = _root[tile].arrToDelete;
  332.    i = 0;
  333.    while(i < arrToDelete.length)
  334.    {
  335.       _root[arr][arrToDelete[i][0]][arrToDelete[i][1]] = 0;
  336.       i++;
  337.    }
  338.    removeMovieClip(_root[tile]);
  339.    RemoveFromArray(tile);
  340.    firstTile = "empty";
  341. }
  342. function RemoveFromArray(tile)
  343. {
  344.    i = 0;
  345.    while(i < arrTilesOnTeScreen.length)
  346.    {
  347.       if(arrTilesOnTeScreen[i] == tile)
  348.       {
  349.          arrTilesOnTeScreen.splice(i,1);
  350.          break;
  351.       }
  352.       i++;
  353.    }
  354.    mcChecker.gotoAndPlay(2);
  355.    UpdateCount();
  356. }
  357. function UpdateCount()
  358. {
  359.    tilesLeft = arrTilesOnTeScreen.length;
  360. }
  361. function AddScore()
  362. {
  363.    var m = tilesLeft / 2;
  364.    var score = eval(firstTile).score;
  365.    totalPoints += m * score;
  366.    if(m == 1)
  367.    {
  368.       endGame = true;
  369.       mcNewShuffle.gotoAndStop(2);
  370.       mcTimer.gotoAndPlay(5);
  371.    }
  372. }
  373. function RemoveAll()
  374. {
  375.    i = 0;
  376.    while(i < arrTilesOnTeScreen.length)
  377.    {
  378.       removeMovieClip(eval(arrTilesOnTeScreen[i]));
  379.       i++;
  380.    }
  381. }
  382. function SoundOn()
  383. {
  384.    soundPress.setVolume(100);
  385.    soundCorrect.setVolume(100);
  386.    soundStart.setVolume(100);
  387.    soundTomer.setVolume(100);
  388.    soundWrong.setVolume(100);
  389. }
  390. function SoundOff()
  391. {
  392.    soundPress.setVolume(0);
  393.    soundCorrect.setVolume(0);
  394.    soundStart.setVolume(0);
  395.    soundTomer.setVolume(0);
  396.    soundWrong.setVolume(0);
  397. }
  398. function TimeBonus()
  399. {
  400.    totalPoints += 10;
  401. }
  402. function GameOver()
  403. {
  404.    endGame = true;
  405.    gameOver = true;
  406.    mcNewShuffle.gotoAndStop(2);
  407.    mcDialog._visible = false;
  408.    mcTimer.gotoAndStop(2);
  409.    mcStart.swapDepths(1000);
  410.    mcStart._y = 212;
  411.    mcStart.gotoAndPlay("gameover");
  412.    trace("");
  413.    play();
  414. }
  415. function ShowDialog()
  416. {
  417.    endGame = true;
  418.    mcDialog.swapDepths(1010);
  419.    mcDialog._visible = true;
  420. }
  421. function Continue()
  422. {
  423.    endGame = false;
  424.    mcDialog._visible = false;
  425. }
  426. stop();
  427. Initialize();
  428. soundStart.start();
  429. mcTimer.play();
  430. endGame = false;
  431.