Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元
关于MVC俄罗斯方块的问题
c.def.gab发起了问答2017-11-10
3
回复
443
浏览
public class Model : MonoBehaviour {

    public const int MAX_ROWS = 23;
    public const int MAX_COLUMS = 10;

    private Transform[,] map = new Transform[MAX_COLUMS,MAX_ROWS];


    public bool IsValidMapPosition(Transform t) {

        foreach (Transform child in t)
        {
            if (child.tag == "Block") continue;// 应该是if(child.tag !="Block") continue;
            Vector2 pos = child.position.Round();
            if (isInsideMap(pos) == false) return false;
            if (map[(int)pos.x, (int)pos.y] != null) return false;
        }
        return true;
    }

    private bool isInsideMap(Vector2 pos)
    {
        return pos.x >= 0 && pos.x <= MAX_COLUMS && pos.y >= 0;
    }

    public void PlaceShape(Transform t)
    {
        foreach(Transform child in t){
            if (child.tag != "Block") return;//   应该是 if(child.tag!="Block") continue; 
            Vector2 pos = child.position.Round();
            map[(int)pos.x, (int)pos.y] = child;
        }
    }
   
}
---------------------------------------------------------------------------------------------------
public class Shape : MonoBehaviour {

    private Ctrl ctrl;
    private GameManager gameManager;

    private bool isPause = false;

    private float timer = 0;

    private float stepTime = 0.2f;
    void Update()
    {
        if (isPause) return;
        timer += Time.deltaTime;
        if (timer > stepTime) {
            Fall();
        }
    }

    public void Init(Color color,Ctrl ctrl,GameManager gameManager)
    {
        foreach (Transform t in transform)
        {
            if (t.tag == "Block")
            {
                t.GetComponent<SpriteRenderer>().color = color;
            }
        }
        this.ctrl = ctrl;
        this.gameManager = gameManager;
    }
    public void Fall() {

        timer = 0;
        Vector3 pos = transform.position;
        pos.y -= 1;
        transform.position = pos;
        if (ctrl.model.IsValidMapPosition(this.transform) == false)
        {
            pos.y += 1;
            transform.position = pos;
            isPause = true;
            //Debug.Log(isPause);
            ctrl.model.PlaceShape(this.transform);
            gameManager.FallDown();
        }
    }
}
---------------------------------------------------------------------------------------------------
我觉得应该就是这两个脚本哪里写的有问题,又不太能找的出来

如图,老师,我的俄罗斯方块在某些方块的地方会叠加起来,我也不知道问题在哪,老师能帮忙看看么。

所有回复
发表回复
你还没有登录,请先 登录或 注册!