public void Move(Vector2 vec)
 {
     vec = Vec2Math.roundVec2(vec);
     if (isValidPos(vec))
     {
         Map.Instance.updateStone(this, mapPos + vec);
     }
 }
Example #2
0
 public Stone getStone(Vector2 vec)
 {
     vec = Vec2Math.roundVec2(vec);
     if (!isInside(vec) || map[(int)vec.x, (int)vec.y] == null)
     {
         return(null);
     }
     return(map[(int)vec.x, (int)vec.y]);
 }
 public void firstSet()
 {
     foreach (Transform child in children)
     {
         if (child.gameObject == gameObject || !child.CompareTag("Stone"))
         {
             continue;
         }
         child.transform.GetComponent <Stone>().mapPos = new Vector2(-1, -1);
         Map.Instance.updateStone(child.transform.GetComponent <Stone>(), Vec2Math.roundVec2(child.transform.position));
     }
 }
 public bool isValidPos(Vector2 vec)
 {
     vec = mapPos + Vec2Math.roundVec2(vec);
     if (!Map.Instance.isInside(vec))
     {
         return(false);
     }
     else if (Map.Instance.getStone(vec) != null && Map.Instance.getStone(vec).transform.parent != transform.parent)
     {
         return(false);
     }
     return(true);
 }
    public bool isStucked()
    {
        Vector2 vec = Vec2Math.roundVec2(mapPos);

        if ((int)vec.y == 0)
        {
            return(true);
        }
        else if (Map.Instance.getStone(vec + Vector2.down) != null && !(Map.Instance.getStone(vec + Vector2.down).isMoving))
        {
            return(true);
        }
        return(false);
    }
Example #6
0
    public void updateStone(Stone stone, Vector2 v)
    {
        Vector2 origin = Vec2Math.roundVec2(stone.mapPos);

        v = Vec2Math.roundVec2(v);
        if (!isInside(v))
        {
            return;
        }

        if (isInside(origin) && map[(int)origin.x, (int)origin.y] == stone)
        {
            map[(int)origin.x, (int)origin.y] = null;
        }
        map[(int)v.x, (int)v.y]             = stone;
        stone.GetComponent <Stone>().mapPos = v;
    }
    public void checkMatch()
    {
        StageManager.Instance.matchQueue.Add(this);
        Vector2 tempVec;
        Stone   tempStone;

        for (int i = 0; i < 4; i++)
        {
            tempVec   = Vec2Math.roundVec2(mapPos + Vec2Math.rotate(Vector2.up, (-90f) * i));
            tempStone = Map.Instance.getStone(tempVec);
            if (Map.Instance.getStone(tempVec) == null)
            {
                continue;
            }
            if (!tempStone.isMoving && tempStone.myCol == myCol && !StageManager.Instance.matchQueue.Contains(tempStone))
            {
                tempStone.checkMatch();
            }
        }
        return;
    }