Пример #1
0
    CarMotion.Move GetOneMoveDirection(CarMotion.Move[] listMove, int total)
    {
        CarMotion.Move ret = carMotion.direction;
        int            idx = Random.Range(0, total);

        //随机选一个方向走
        ret = listMove[idx];
        return(ret);
    }
Пример #2
0
    public CarMotion.Move CarMotionGetMoveDirection(CarMotion motion)
    {
        CarMotion.Move ret = motion.direction;

        // bool isNeedUpdate = UpdateRoadTilePostion();
        // if (!isNeedUpdate)
        // {
        //  return ret;
        // }


        int total = GetAllMoveDirection(listMoveNow);

        if (carMotion.runMode == CarMotion.RunMode.AUTO)
        {
            if (total > 1)
            {
                Debug.Log("CarMotionGetMoveDirection:total=" + total + " carMotion.direction=" + carMotion.direction + " now=(" + tileX + " ," + tileY + ") pre=(" + tileXPre + "," + tileYPre + ")");
            }
            if (total > 0)
            {
                ret = GetOneMoveDirection(listMoveNow, total);
            }
        }
        else if (carMotion.runMode == CarMotion.RunMode.CMD)
        {
            ret = GetCmdDirection(indexCmd);
            Debug.Log("GetCmdDirection::ret=" + ret + " indexCmd=" + indexCmd);
            if (IsCmdError(motion, ret, total))
            {
                //命令错误 停止运动
                Debug.Log("cmd is wrong,stop...");
                ret = CarMotion.Move.NONE;
                carMotion.runStatus = CarMotion.RunStatus.ERROR;
                if (iCarDelegate != null)
                {
                    iCarDelegate.CarUpdateStatus(this, carMotion.runStatus);
                }
            }
        }

        //运动停止
        if (total == 0)
        {
            //无路可走
            Debug.Log("no road to go...");
            ret = CarMotion.Move.NONE;
            carMotion.runStatus = CarMotion.RunStatus.STOP;
            if (iCarDelegate != null)
            {
                iCarDelegate.CarUpdateStatus(this, carMotion.runStatus);
            }
        }

        return(ret);
    }
Пример #3
0
    //判断命令是否错误
    public bool IsCmdError(CarMotion motion, CarMotion.Move cmdDirection, int total)
    {
        bool ret = true;

        for (int i = 0; i < total; i++)
        {
            CarMotion.Move direction = listMoveNow[i];
            if (cmdDirection == direction)
            {
                ret = false;
            }
        }

        return(ret);
    }
Пример #4
0
    CarMotion.Move GetCmdDirection(int idx)
    {
        CarMotion.Move ret = CarMotion.Move.NONE;
        if (idx < uiCmdBarRun.listItem.Count)
        {
            UICmdItem item = uiCmdBarRun.listItem[idx] as UICmdItem;
            switch (item.cmdType)
            {
            case UICmdItem.CmdType.START:
                ret = CarMotion.Move.RIGHT;
                break;

            case UICmdItem.CmdType.LEFT:
                ret = CarMotion.Move.LEFT;
                break;

            case UICmdItem.CmdType.RIGHT:
                ret = CarMotion.Move.RIGHT;
                break;

            case UICmdItem.CmdType.UP:
                ret = CarMotion.Move.UP;
                break;

            case UICmdItem.CmdType.DOWN:
                ret = CarMotion.Move.DOWN;
                break;

            case UICmdItem.CmdType.NONE:
                ret = CarMotion.Move.NONE;
                carMotion.runStatus = CarMotion.RunStatus.NO_CMD;
                if (iCarDelegate != null)
                {
                    iCarDelegate.CarUpdateStatus(this, carMotion.runStatus);
                }
                break;

            default:

                break;
            }
        }

        return(ret);
    }
Пример #5
0
    //判断是否是拐弯点
    public bool IsCornerItem(CarMotion motion)
    {
        bool ret = false;

        CarMotion.Move[] listMove = new CarMotion.Move[4];
        int total = GetAllMoveDirection(listMove);

        if (total > 1)
        {
            ret = true;
        }
        else if (total == 1)
        {
            if (listMove[0] != motion.direction)
            {
                ret = true;
            }
        }
        return(ret);
    }
Пример #6
0
    //上一个tile的方向
    CarMotion.Move GePretRoadTileDirection()
    {
        CarMotion.Move ret = CarMotion.Move.NONE;
        if ((tileXPre < tileX) && (tileYPre == tileY))
        {
            ret = CarMotion.Move.LEFT;
        }
        if ((tileXPre > tileX) && (tileYPre == tileY))
        {
            ret = CarMotion.Move.RIGHT;
        }

        if ((tileXPre == tileX) && (tileYPre > tileY))
        {
            ret = CarMotion.Move.UP;
        }
        if ((tileXPre == tileX) && (tileYPre < tileY))
        {
            ret = CarMotion.Move.DOWN;
        }

        return(ret);
    }