explain sliding game lingo

Posted on 2005-04-21
Last Modified: 2013-12-24
This code is for a picture sliding game where one block is used to move the images. There are 16 individual images including the empty block. Can any one explain the code below?

property spriteNum, piece

global pieceList, pickList

on beginSprite me

  piece = sprite(spriteNum)
  if pieceList = void then
    pieceList = []
  end if
  if pieceList.getOne(piece) <> 0 then

    pieceList = []
  end if  

on shuffle me
  if pickList = void then
    pickList = duplicate(pieceList)
  else if pickList.count = 0 then
    pickList = duplicate(pieceList)
  end if
  thisOne = random(pickList.count)
  sprite(spriteNum).member = member(pickList[thisOne])

on swap me, whatRect, whatSprite

  if sprite(spriteNum).member = member(pieceList[pieceList.count]) and spriteNum <> whatSprite then

    overlap = intersect(sprite(spriteNum).rect, whatRect)
    if (overLap.width > 0 or overlap.height > 0) then

      if overLap.width > 1 or overlap.height > 1 then

        whatMember = sprite(spriteNum).member
        sprite(spriteNum).member = sprite(whatSprite).member
        sprite(whatSprite).member = whatMember
      end if
    end if
  end if

on checkWin me, winList
  if sprite(spriteNum) = piece then
  end if

on mouseUp me
  sendAllSprites(#swap, (sprite(spriteNum).rect + rect(-1,-1,1,1), spriteNum)
  winList = []
  sendAllSprites(#checkWin, winList)
  if winList.getOne(0) = 0 then

    go "win"
  end if

on getBehaviorDescription me
  describe = "This behavior can be dropped on a grid of images to create a sliding puzzle game."
  describe = describe & return & "Be sure to name your pieces conncurrently and name the " & quote & "empty" & quote & " piece so that it will fall at the end of the list when sorted alphabetically."
  describe = describe & return &
  return describe
Question by:lukegriffiths110
    1 Comment
    LVL 5

    Accepted Solution

    It sure wold help if you were a bit more specific about what you understand and what you don't, do you have a working copy of the game? or do you need basic member score configuration tips for getting the code to work right?

    A couple of observations

    The behavior is dropped on all 16 tile sprites

    property spriteNum, piece
    -- are private variables different for each tile, sprieNum is a property of the scrip instance me passed to the handlers, a more common way to use it would be.

    put "my sprite is " & sprite(me.spriteNum)

    global pieceList, pickList
     -- are variables shared by all tiles, the lowest sprite number is the first script to run, it detects if the lists are not defined and creates the initial empty one as needed with:

    if pieceList = void then
        pieceList = []
      end if

    Each tile sprite, in turn adds it's member name to the  pieceList global list variable.  There mus be 16 unique member names assigned to the tile bitmaps, I suggest:  Tile1, Tile2 ...tile15, zEmptyOne The name "zEmptyOne" starts with z to insure the empty tile (a part of the background cut out in a tile shape) name ends at the end of a sorted list.

    it appears that a separate Shuffle button has to call the Shuffle handler in each of the  tiles in order to get the game reset.

    -- this reset button script should do
    on mouseUp
      sendAllSprites #Shuffle

    sendAllSprites is the function used by the clicked tile to  pass some information about it'self while communicating to all the others,

    Clicking a tile makes it send swap to all the tiles, passing a slightly expanded (by one pixel) rectangle to all the other sprites, only the sprite currently assigned the member takes action, it determines by the expanded rects pased to it, which tile is touching it, the empty tile sprit swaps image members with the clicked tile which is the one touching it

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
    Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
    The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be Log into your Hosting account. IPage will be used for demonstration : Locat…
    The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now