?
Solved

explain sliding game lingo

Posted on 2005-04-21
1
Medium Priority
?
400 Views
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).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
0
Comment
Question by:lukegriffiths110
1 Comment
 
LVL 5

Accepted Solution

by:
LingoMaster earned 2000 total points
ID: 13839568
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
end

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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
Suggested Courses

862 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