Link to home
Start Free TrialLog in
Avatar of lukegriffiths110
lukegriffiths110

asked on

explain sliding game lingo

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).member.name
  if pieceList = void then
    pieceList = []
  end if
  if pieceList.getOne(piece) <> 0 then

    pieceList = []
  end if  
  pieceList.add(piece)
end

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])
  pickList.deleteAt(thisOne)  
end

on swap me, whatRect, whatSprite

  sort(pieceList)  
  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
end

on checkWin me, winList
  if sprite(spriteNum).member.name = piece then
    winList.add(1)
  else
    winList.add(0)
  end if
end

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
end

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
end
ASKER CERTIFIED SOLUTION
Avatar of LingoMaster
LingoMaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial