home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / devglry / studiosw / source / shokcats.dir / 00069_aGameBrd.ls < prev    next >
Encoding:
Text File  |  1996-05-10  |  5.4 KB  |  212 lines

  1. property pCast, pSprite, pGameTiles, pfloatingTile, pGrid, pInitTileSprite, pTilesPerSide, gBaseScore, pOpenSet, pOpenTile, gRevealed, gTheScore
  2. global gGameInPlay, gTimeOut
  3.  
  4. on birth me, theCast, theSprite, theFloatTile
  5.   set pGrid to []
  6.   set pfloatingTile to theFloatTile
  7.   set pCast to theCast
  8.   set pSprite to theSprite
  9.   set pGameTiles to []
  10.   set gBaseScore to 150
  11.   set pOpenSet to 0
  12.   makeScoreBoard(me)
  13.   return me
  14. end
  15.  
  16. on createNewGame me, firstTile, firstTileSprite, numSqTiles, hideTile, firstRevTile
  17.   set pInitTileSprite to firstTileSprite - 1
  18.   set pTilesPerSide to numSqTiles
  19.   set TileBaseSize to the width of cast firstTile
  20.   set gRevealed to 0
  21.   set count to 1
  22.   set TCount to 1
  23.   set HBase to findLeftEdge(me, TileBaseSize, pTilesPerSide)
  24.   set VBase to findTopEdge(me, TileBaseSize, pTilesPerSide)
  25.   set maxTiles to 20
  26.   set lhideState to 0
  27.   repeat while count <= maxTiles
  28.     set Tile to birth(script "aPICTtile", pInitTileSprite + count, firstTile - 1 + TCount, hideTile, firstRevTile - 1 + count)
  29.     setAt(pGameTiles, count, Tile)
  30.     setHomePos(Tile, HBase, VBase)
  31.     set count to count + 1
  32.     if count = 11 then
  33.       set TCount to 1
  34.     else
  35.       set TCount to TCount + 1
  36.     end if
  37.     if (count = (pTilesPerSide + 1)) or (count = ((pTilesPerSide * 2) + 1)) or (count = ((pTilesPerSide * 3) + 1)) then
  38.       set HBase to findLeftEdge(me, TileBaseSize, pTilesPerSide)
  39.       set VBase to VBase + TileBaseSize
  40.     else
  41.       set HBase to HBase + TileBaseSize
  42.     end if
  43.     hide(Tile)
  44.   end repeat
  45.   resetTiles(me)
  46.   showAll(me)
  47. end
  48.  
  49. on findLeftEdge me, baseSize, numOfTiles
  50.   return (baseSize / 2) + 19
  51. end
  52.  
  53. on findTopEdge me, baseSize, numOfTiles
  54.   return (baseSize / 2) + 32
  55. end
  56.  
  57. on doMouseDown me, theSprite
  58.   set count to theSprite - pInitTileSprite
  59.   set activeTile to getAt(pGameTiles, count)
  60.   if pOpenSet then
  61.     show(activeTile)
  62.     updateStage()
  63.     if (getTile(activeTile) = getTile(pOpenTile)) and (getSprite(activeTile) <> getSprite(pOpenTile)) then
  64.       puppetSound("meow1.aiff")
  65.       addScore(me, 2 * gBaseScore)
  66.       set gRevealed to gRevealed + 1
  67.       set deltaT to the ticks + 120
  68.       repeat while (the ticks < deltaT) and not (the mouseDown)
  69.       end repeat
  70.       reveal(activeTile)
  71.       reveal(pOpenTile)
  72.       updateStage()
  73.       set pOpenSet to 0
  74.       if isGameSolved(me) then
  75.         puppetSound("meow1.aiff")
  76.         set gGameInPlay to 0
  77.         set pOpenSet to 0
  78.         set gTimeOut to 60
  79.         addScore(me, 4 * gBaseScore)
  80.         go("WinningAnnimation")
  81.       end if
  82.     else
  83.       updateStage()
  84.       addScore(me, -1 * gBaseScore)
  85.       set deltaT to the ticks + 120
  86.       repeat while (the ticks < deltaT) and not (the mouseDown)
  87.       end repeat
  88.       hide(activeTile)
  89.       hide(pOpenTile)
  90.       updateStage()
  91.       set pOpenSet to 0
  92.     end if
  93.   else
  94.     set pOpenTile to activeTile
  95.     set pOpenSet to 1
  96.     show(pOpenTile)
  97.     updateStage()
  98.   end if
  99. end
  100.  
  101. on isGameSolved me
  102.   if gRevealed = 10 then
  103.     return 1
  104.   else
  105.     return 0
  106.   end if
  107. end
  108.  
  109. on resetTiles me
  110.   set count to 1
  111.   set maxTiles to 20
  112.   repeat while count <= maxTiles
  113.     set thisTile to getAt(pGameTiles, count)
  114.     set the locH of sprite (count + pInitTileSprite) to getHomeHPos(thisTile)
  115.     set the locV of sprite (count + pInitTileSprite) to getHomeVPos(thisTile)
  116.     set count to count + 1
  117.   end repeat
  118.   updateStage()
  119. end
  120.  
  121. on reset me
  122.   set gGameInPlay to 0
  123.   set pOpenSet to 0
  124.   set gRevealed to 0
  125.   resetTiles(me)
  126. end
  127.  
  128. on scramble me
  129.   showAll(me)
  130.   updateStage()
  131.   set count to 1
  132.   set maxTiles to 20
  133.   repeat while count < 100
  134.     set rT1 to random(maxTiles)
  135.     set rT2 to random(maxTiles)
  136.     if not (rT1 = rT2) then
  137.       set holdH to the locH of sprite (rT1 + pInitTileSprite)
  138.       set holdV to the locV of sprite (rT1 + pInitTileSprite)
  139.       set the locH of sprite (rT1 + pInitTileSprite) to the locH of sprite (rT2 + pInitTileSprite)
  140.       set the locV of sprite (rT1 + pInitTileSprite) to the locV of sprite (rT2 + pInitTileSprite)
  141.       set the locH of sprite (rT2 + pInitTileSprite) to holdH
  142.       set the locV of sprite (rT2 + pInitTileSprite) to holdV
  143.       updateStage()
  144.     else
  145.     end if
  146.     set count to count + 1
  147.   end repeat
  148.   hideAll(me)
  149.   updateStage()
  150. end
  151.  
  152. on scrambleTwoTiles me
  153.   set rT1 to random(20)
  154.   set rT2 to random(20)
  155.   if not (rT1 = rT2) then
  156.     set holdH to the locH of sprite (rT1 + pInitTileSprite)
  157.     set holdV to the locV of sprite (rT1 + pInitTileSprite)
  158.     set the locH of sprite (rT1 + pInitTileSprite) to the locH of sprite (rT2 + pInitTileSprite)
  159.     set the locV of sprite (rT1 + pInitTileSprite) to the locV of sprite (rT2 + pInitTileSprite)
  160.     set the locH of sprite (rT2 + pInitTileSprite) to holdH
  161.     set the locV of sprite (rT2 + pInitTileSprite) to holdV
  162.     updateStage()
  163.   else
  164.   end if
  165. end
  166.  
  167. on StartANewGame me
  168.   reset(me)
  169.   scramble(me)
  170.   setNumber(gTheScore, 0)
  171.   incNumber(gTheScore, gBaseScore * 10)
  172. end
  173.  
  174. on killGame me
  175. end
  176.  
  177. on makeScoreBoard me
  178.   set gTheScore to birth(script "aDDisplay", 4, 30)
  179.   setNumber(gTheScore, 0)
  180. end
  181.  
  182. on deactivateMIW me
  183. end
  184.  
  185. on doTick me
  186.   addScore(me, -gBaseScore)
  187. end
  188.  
  189. on addScore me, sValue
  190.   incNumber(gTheScore, sValue)
  191. end
  192.  
  193. on showAll me
  194.   set count to 1
  195.   set maxTile to 20
  196.   repeat while maxTile >= count
  197.     set theTile to getAt(pGameTiles, count)
  198.     show(theTile)
  199.     set count to count + 1
  200.   end repeat
  201. end
  202.  
  203. on hideAll me
  204.   set count to 1
  205.   set maxTile to 20
  206.   repeat while maxTile >= count
  207.     set theTile to getAt(pGameTiles, count)
  208.     hide(theTile)
  209.     set count to count + 1
  210.   end repeat
  211. end
  212.