home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / devglry / studiosw / origgame / catscon.dxr / 00002_aGameBrd.ls < prev    next >
Encoding:
Text File  |  1996-04-17  |  6.0 KB  |  234 lines

  1. property pCast, pSprite, pGameTiles, pfloatingTile, pGrid, pInitTileSprite, pTilesPerSide, gBaseScore, pOpenSet, pOpenTile, gRevealed
  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) + 43
  51. end
  52.  
  53. on findTopEdge me, baseSize, numOfTiles
  54.   return (baseSize / 2) + 60
  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.   set w to getAt(the windowList, 1)
  171.   tell w
  172.     SETDisplay(0)
  173.     onINCDispay(gBaseScore * 10)
  174.   end tell
  175. end
  176.  
  177. on killGame me
  178.   deactivateMIW(me)
  179. end
  180.  
  181. on makeScoreBoard me
  182.   cursor(4)
  183.   if not (the windowList = []) then
  184.     deactivateMIW(me)
  185.   end if
  186.   set pWindow to the pathName & "CATSCORE"
  187.   set the windowType of window pWindow to 2
  188.   set offSetL to the stageLeft
  189.   set offSetT to the stageTop
  190.   set myTop to the top of sprite pSprite + 34
  191.   set theRect to rect(offSetL + 528, offSetT + myTop, offSetL + 528 + 94, offSetT + myTop + 40)
  192.   set the rect of window pWindow to theRect
  193.   set w to getAt(the windowList, 1)
  194.   set the visible of w to 1
  195.   cursor(-1)
  196. end
  197.  
  198. on deactivateMIW me
  199.   set w to getAt(the windowList, 1)
  200.   set the visible of w to 0
  201.   forget(w)
  202. end
  203.  
  204. on doTick me
  205.   addScore(me, -gBaseScore)
  206. end
  207.  
  208. on addScore me, sValue
  209.   set w to getAt(the windowList, 1)
  210.   tell w
  211.     onINCDispay(sValue)
  212.   end tell
  213. end
  214.  
  215. on showAll me
  216.   set count to 1
  217.   set maxTile to 20
  218.   repeat while maxTile >= count
  219.     set theTile to getAt(pGameTiles, count)
  220.     show(theTile)
  221.     set count to count + 1
  222.   end repeat
  223. end
  224.  
  225. on hideAll me
  226.   set count to 1
  227.   set maxTile to 20
  228.   repeat while maxTile >= count
  229.     set theTile to getAt(pGameTiles, count)
  230.     hide(theTile)
  231.     set count to count + 1
  232.   end repeat
  233. end
  234.