Time for action — counting matching tiles

To count the matching tiles, follow the ensuing steps:

  1. Add the method CountGems into the game class. The parameters are the first and second object.
    Method CountGems:Int(obj1:ftObject, obj2:ftObject)
    
  2. Define four local INT variables that store the x and y positions of the objects.
    Local x1:Int
    Local y1:Int
    Local x2:Int
    Local y2:Int
    
  3. Now define four INT variables that store the number of gems that were found.
    Local gemCountX1:Int
    Local gemCountY1:Int
    Local gemCountX2:Int
    Local gemCountY2:Int
    
  4. Get the slot positions of both objects.
    x1 = GetSlotX(obj1)
    y1 = GetSlotX(obj1)
    x2 = GetSlotX(obj2)
    y2 = GetSlotY(obj2)
    
  5. Retrieve the gem count of the first object. The position is the one of the second object, as that is where the first object is to be moved.
    gemCountX1 = CheckGemsX(x2, y2, obj1.GetTag())
    gemCountY1 = CheckGemsY(x2, y2, obj1.GetTag())
    
  6. Do the opposite for the second object.
    gemCountX2 = CheckGemsX(x1, y1, obj2.GetTag())
    gemCountY2 = CheckGemsY(x1, y1, obj2.GetTag())
    
  7. Return the higher of these values.
    Return Max(Max(gemCountX1, gemCountY1),Max(gemCountX2, gemcountY2))
    End
    

What just happened?

The method CountGems will let you determine how many matching gems there would be, if two objects switched their locations. We will make use of this data in the OnObjectTouch event from the engine class.

The precious one… creating a gem

If gems are deleted, it is only natural to create new ones, in a game like Treasure Chest. For this, we will create a new method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.228.78