home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2001 #7 / K-CD_2001-07.iso / MasterMind / Mastermind.exe / scripts / frame_1 / DoAction.as
Text File  |  2001-01-27  |  5KB  |  202 lines

  1. function reset()
  2. {
  3.    var colloop = 1;
  4.    var rowloop = 1;
  5.    var count = 0;
  6.    rowloop = 1;
  7.    while(highestturn + 1 >= rowloop)
  8.    {
  9.       colloop = 1;
  10.       while(highestlevel + 2 >= colloop)
  11.       {
  12.          with(eval("_root.peg" + rowloop + colloop))
  13.          {
  14.             if(currentlevel + 2 >= colloop)
  15.             {
  16.                gotoAndStop("lblColour0");
  17.             }
  18.             else
  19.             {
  20.                gotoAndStop("lblColour255");
  21.             }
  22.          }
  23.          colloop++;
  24.       }
  25.       rowloop++;
  26.    }
  27.    count = 1;
  28.    while(highestturn >= count)
  29.    {
  30.       eval("_root.colorclue" + count).gotoAndStop("lbl255");
  31.       eval("_root.placeclue" + count).gotoAndStop("lbl255");
  32.       count++;
  33.    }
  34.    _root.level.gotoAndStop("lbl" + currentlevel);
  35.    _root.action.gotoAndStop("lblGo");
  36.    currentturn = 1;
  37.    currentpeg = 1;
  38.    count = 0;
  39.    while(highestlevel + 2 - 1 >= count)
  40.    {
  41.       userarray[count] = 0;
  42.       answerarray[count] = 0;
  43.       count++;
  44.    }
  45.    initialiseanswerarray();
  46.    gameover = false;
  47. }
  48. function initialiseanswerarray()
  49. {
  50.    var count = 0;
  51.    count = 0;
  52.    while(currentlevel + 2 - 1 >= count)
  53.    {
  54.       answerarray[count] = Math.round(Math.random() * 6) + 1;
  55.       count++;
  56.    }
  57. }
  58. function setpeg(PegNumber)
  59. {
  60.    if(gameover == false && currentlevel + 2 >= currentpeg)
  61.    {
  62.       eval("_root.peg" + currentturn + currentpeg).gotoAndStop("lblColour" + PegNumber);
  63.       userarray[currentpeg - 1] = PegNumber;
  64.       currentpeg++;
  65.    }
  66. }
  67. function back()
  68. {
  69.    if(gameover == false && 1 < currentpeg)
  70.    {
  71.       currentpeg--;
  72.       eval("_root.peg" + currentturn + currentpeg).gotoAndStop("lblColour0");
  73.    }
  74. }
  75. function levelup()
  76. {
  77.    if(currentlevel < highestlevel)
  78.    {
  79.       currentlevel++;
  80.       reset();
  81.    }
  82. }
  83. function leveldn()
  84. {
  85.    if(lowestlevel < currentlevel)
  86.    {
  87.       currentlevel--;
  88.       reset();
  89.    }
  90. }
  91. function actionhandler()
  92. {
  93.    var count = 0;
  94.    var winflag = false;
  95.    if(gameover == false)
  96.    {
  97.       if(currentlevel + 2 < currentpeg)
  98.       {
  99.          showclues();
  100.          winflag = true;
  101.          count = 0;
  102.          while(currentlevel + 2 - 1 >= count)
  103.          {
  104.             if(answerarray[count] != userarray[count])
  105.             {
  106.                winflag = false;
  107.             }
  108.             count++;
  109.          }
  110.          if(currentturn >= highestturn || winflag == true)
  111.          {
  112.             count = 0;
  113.             while(currentlevel + 2 - 1 >= count)
  114.             {
  115.                eval("_root.peg" + (highestturn + 1) + (count + 1)).gotoAndStop("lblColour" + answerarray[count]);
  116.                count++;
  117.             }
  118.             _root.action.gotoAndStop("lblNew");
  119.             gameover = true;
  120.             if(winflag == true)
  121.             {
  122.                _root.sounds.gotoAndPlay("lblWinner");
  123.             }
  124.             else
  125.             {
  126.                _root.sounds.gotoAndPlay("lblLoser");
  127.             }
  128.          }
  129.          currentpeg = 1;
  130.          currentturn++;
  131.       }
  132.    }
  133.    else
  134.    {
  135.       reset();
  136.    }
  137. }
  138. function showclues()
  139. {
  140.    var count = 0;
  141.    var count2 = 0;
  142.    var colorclue = 0;
  143.    var placeclue = 0;
  144.    var tempuserarray = new Array(highestlevel + 2);
  145.    var tempanswerarray = new Array(highestlevel + 2);
  146.    count = 0;
  147.    while(currentlevel + 2 - 1 >= count)
  148.    {
  149.       tempuserarray[count] = userarray[count];
  150.       tempanswerarray[count] = answerarray[count];
  151.       count++;
  152.    }
  153.    count = 0;
  154.    while(currentlevel + 2 - 1 >= count)
  155.    {
  156.       count2 = 0;
  157.       while(currentlevel + 2 - 1 >= count2)
  158.       {
  159.          if(tempuserarray[count] == tempanswerarray[count2] && count == count2 && tempuserarray[count] != 0 && tempanswerarray[count2] != 0)
  160.          {
  161.             colorclue++;
  162.             placeclue++;
  163.             tempuserarray[count] = 0;
  164.             tempanswerarray[count2] = 0;
  165.          }
  166.          count2++;
  167.       }
  168.       count++;
  169.    }
  170.    count = 0;
  171.    while(currentlevel + 2 - 1 >= count)
  172.    {
  173.       count2 = 0;
  174.       while(currentlevel + 2 - 1 >= count2)
  175.       {
  176.          if(tempuserarray[count] == tempanswerarray[count2] && count != count2 && tempuserarray[count] != 0 && tempanswerarray[count2] != 0)
  177.          {
  178.             colorclue++;
  179.             tempuserarray[count] = 0;
  180.             tempanswerarray[count2] = 0;
  181.          }
  182.          count2++;
  183.       }
  184.       count++;
  185.    }
  186.    eval("_root.colorclue" + currentturn).gotoAndStop("lbl" + colorclue);
  187.    eval("_root.placeclue" + currentturn).gotoAndStop("lbl" + placeclue);
  188. }
  189. var lowestlevel = 1;
  190. var highestlevel = 7;
  191. var currentlevel = lowestlevel + 1;
  192. var highestturn = 10;
  193. var currentturn = 1;
  194. var currentpeg = 1;
  195. var userarray = new Array(highestlevel + 2);
  196. var answerarray = new Array(highestlevel + 2);
  197. var gameover = false;
  198. var fullscreengame = false;
  199. getUrl("FSCommand:fullscreen", "true");
  200. fullscreengame = true;
  201. reset();
  202.