Exemplo n.º 1
0
    public ChessObj addChess(GridObj go)
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return(null);
        }

        if (!_IsStarted || (_RoundState != DisplayState.HAS_NOT_PLACE_CHESS &&
                            _RoundState != DisplayState.HAS_PLACE_CHESS &&
                            _RoundState != DisplayState.PLACE_CHESS_WRONG &&
                            _RoundState != DisplayState.DO_NOTHING))
        {
            //Debug.Log("回合状态不对");
            return(null);
        }

        if (_Manager.isThisGridEmpty(go.x, go.y))
        {
            ChessObj co = generateChess(go.x, go.y, go, _Manager._PlayerNow);
            if (_TempChess != null)
            {
                Destroy(_TempChess.gameObject);
            }
            _TempChess = co;
            changeDgree(0);
            return(co);
        }

        Debug.Log("底层认为格子不空");
        return(null);
    }
Exemplo n.º 2
0
        public static LiuheChessBoard getTryEndBoard(ChessObj co, LiuheChessBoard lcb)
        {
            LiuheChess lc = lcb.findChessByIdnum(co._ChessIdentityNumber);

            int[]          pos = lcb.getPointPos(lc.x, lc.y, lc.dir);
            GridValidState gvs = getGridValidState(lcb, pos[0], pos[1]);

            if (gvs != GridValidState.VOID)
            {
                return(null);
            }
            else
            {
                LiuheChessBoard lcb2 = lcb.getCopy();
                LiuheChess      lc2  = lcb2.findChessByIdnum(lc.identityNumber);
                if (lc2 == null)
                {
                    Debug.Log("严重错误");
                    return(null);
                }
                lc2.x = pos[0];
                lc2.y = pos[1];

                GameBoardCalculateItself(lcb2);
                return(lcb2);
            }
        }
Exemplo n.º 3
0
    public void OnMouseDown()
    {
        // Debug.Log("点击了网格");
        //有棋子存在情况下
        if (_Chess != null)
        {
            //Debug.Log("waht");
            //如果这个棋子可以转动(也就是这个回合下的棋子的话)
            if (!_CanChange)
            {
                Debug.Log("不可移动");
                return;
            }
            else
            {
                //Debug.Log("点击到了本回合生成的棋子上");
            }
        }

        //没有棋子存在的情况下,生成棋子并赋值
        ChessObj co = _Father.addChess(this);

        if (co != null)
        {
            _Chess     = co;
            _CanChange = true;
        }
        else
        {
            //Debug.Log("没有成功生成");
        }
    }
Exemplo n.º 4
0
    public ChessObj set(int xx, int yy, int dir, GridObj go, int ownner)
    {
        _Ownner              = ownner;
        _Direction           = dir;
        _ChessIdentityNumber = -1;
        _GridOccupy          = go;

        x = go.x;
        y = go.y;

        Debug.Log(ownner);

        _DisRenderer.sprite = _DirsSprite[ownner];

        _Health = 0;
        _Absorb = 0;
        _Attack = 0;

        this.transform.name = "(" + go.x + ", " + go.y + ")--棋子";

        _CanMove = false;

        _IsAlive           = true;
        _Temp_ForwardChess = null;

        return(this);
    }
Exemplo n.º 5
0
    //点到了空白的地方
    public void clickEmypt()
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return;
        }

        //如果有临时棋子
        if (_TempChess != null)
        {
            //删除临时棋子
            Destroy(_TempChess.gameObject);
            _TempChess = null;
            //如果是下过或者下错棋的模式,就把状态拨回
            if (_RoundState == DisplayState.DO_NOTHING || _RoundState == DisplayState.PLACE_CHESS_WRONG || _RoundState == DisplayState.HAS_NOT_PLACE_CHESS)
            {
                _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
                //弹出说明框
                _ChessLogTransform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog3Transform.DOMove(_ChessLogStart.position, 0.5f);
                //变色
                tintLog2();
                _ChessLog2Transform.DOMove(_ChessLogEnd.position, 0.5f);
                //Debug.Log("切换状态");
            }
        }
        updateBoard();
    }
Exemplo n.º 6
0
 public void aiMove(Vector3 np, ChessObj tar)
 {
     transform.DOMove(np, 0.35f);
     _GridOccupy         = tar._GridOccupy;
     x                   = tar.x;
     y                   = tar.y;
     this.transform.name = "(" + x + ", " + y + ")--棋子";
 }
Exemplo n.º 7
0
        public bool moveChess(ChessObj co)
        {
            Debug.Log("移动了棋子,棋子是:");
            LiuheLogger.Log(co);

            bool result = Rules.Rules.moveChessInBoard(_GameBoard.findChessByIdnum(co._ChessIdentityNumber), _GameBoard);

            return(result);
        }
Exemplo n.º 8
0
    private ChessObj generateChess(int xx, int yy, GridObj go, int ownner)
    {
        ChessObj co = Instantiate(_ChessPrefab, new Vector3(0, 0, 0), Quaternion.identity);

        co.set(xx, yy, 0, go, ownner);
        co._Father = this;
        co.recalculatorTransform();
        co.transform.SetParent(_ChessRoot);
        //Debug.Log(pos.ToString());
        return(co);
    }
Exemplo n.º 9
0
        public static void Log(ChessObj co)
        {
            string str = "棋子" + co.transform.name + ":\n";

            str += co.x + ", " + co.y + ", " + co._Direction + "\n";
            str += "Can move:  " + co._CanMove + "\n";
            str += "Has Move: " + co._HasMove + "\n";
            str += "Is Alive: " + co._IsAlive + "\n";
            str += "ID" + co._ChessIdentityNumber + "\n";

            Debug.Log(str);
        }
Exemplo n.º 10
0
 //可以移动
 public void setForward(Vector3 np, ChessObj tar, int ti)
 {
     _OldTrans  = new Vector3(transform.position.x, transform.position.y, transform.position.z);
     _TenpTrans = new Vector3(np.x, np.y, np.z);
     _ForwardTarget.DOScale(new Vector3(1, 1, 1), 0.25f);
     _Temp_ForwardChess = tar;
     _CanMove           = true;
     _HasMove           = false;
     _GridOccupyOld     = _GridOccupy;
     oldx       = x;
     oldy       = y;
     _TargetInt = ti;
 }
Exemplo n.º 11
0
    public void placeChessUnsafeAI(int xx, int yy, int dir, int ownner)
    {
        GridObj  go  = findGridObj(xx, yy);
        ChessObj co  = generateChess(go.x, go.y, go, ownner);
        int      idm = _Manager.makeNewChessUnSafe(xx, yy, dir, ownner);

        co._ChessIdentityNumber = idm;
        _ChessList.Add(co);
        go._Chess = co;
        co.rotate(dir);
        GameManager._Main.updateChessBoard();
        updateBoard();
        Debug.Log("生成了一颗棋子");
    }
Exemplo n.º 12
0
    public void makeChess(int xx, int yy, int dir, int oo)
    {
        GridObj  go  = findGridObj(xx, yy);
        ChessObj co  = generateChess(go.x, go.y, go, oo);
        int      idm = _Manager.makeNewChessUnSafe(xx, yy, dir, oo);

        co._ChessIdentityNumber = idm;
        _ChessList.Add(co);
        go._Chess = co;
        co.rotate(dir);

        Debug.Log("生成了一颗棋子");

        return;
    }
Exemplo n.º 13
0
        public bool getTryMoveBoard(ChessObj co)
        {
            LiuheChessBoard lcb = Rules.Rules.getTryEndBoard(co, _GameBoard);

            if (lcb != null)
            {
                int h = lcb.findChessByIdnum(co._ChessIdentityNumber).health;
                Debug.Log(h);
                if (h <= 0)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 14
0
    public IEnumerator killAChessAndMove(int xx, int yy)
    {
        _Manager.updateChessBoard();
        updateBoard();

        int      idm = GameManager._Main._GameBoard.findChessByPosition(xx, yy).identityNumber;
        ChessObj cc  = findChessObj(idm);
        ChessObj ck  = null;

        foreach (ChessObj co in _ChessList)
        {
            if (co._Health <= 0)
            {
                co.kill();
                ck = co;
                break;
            }
        }

        if (ck != null)
        {
            yield return(new WaitForSeconds(0.5f));

            cc.aiMove(ck.GetComponent <Transform> ().position, ck);
            GameManager._Main.washOut();
            if (_Manager.moveChessAI(cc))
            {
                //Debug.Log("fine");
            }
            else
            {
                Debug.Log("老兄你又写错了");
            }
            _ChessList.Remove(ck);
            Destroy(ck.gameObject);
            yield return(new WaitForSeconds(0.5f));

            relinkGrid();
        }
    }
Exemplo n.º 15
0
 //不要移动
 public void setNotMove()
 {
     _ForwardTarget.DOScale(new Vector3(0, 0, 1), 0.25f);
     _Temp_ForwardChess = null;
     _CanMove           = false;
 }
Exemplo n.º 16
0
        public bool moveChessAI(ChessObj co)
        {
            bool result = Rules.Rules.moveChessInBoardUnsafe(_GameBoard.findChessByIdnum(co._ChessIdentityNumber), _GameBoard);

            return(result);
        }
Exemplo n.º 17
0
 public void clear()
 {
     _Chess     = null;
     _CanChange = false;
 }
Exemplo n.º 18
0
 public LiuheChessBoard getTryMoveChessBoard(ChessObj co, LiuheChessBoard lcb)
 {
     return(Rules.Rules.getTryEndBoard(co, lcb));
 }
Exemplo n.º 19
0
 public LiuheChessBoard getTryMoveChessBoard(ChessObj co)
 {
     return(Rules.Rules.getTryEndBoard(co, _GameBoard));
 }
Exemplo n.º 20
0
 public void setChess(ChessObj co)
 {
     _Chess     = co;
     _CanChange = false;
 }
Exemplo n.º 21
0
    public void endTurn()
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return;
        }

        switch (_RoundState)
        {
        case DisplayState.HAS_NOT_PLACE_CHESS:
            //有棋子
            if (_TempChess != null)
            {
                LiuheChessBoard lcb = _Manager.tryToPlace(_TempChess.x, _TempChess.y, _TempChess._Direction);
                //落子成功
                if (lcb != null)
                {
                    //如果生命值小于等于零
                    if (_TempChess._Health <= 0)
                    {
                        _ChessLogTransform.GetComponent <Animator>().SetTrigger("atten");
                        Destroy(_TempChess.gameObject);
                        _TempChess  = null;
                        _RoundState = DisplayState.PLACE_CHESS_WRONG;
                    }
                    //如果生命值大于零
                    else
                    {
                        //如果可以下棋,则下棋一个
                        _ChessList.Add(_TempChess);
                        _Manager.placeChess(_Manager._Players[_Manager._PlayerNow], _TempChess.x, _TempChess.y, _TempChess._Direction);
                        _TempChess._GridOccupy.setLock();
                        _TempChess = null;
                        //状态转为下过了棋子,再一次调用这个函数
                        _RoundState = DisplayState.HAS_PLACE_CHESS;
                        endTurn();
                    }
                }
                //落子失败
                else
                {
                    _ChessLogTransform.GetComponent <Animator>().SetTrigger("atten");
                    Destroy(_TempChess.gameObject);
                    _TempChess  = null;
                    _RoundState = DisplayState.PLACE_CHESS_WRONG;
                }
            }
            //没有棋子
            else
            {
                //状态转为什么也不干
                _RoundState = DisplayState.DO_NOTHING;
                //告知将结束回合
                _ChessLogTransform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog3Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }

            break;

        case DisplayState.HAS_PLACE_CHESS:
            //判断下子之后需不需要特殊处理
            if (_Manager._GameBoard.deads.Count > 0)
            {
                //如果有棋子死亡,则转到移动棋子模式,再一次调用这个函数
                _RoundState = DisplayState.MOVE_CHESS;
                endTurn();
            }
            else
            {
                //如果没有棋子死亡,则自动进入下一回合
                //状态转为结束回合,再一次调用这个函数
                _RoundState = DisplayState.ENDTURN;
                endTurn();
            }
            break;

        case DisplayState.PLACE_CHESS_WRONG:
            if (_TempChess != null)
            {
                _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
                endTurn();
                break;
            }

            //状态转为什么也不干
            _RoundState = DisplayState.DO_NOTHING;
            //告知将结束回合
            _ChessLogTransform.DOMove(_ChessLogStart.position, 0.5f);
            _ChessLog2Transform.DOMove(_ChessLogStart.position, 0.5f);
            _ChessLog3Transform.DOMove(_ChessLogEnd.position, 0.5f);
            break;

        case DisplayState.MOVE_CHESS:       //找出可以移动的棋子
            //移动棋子代码不在这里,这里是设置移动棋子状态的地方

            //杀掉不需要的棋子
            foreach (ChessObj co in _ChessList)
            {
                if (co._Health <= 0)
                {
                    co.kill();
                }
            }

            //把所有的棋子都设为不可移动
            foreach (ChessObj item in _ChessList)
            {
                item.setNotMove();
            }

            //获得尝试结束的结果
            List <SpecialChessLink> scl = _Manager.tryEndAction();
            _HasMoveChessList = new List <ChessObj>();

            //当返回为空、或者没有可当前攻击的棋子时,结束回合;反之,进行移动棋子
            if (scl != null)
            {
                List <ChessObj> cos = new List <ChessObj>();
                //查看所有能攻击的棋子
                foreach (SpecialChessLink item in scl)
                {
                    ChessObj c = findChessObj(item._From_Idm);
                    //当可以攻击的棋子存在并且是当前回合的玩家时
                    if (c != null && c._Ownner == _Manager._PlayerNow)
                    {
                        ChessObj atc = findChessObj(item._To_Idm);
                        if (atc == null)
                        {
                            Debug.Log(item._To_Idm);
                            LiuheLogger.Log(_Manager._GameBoard.findChessByIdnum(c._ChessIdentityNumber));
                            Debug.Log("严重错误!");
                            LiuheLogger.Log(scl);
                        }
                        //设置这个棋子可以移动
                        c.setForward(atc.transform.position, atc, item._To_Idm);
                        cos.Add(c);
                    }
                }

                if (cos.Count > 0)
                {
                    //当有足够的可攻击棋子存在时,去除所有的死亡棋子
                    _Manager.washOut();
                    //状态转换为等待棋子移动
                    _RoundState = DisplayState.HAS_MOVED_CHESS;
                    clickEmypt();
                }
                else
                {
                    //当没有足够可攻击棋子存在时,也就是结束回合
                    _Manager.washOut();
                    _RoundState = DisplayState.ENDTURN;
                    endTurn();
                }
            }
            //当返回为空时,也就是没有合理棋子指着这里
            else
            {
                //结束回合
                _Manager.washOut();
                _RoundState = DisplayState.ENDTURN;
                endTurn();
            }
            break;

        case DisplayState.HAS_MOVED_CHESS:      //移动的棋子移动之后(或者没有移动之后)
        {
            //这里都是已经决定好移动结果后进来的地方
            //也就是移动的代码在别处,这里只提交结果
            if (_HasMoveChessList != null && _HasMoveChessList.Count > 0)
            {
                //判断是否真的可以
                bool            allright = true;
                LiuheChessBoard lcb      = _Manager._GameBoard.getCopy();
                lcb = _Manager.getTryMovesMultiChessBoard(_HasMoveChessList, lcb);
                List <ChessObj> dcoes = new List <ChessObj>();
                foreach (ChessObj co in _HasMoveChessList)
                {
                    if (lcb.findChessByIdnum(co._ChessIdentityNumber).health <= 0)
                    {
                        co.moveToOld();
                        dcoes.Add(co);
                        allright = false;
                        //Debug.Log("应该回去");
                    }
                }

                if (allright)
                {
                    //删除所有死掉的棋子
                    List <ChessObj> dd = new List <ChessObj>();
                    foreach (ChessObj co in _ChessList)
                    {
                        if (!co._IsAlive)
                        {
                            dd.Add(co);
                        }
                    }

                    foreach (ChessObj co in dd)
                    {
                        _ChessList.Remove(co);
                        Destroy(co.gameObject);
                    }

                    _Manager.washOut();


                    //正式移动
                    foreach (ChessObj co in _HasMoveChessList)
                    {
                        _Manager.moveChess(co);
                    }
                    _RoundState = DisplayState.MOVE_CHESS;
                    updateBoard();
                    _HasMoveChessList = new List <ChessObj>();
                    endTurn();
                }
                else
                {
                    foreach (ChessObj c in dcoes)
                    {
                        _HasMoveChessList.Remove(c);
                    }
                }



                #region old

                /*
                 * if (_Manager.getTryMoveBoard(_HasMovedChess))
                 * {
                 *  //删除所有死掉的棋子
                 *  List<ChessObj> dd = new List<ChessObj>();
                 *  foreach (ChessObj co in _ChessList)
                 *  {
                 *      if (!co._IsAlive)
                 *      {
                 *          dd.Add(co);
                 *      }
                 *  }
                 *
                 *  foreach (ChessObj co in dd)
                 *  {
                 *      _ChessList.Remove(co);
                 *      Destroy(co.gameObject);
                 *  }
                 *
                 *  _Manager.washOut();
                 *
                 *
                 *  //正式移动
                 *  _Manager.moveChess(_HasMovedChess);
                 *  _RoundState = DisplayState.MOVE_CHESS;
                 *  updateBoard();
                 *  _HasMovedChess = null;
                 *  endTurn();
                 * }
                 * else
                 * {
                 *  _HasMovedChess.moveToOld();
                 *  _HasMovedChess = null;
                 *  updateBoard();
                 *  Debug.Log("应该回去");
                 * }
                 */
                #endregion
            }
            else
            {
                //删除所有死掉的棋子
                List <ChessObj> dd = new List <ChessObj>();
                foreach (ChessObj co in _ChessList)
                {
                    if (!co._IsAlive)
                    {
                        dd.Add(co);
                    }
                }

                foreach (ChessObj co in dd)
                {
                    _ChessList.Remove(co);
                    Destroy(co.gameObject);
                }

                _RoundState = DisplayState.MOVE_CHESS;
                clickEmypt();
                endTurn();
            }
        }
        break;

        case DisplayState.DO_NOTHING:
            if (_TempChess != null)
            {
                _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
                endTurn();
                break;
            }

            //状态转为结束游戏,然后再一次调用
            _RoundState = DisplayState.ENDTURN;
            endTurn();
            break;

        case DisplayState.ENDTURN:
            //真正结束回合
            _Manager.endTurn();
            //切换新的指示牌出来
            if (_Manager._Players[_Manager._PlayerNow]._Type == PLAYER_TYPE.LOCAL)
            {
                tintLog2();
                _ChessLog3Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }
            //删除所有死掉的棋子
            List <ChessObj> dco = new List <ChessObj>();
            foreach (ChessObj co in _ChessList)
            {
                if (!co._IsAlive)
                {
                    dco.Add(co);
                }
            }

            foreach (ChessObj co in dco)
            {
                _ChessList.Remove(co);
                Destroy(co.gameObject);
            }
            relinkGrid();
            _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
            break;

        default:
            break;
        }
    }
Exemplo n.º 22
0
    //点击移动棋子,输入是要移动的棋子
    public void clickMoveChess(ChessObj co)
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return;
        }

        if (co._HasMove)
        {
            co.moveToOld();
            _HasMoveChessList.Remove(co);
        }
        else
        {
            ChessObj oldc = findChessByMoveTarget(co._TargetInt);
            if (oldc != null)
            {
                _HasMoveChessList.Remove(oldc);
                oldc.moveToOld();
            }

            co.moveToTemp();
            _HasMoveChessList.Add(co);
        }

        LiuheChessBoard lcb = _Manager._GameBoard.getCopy();

        lcb = _Manager.getTryMovesMultiChessBoard(_HasMoveChessList, lcb);

        updateBoard(lcb.chesses);

        #region old


        /*
         *
         * _HasMovedChess = null;
         * //Debug.Log("iinin");
         * foreach (ChessObj c in _ChessList) {
         *  if (c == co)
         *  {
         *      if (c._HasMove)
         *      {
         *          c.moveToOld();
         *      }
         *      else
         *      {
         *          _HasMovedChess = co;
         *          c.moveToTemp();
         *      }
         *  }
         *  else if (c._CanMove && c._HasMove) {
         *      c.moveToOld();
         *  }
         * }
         * if (_HasMovedChess != null)
         * {
         *  //更新移动后的数值
         *  LiuheChessBoard lcb2 = _Manager.getTryMoveChessBoard(_HasMovedChess);
         *  updateBoard(lcb2.chesses);
         * }
         * else {
         *  updateBoard();
         * }
         *
         */

        #endregion
    }