Beispiel #1
0
 /// <summary>
 /// 重置棋子状态
 /// </summary>
 public void ResetChessReciprocalState()
 {
     if (chessReciprocalState != ChessReciprocalState.unChoosed)
     {
         chessReciprocalState = ChessReciprocalState.unChoosed;
     }
 }
Beispiel #2
0
    protected ChessSituationState chessSituationState;      //棋子形势状态

    public virtual void Awake()
    {
        createManager          = GameObject.Find("CreateManager").GetComponent <CreateManager>();
        chessReciprocalState   = ChessReciprocalState.unChoosed;
        chessSituationState    = ChessSituationState.Idle;
        PoolManager.PushEvent += SubscribeEvents;//棋子被创建时就该订阅这一堆事件
        //SubscribeEvents(gameObject);
        PoolManager.TakeEvent    += SubscribeEvents;
        PoolManager.RestoreEvent += CancelSubscribeEvents;
    }
Beispiel #3
0
    public virtual void Awake()
    {
        createManager             = CreateManager.Instance;
        chessReciprocalState      = ChessReciprocalState.unChoosed;
        chessSituationState       = ChessSituationState.Idle;
        PoolManager.PushEvent    += SubscribeEvents;//棋子被创建时就该订阅这一堆事件
        PoolManager.TakeEvent    += SubscribeEvents;
        PoolManager.RestoreEvent += CancelSubscribeEvents;

        gameObject.AddComponent <AttrBox>();
        attrBox = gameObject.GetComponent <AttrBox>();
        attrBox.SetAttrList(ChessConfig.GetAttrList(chessName));
    }
Beispiel #4
0
    /// <summary>
    /// 通过鼠标点击来移动
    /// </summary>
    public void Move()
    {
        if (chessReciprocalState == ChessReciprocalState.beChoosed)
        {
            Vector2[] canMovePoints = CanMovePoints(CalculateUtil.chess2Vector, CalculateUtil.vector2Chess).ToArray();
            Vector3[] canMoveGrids  = new Vector3[canMovePoints.Length];
            for (int i = 0; i < canMoveGrids.Length; i++)   //将所有可移动的二维坐标转化成网格点三维坐标
            {
                canMoveGrids[i] = CalculateUtil.vector2Grids[canMovePoints[i]].transform.position;
            }

            if (canMovePoints.Length > 0)
            {
                for (int i = 0; i < canMovePoints.Length; i++)
                {
                    //鼠标点击在可移动点附近范围内,即可走步
                    if (canMoveGrids[i].x - 30 <= Input.mousePosition.x && Input.mousePosition.x <= canMoveGrids[i].x + 30 &&
                        canMoveGrids[i].y - 27.5 <= Input.mousePosition.y && Input.mousePosition.y <= canMoveGrids[i].y + 27.5)
                    {
                        //若点击位置存在其他棋子 且 是敌方棋子,那就是吃
                        if (CalculateUtil.vector2Chess.ContainsKey(canMovePoints[i]))
                        {
                            GameObject otherChess = CalculateUtil.vector2Chess[canMovePoints[i]];
                            if (otherChess.GetComponent <ChessCamp>().camp != GetComponent <ChessCamp>().camp)
                            {
                                EatEvent(otherChess);   //吃
                            }
                        }

                        chessReciprocalState = ChessReciprocalState.moving;//这里在移动的时候时间是0.1秒,这个时间段的状态改成moving状态,还需要改进,否则会有bug
                        iTween.MoveTo(gameObject, iTween.Hash("time", 0.1f, "position", canMoveGrids[i],
                                                              "easetype", iTween.EaseType.linear, "oncomplete", "TBS", "oncompletetarget", GameObject.Find("GameController")));
                    }
                    else if (chessReciprocalState != ChessReciprocalState.moving)
                    {
                        CancelChoose();
                    }
                }
            }
            else
            {
                CancelChoose();
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// 被选中
    /// </summary>
    public void BeChoosed()
    {
        //有白边圈住
        transform.FindChild("白边").gameObject.SetActive(true);

        //棋子稍微上升

        //可以提示出该棋子能移动的所有位置
        Vector2[] canMovePoints = CanMovePoints(CalculateUtil.chess2Vector, CalculateUtil.vector2Chess).ToArray();
        for (int i = 0; i < canMovePoints.Length; i++)
        {
            CalculateUtil.vector2Grids[canMovePoints[i]].GetComponent <Image>().enabled = true;
            //若可移动点上存在其他棋子,那肯定就是敌方棋子了,提示可以击杀之
            if (CalculateUtil.vector2Chess.ContainsKey(canMovePoints[i]))
            {
                CalculateUtil.vector2Chess[canMovePoints[i]].transform.FindChild("被成为目标").gameObject.SetActive(true);
            }
        }
        chessReciprocalState = ChessReciprocalState.beChoosed;
    }
Beispiel #6
0
    /// <summary>
    /// 被选中
    /// </summary>
    /// <param name="isAdding">是否在加属性</param>
    public void BeChoosed(bool isAdding)
    {
        transform.FindChild("baibian").gameObject.SetActive(true);  //有白边圈住
        if (!isAdding)
        {
            Scene3_UI.ResetChessBoardPoints();
            //可以提示出该棋子能移动的所有位置
            Vector2[] canMovePoints = CanMovePoints(GameCache.Chess2Vector, GameCache.Vector2Chess).ToArray();
            for (int i = 0; i < canMovePoints.Length; i++)
            {
                int x = (int)canMovePoints[i].x;
                int y = (int)canMovePoints[i].y;

                Scene3_UI.cells[x, y].GetComponent <Image>().enabled = true;
                //若可移动点上存在其他棋子,那肯定就是敌方棋子了,提示可以击杀之
                if (GameCache.Vector2Chess.ContainsKey(canMovePoints[i]))
                {
                    GameCache.Vector2Chess[canMovePoints[i]].transform.FindChild("redpoint").gameObject.SetActive(true);
                    TipsKillEvent(canMovePoints[i]);
                }
            }
            chessReciprocalState = ChessReciprocalState.beChoosed;
        }
    }
Beispiel #7
0
 public void OnMoveStart()
 {
     chessReciprocalState = ChessReciprocalState.moving;
     Scene3_UI.ResetChessBoardPoints();
 }