コード例 #1
0
        public int addNewChess(int xx, int yy, int dir, int ownner)
        {
            LiuheChess nlc = new LiuheChess(xx, yy, dir, ownner, IdentityNumberNow);

            chesses.Add(nlc);

            ChessBoardStateInfo cbsi = checkChessBoardState();

            if (cbsi.state != ChessBoardState.HEALTH)
            {
                LiuheLogger.Log(cbsi);
                chesses.Remove(nlc);
                return(-1);
            }

            List <int> dirs = Rules.Rules.getUsableDirection(this);

            if (!dirs.Contains(dir))
            {
                chesses.Remove(nlc);
                return(-2);
            }

            places.Add(new PlaceMemory(ownner, IdentityNumberNow, dir));
            if (places.Count > 2)
            {
                places.RemoveAt(0);
            }

            IdentityNumberNow++;
            return(IdentityNumberNow - 1);
        }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: shacleff/LianQiClient
        public bool moveChess(ChessObj co)
        {
            Debug.Log("移动了棋子,棋子是:");
            LiuheLogger.Log(co);

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

            return(result);
        }
コード例 #3
0
ファイル: Rules.cs プロジェクト: shacleff/LianQiClient
        public static LiuheChessBoard getTryResult(LiuheChessBoard board, int xx, int yy, int dir, LiuhePlayer lp)
        {
            GridValidState gvs = getGridValidState(board, xx, yy);

            if (gvs != GridValidState.VOID)
            {
                LiuheLogger.Log(gvs);
                return(null);
            }
            int idm = board.addNewChess(xx, yy, dir, lp._PlayerIndex);

            if (idm < 0)
            {
                //Debug.Log("此位置存在错误!");
                return(null);
            }

            GameBoardCalculateItself(board);

            return(board);
        }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: shacleff/LianQiClient
        public void startGame(int level, List <PLAYER_TYPE> ps, List <PLAYER_CHARACTER> pc)
        {
            if (_State != GAME_STATE.READY)
            {
                Debug.Log("当前状态下不能开始游戏!请检查后重新设置");
                return;
            }

            _BoardLevel = level;
            _GameBoard  = new LiuheChessBoard(_BoardLevel);

            _PlayerNum = ps.Count;
            _Players   = new List <LiuhePlayer>();
            for (int i = 0; i < _PlayerNum; i++)
            {
                if (ps[i] == PLAYER_TYPE.AI)
                {
                    _Players.Add(new LiuheAIPlayer(i, pc[i]));
                }
                else if (ps[i] == PLAYER_TYPE.LOCAL)
                {
                    _Players.Add(new LiuheLocalPlayer(i, pc[i]));
                }
                else if (ps[i] == PLAYER_TYPE.NETWORK)
                {
                    _Players.Add(new LiuheNetworkPlayer(i, pc[i]));
                }
                else
                {
                    Debug.Log("不存在这样的玩家类型!请检查后重新输入!");
                }
            }

            _State     = GAME_STATE.RUNNING;
            _PlayerNow = 0;

            LiuheLogger.Log(_Players);
        }
コード例 #5
0
ファイル: Display.cs プロジェクト: shacleff/LianQiClient
    // Update is called once per frame
    void Update()
    {
        //输出信息
        if (Input.GetButtonDown("Print"))
        {
            Debug.Log("输出信息:");
            LiuheChessBoard lb = _Manager._GameBoard;
            LiuheLogger.Log(lb);
        }
        if (Input.GetButtonDown("PrintDisplay"))
        {
            Debug.Log("输出信息:");
            LiuheLogger.Log(this);
        }

        if (_Manager._RoundNum != this._LastRound)
        {
            _LastRound  = _Manager._RoundNum;
            _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
            Debug.Log("切换了新回合");


            //切换新的指示牌出来
            if (_Manager._Players[_Manager._PlayerNow]._Type == PLAYER_TYPE.LOCAL)
            {
                tintLog2();
                _ChessLog3Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }
            else
            {
                tintLog2();
                _ChessLog3Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }
        }
    }
コード例 #6
0
ファイル: Rules.cs プロジェクト: shacleff/LianQiClient
        public static bool tryPlaceChessToGameBoard(LiuheChessBoard board, int xx, int yy, int dir, LiuhePlayer lp)
        {
            GridValidState gvs = getGridValidState(board, xx, yy);

            if (gvs != GridValidState.VOID)
            {
                LiuheLogger.Log(gvs);
                return(false);
            }

            int ss = board.places.Count;

            if (ss > 2)
            {
                Debug.Log("严重问题!! 过去存储超过限额!");
            }

            if (ss == 1)
            {
                PlaceMemory pm = board.places[0];
                if (pm.placeOwnner == lp._PlayerIndex)
                {
                    Debug.Log("该玩家这回合已经下过了!");
                    return(false);
                }
                if (pm.chessDir == dir)
                {
                    Debug.Log("这个方向是禁手方向!");
                    return(false);
                }
            }
            else if (ss == 2)
            {
                PlaceMemory pm0 = board.places[0];
                PlaceMemory pm1 = board.places[1];
                if (pm1.placeOwnner == lp._PlayerIndex)
                {
                    Debug.Log("该玩家这回合已经下过了!");
                    return(false);
                }
                if (pm0.chessDir == dir || pm1.chessDir == dir)
                {
                    Debug.Log("这个方向是禁手方向!");
                    return(false);
                }
            }


            int idm = board.addNewChess(xx, yy, dir, lp._PlayerIndex);

            if (idm < 0)
            {
                Debug.Log("此位置存在错误!");
                return(false);
            }

            GameBoardCalculateItself(board);

            if (board.findChessByIdnum(idm).health <= 0)
            {
                Debug.Log("下在此处生命值会不够!");
                return(false);
            }

            return(true);
        }
コード例 #7
0
ファイル: Display.cs プロジェクト: shacleff/LianQiClient
    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;
        }
    }