home *** CD-ROM | disk | FTP | other *** search
- property pCast, pSprite, pGameTiles, pfloatingTile, pGrid, pInitTileSprite, pTilesPerSide, gBaseScore, pOpenSet, pOpenTile, gRevealed
- global gGameInPlay, gTimeOut
-
- on birth me, theCast, theSprite, theFloatTile
- set pGrid to []
- set pfloatingTile to theFloatTile
- set pCast to theCast
- set pSprite to theSprite
- set pGameTiles to []
- set gBaseScore to 150
- set pOpenSet to 0
- makeScoreBoard(me)
- return me
- end
-
- on createNewGame me, firstTile, firstTileSprite, numSqTiles, hideTile, firstRevTile
- set pInitTileSprite to firstTileSprite - 1
- set pTilesPerSide to numSqTiles
- set TileBaseSize to the width of cast firstTile
- set gRevealed to 0
- set count to 1
- set TCount to 1
- set HBase to findLeftEdge(me, TileBaseSize, pTilesPerSide)
- set VBase to findTopEdge(me, TileBaseSize, pTilesPerSide)
- set maxTiles to 20
- set lhideState to 0
- repeat while count <= maxTiles
- set Tile to birth(script "aPICTtile", pInitTileSprite + count, firstTile - 1 + TCount, hideTile, firstRevTile - 1 + count)
- setAt(pGameTiles, count, Tile)
- setHomePos(Tile, HBase, VBase)
- set count to count + 1
- if count = 11 then
- set TCount to 1
- else
- set TCount to TCount + 1
- end if
- if (count = (pTilesPerSide + 1)) or (count = ((pTilesPerSide * 2) + 1)) or (count = ((pTilesPerSide * 3) + 1)) then
- set HBase to findLeftEdge(me, TileBaseSize, pTilesPerSide)
- set VBase to VBase + TileBaseSize
- else
- set HBase to HBase + TileBaseSize
- end if
- hide(Tile)
- end repeat
- resetTiles(me)
- showAll(me)
- end
-
- on findLeftEdge me, baseSize, numOfTiles
- return (baseSize / 2) + 43
- end
-
- on findTopEdge me, baseSize, numOfTiles
- return (baseSize / 2) + 60
- end
-
- on doMouseDown me, theSprite
- set count to theSprite - pInitTileSprite
- set activeTile to getAt(pGameTiles, count)
- if pOpenSet then
- show(activeTile)
- updateStage()
- if (getTile(activeTile) = getTile(pOpenTile)) and (getSprite(activeTile) <> getSprite(pOpenTile)) then
- puppetSound("meow1.aiff")
- addScore(me, 2 * gBaseScore)
- set gRevealed to gRevealed + 1
- set deltaT to the ticks + 120
- repeat while (the ticks < deltaT) and not (the mouseDown)
- end repeat
- reveal(activeTile)
- reveal(pOpenTile)
- updateStage()
- set pOpenSet to 0
- if isGameSolved(me) then
- puppetSound("meow1.aiff")
- set gGameInPlay to 0
- set pOpenSet to 0
- set gTimeOut to 60
- addScore(me, 4 * gBaseScore)
- go("WinningAnnimation")
- end if
- else
- updateStage()
- addScore(me, -1 * gBaseScore)
- set deltaT to the ticks + 120
- repeat while (the ticks < deltaT) and not (the mouseDown)
- end repeat
- hide(activeTile)
- hide(pOpenTile)
- updateStage()
- set pOpenSet to 0
- end if
- else
- set pOpenTile to activeTile
- set pOpenSet to 1
- show(pOpenTile)
- updateStage()
- end if
- end
-
- on isGameSolved me
- if gRevealed = 10 then
- return 1
- else
- return 0
- end if
- end
-
- on resetTiles me
- set count to 1
- set maxTiles to 20
- repeat while count <= maxTiles
- set thisTile to getAt(pGameTiles, count)
- set the locH of sprite (count + pInitTileSprite) to getHomeHPos(thisTile)
- set the locV of sprite (count + pInitTileSprite) to getHomeVPos(thisTile)
- set count to count + 1
- end repeat
- updateStage()
- end
-
- on reset me
- set gGameInPlay to 0
- set pOpenSet to 0
- set gRevealed to 0
- resetTiles(me)
- end
-
- on scramble me
- showAll(me)
- updateStage()
- set count to 1
- set maxTiles to 20
- repeat while count < 100
- set rT1 to random(maxTiles)
- set rT2 to random(maxTiles)
- if not (rT1 = rT2) then
- set holdH to the locH of sprite (rT1 + pInitTileSprite)
- set holdV to the locV of sprite (rT1 + pInitTileSprite)
- set the locH of sprite (rT1 + pInitTileSprite) to the locH of sprite (rT2 + pInitTileSprite)
- set the locV of sprite (rT1 + pInitTileSprite) to the locV of sprite (rT2 + pInitTileSprite)
- set the locH of sprite (rT2 + pInitTileSprite) to holdH
- set the locV of sprite (rT2 + pInitTileSprite) to holdV
- updateStage()
- else
- end if
- set count to count + 1
- end repeat
- hideAll(me)
- updateStage()
- end
-
- on scrambleTwoTiles me
- set rT1 to random(20)
- set rT2 to random(20)
- if not (rT1 = rT2) then
- set holdH to the locH of sprite (rT1 + pInitTileSprite)
- set holdV to the locV of sprite (rT1 + pInitTileSprite)
- set the locH of sprite (rT1 + pInitTileSprite) to the locH of sprite (rT2 + pInitTileSprite)
- set the locV of sprite (rT1 + pInitTileSprite) to the locV of sprite (rT2 + pInitTileSprite)
- set the locH of sprite (rT2 + pInitTileSprite) to holdH
- set the locV of sprite (rT2 + pInitTileSprite) to holdV
- updateStage()
- else
- end if
- end
-
- on StartANewGame me
- reset(me)
- scramble(me)
- set w to getAt(the windowList, 1)
- tell w
- SETDisplay(0)
- onINCDispay(gBaseScore * 10)
- end tell
- end
-
- on killGame me
- deactivateMIW(me)
- end
-
- on makeScoreBoard me
- cursor(4)
- if not (the windowList = []) then
- deactivateMIW(me)
- end if
- set pWindow to the pathName & "CATSCORE"
- set the windowType of window pWindow to 2
- set offSetL to the stageLeft
- set offSetT to the stageTop
- set myTop to the top of sprite pSprite + 34
- set theRect to rect(offSetL + 528, offSetT + myTop, offSetL + 528 + 94, offSetT + myTop + 40)
- set the rect of window pWindow to theRect
- set w to getAt(the windowList, 1)
- set the visible of w to 1
- cursor(-1)
- end
-
- on deactivateMIW me
- set w to getAt(the windowList, 1)
- set the visible of w to 0
- forget(w)
- end
-
- on doTick me
- addScore(me, -gBaseScore)
- end
-
- on addScore me, sValue
- set w to getAt(the windowList, 1)
- tell w
- onINCDispay(sValue)
- end tell
- end
-
- on showAll me
- set count to 1
- set maxTile to 20
- repeat while maxTile >= count
- set theTile to getAt(pGameTiles, count)
- show(theTile)
- set count to count + 1
- end repeat
- end
-
- on hideAll me
- set count to 1
- set maxTile to 20
- repeat while maxTile >= count
- set theTile to getAt(pGameTiles, count)
- hide(theTile)
- set count to count + 1
- end repeat
- end
-