围住神经猫

23 篇文章 0 订阅
    /// <summary>
    /// 判断下一步可能的位置,计算猫可移动的位置
    /// </summary>
    /// <returns></returns>
    private ArrayList FindSteps()
    {
        Items items = cat.GetComponent<Items>();
        int rowIndex = items.rowIndex;
        int columnIndex = items.columnIndex;


        ArrayList steps = new ArrayList();
        Vector2 nextStep = new Vector2();
        #region 获得可以行走的位置 上下左右
        //left
        nextStep.y = rowIndex;
        nextStep.x = columnIndex-1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //right
        nextStep.y = rowIndex;
        nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //top
        nextStep.y = rowIndex + 1;
        nextStep.x = columnIndex;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //bottom
        nextStep.y = rowIndex - 1;
        nextStep.x = columnIndex;
        if (Movable(nextStep))
            steps.Add(nextStep);
        #endregion


        //奇数行topleft,偶数行topright
        nextStep.y = rowIndex + 1;
        if (rowIndex % 2 == 1)
            nextStep.x = columnIndex - 1;
        else
            nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //奇数行bottomleft,偶数行bottomright
        nextStep.y = rowIndex - 1;
        if (rowIndex % 2 == 1)
            nextStep.x = columnIndex - 1;
        else
            nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        return steps;
    }
    /// <summary>
    /// 根据指定的位置找最大的通路
    /// </summary>
    /// <param name="vector"></param>
    /// <returns></returns>
    int FindSteps(Vector2 vector)
    {
        Items items = GetPot((int)vector.y, (int)vector.x);
        int rowIndex = items.rowIndex;
        int columnIndex = items.columnIndex;
        ArrayList steps = new ArrayList();
        Vector2 nextStep = new Vector2();


        #region 获得可以行走的位置 上下左右
        //left
        nextStep.y = rowIndex;
        nextStep.x = columnIndex - 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //right
        nextStep.y = rowIndex;
        nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //top
        nextStep.y = rowIndex + 1;
        nextStep.x = columnIndex;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //bottom
        nextStep.y = rowIndex - 1;
        nextStep.x = columnIndex;
        if (Movable(nextStep))
            steps.Add(nextStep);
        #endregion


        //奇数行topleft,偶数行topright
        nextStep.y = rowIndex + 1;
        if (rowIndex % 2 == 1)
            nextStep.x = columnIndex - 1;
        else
            nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        //奇数行bottomleft,偶数行bottomright
        nextStep.y = rowIndex - 1;
        if (rowIndex % 2 == 1)
            nextStep.x = columnIndex - 1;
        else
            nextStep.x = columnIndex + 1;
        if (Movable(nextStep))
            steps.Add(nextStep);
        return steps.Count;

    }



  private void SetAllPaths()
    {
        //左上角
        for (int i = 0; i < rowNum ; i++)
        {
            for (int j = 0; j < columnNum ; j++)
            {
                if (Movable(new Vector2(i, j)))
                    ChangePath(new Vector2(i, j));


                if (Movable(new Vector2(j, i)))
                    ChangePath(new Vector2(j, i));
            }
        }
        //左下角
        for (int i = 0; i < rowNum ; i++)
        {
            for (int j = 0; j < columnNum ; j++)
            {
                if(Movable (new Vector2 (i,rowNum -1-j)))
                    ChangePath (new Vector2 (i,rowNum -1-j));
                if(Movable (new Vector2 (columnNum -1-j,i)))
                ChangePath (new Vector2 (columnNum -1-j,i));
            }
        }


        //右上角
        for (int i = 0; i < rowNum; i++)
        {
            for (int j = 0; j < columnNum; j++)
            {
                if (Movable(new Vector2(i, rowNum - 1 - j)))
                    ChangePath(new Vector2(i, rowNum - 1 - j));
                if (Movable(new Vector2(j, columnNum - 1 - i)))
                    ChangePath(new Vector2(j, columnNum - 1 - i));
            }
        }


        //右下角
        for (int i = 0; i < rowNum; i++)
        {
            for (int j = 0; j < columnNum; j++)
            {
                if (Movable(new Vector2(rowNum - 1 - i, rowNum - 1 - j)))
                    ChangePath(new Vector2(rowNum - 1 - i, rowNum - 1 - j));
                if (Movable(new Vector2(columnNum - 1 - j, columnNum - 1 - i)))
                    ChangePath(new Vector2(columnNum - 1 - j, columnNum - 1 - i));
            }
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值