コード例 #1
0
ファイル: ChessMove.cs プロジェクト: jie65535/ChineseChess
 public ChessMove(ChessCamp camp, ChessType chess, ChessType?killed, ChessboardPosition start, ChessboardPosition end, string text)
 {
     Camp   = camp;
     Chess  = chess;
     Killed = killed;
     Start  = start;
     End    = end;
     Text   = text;
 }
コード例 #2
0
        protected override GetChessPiecePossibleMovesResponse Handle(GetChessPiecePossibleMovesRequest request)
        {
            var currentPosition = new ChessboardPosition(request.ChessboardPosition.X, request.ChessboardPosition.Y);
            var possibleMoves   = chessPieceCollection
                                  .GetChessPiece(request.ChessPieceKind)
                                  .GetPossibleMoves(currentPosition);

            return(new GetChessPiecePossibleMovesResponse(
                       request.ChessboardPosition,
                       possibleMoves.Select(m => new ChessboardPositionDto(m.To.X, m.To.Y))));
        }
コード例 #3
0
    private Unit unit; // UI所属的单位

    #endregion Fields

    #region Constructors

    public UnitUI(Unit summonUnit, ChessboardPosition position)
    {
        if (Chessboard.GetCell(position).UnitOnCell == null)
        {
            unit = summonUnit;
            InitUnitImage();
            InitUnitGroupImage();
            InitUnitHPText();

            UnitManager.AddUnitSprite(this);
        }
    }
コード例 #4
0
        private static IEnumerable <ChessMove> MoveWhileValid(
            ChessboardPosition currentPosition, PositionChange positionChange)
        {
            var initialPosition = currentPosition;
            var chessMoves      = new List <ChessMove>();

            while (currentPosition.CanMoveBy(positionChange))
            {
                var nextPosition = currentPosition.MovedBy(positionChange);
                chessMoves.Add(new ChessMove(initialPosition, nextPosition));
                currentPosition = nextPosition;
            }
            return(chessMoves);
        }
コード例 #5
0
 /// <summary>
 /// 检测两个位置是否相邻
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public bool Adjacent(ChessboardPosition position)
 {
     return Math.Abs(position.x - x) + Math.Abs(position.y - y) == 1;
 }
コード例 #6
0
 public IEnumerable <ChessMove> GetPossibleMoves(ChessboardPosition currentPosition)
 {
     return(AllowedMoves.SelectMany(move => MoveWhileValid(currentPosition, move)));
 }
コード例 #7
0
 /// <summary>
 /// </summary>
 /// <param name="position">左下为(0, 0)</param>
 /// <returns></returns>
 private static Vector2 GetCellPosition(ChessboardPosition position)
 {
     const float pivot = 0.5F;
     RectTransform anchor = ChessboardObject.GetInstance().GetComponent<RectTransform>();
     return new Vector2(anchor.localPosition.x + (position.x + pivot) * CellSize,
         anchor.localPosition.y - (BattleConsts.MapMaxRow - position.y - pivot) * CellSize);
 }
コード例 #8
0
 /// <summary>
 /// 检测两个位置是否相邻
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public bool Adjacent(ChessboardPosition position)
 {
     return Math.Abs(position.col - col) + Math.Abs(position.row - row) == 1;
 }
コード例 #9
0
 public IEnumerable <ChessMove> GetPossibleMoves(ChessboardPosition currentPosition)
 {
     return(AllowedMoves
            .Where(currentPosition.CanMoveBy)
            .Select(move => new ChessMove(currentPosition, currentPosition.MovedBy(move))));
 }
コード例 #10
0
 public void ShowMovableRange()
 {
     var attribute = UnitOnCell.UnitAttribute;
     for (int x = Math.Max(0, Position.x - attribute.motility);
         x <= Math.Min(BattleConsts.MapMaxCol - 1, Position.x + attribute.motility);
         ++x)
         for (int y = Math.Max(0, Position.y - attribute.motility);
             y <= Math.Min(BattleConsts.MapMaxRow - 1, Position.y + attribute.motility);
             ++y)
         {
             var itPosition = new ChessboardPosition(x, y);
             int distance = Position.Distance(itPosition);
             if (distance <= attribute.motility)
                 Chessboard.GetCell(itPosition).SetBackgroundColor(MovableColor);
         }
 }
コード例 #11
0
 public void ShowAttackableRange()
 {
     var attribute = UnitOnCell.UnitAttribute;
     for (int x = Math.Max(0, Position.x - attribute.maxAtkRange);
         x <= Math.Min(BattleConsts.MapMaxCol, Position.x + attribute.maxAtkRange);
         ++x)
         for (int y = Math.Max(0, Position.y - attribute.maxAtkRange);
             y <= Math.Min(BattleConsts.MapMaxRow, Position.y + attribute.maxAtkRange);
             ++y)
         {
             var itPosition = new ChessboardPosition(x, y);
             int distance = Position.Distance(itPosition);
             if (attribute.minAtkRange <= distance &&
                 distance <= attribute.maxAtkRange)
                 Chessboard.GetCell(itPosition).SetBackgroundColor(AttackableColor);
         }
 }
コード例 #12
0
 public virtual void OnChangeCell(ChessboardPosition position)
 {
 }
コード例 #13
0
    /// <summary>
    /// 根据曼哈顿距离显示范围
    /// </summary>
    /// <param name="centerRow"></param>
    /// <param name="centerCol"></param>
    /// <param name="minDis"></param>
    /// <param name="maxDis"></param>
    public static void showRangeByManhattanDis(int centerRow, int centerCol, int minDis,int maxDis)
    {
        int rowLimit = BattleConsts.MapMaxRow;
        int colLimit = BattleConsts.MapMaxCol;
        int len = rowLimit * colLimit;
        int[] rangeList = new int[len];
        for (int i=0;i< len;i++)
        {
            rangeList[i] = 0;
        }

        ChessboardPosition center = new ChessboardPosition(centerCol, centerRow);
        for (int col = 0; col < colLimit; ++col)
        {
            for (int row = 0; row < rowLimit; ++row)
            {
                int distance = center.Distance(new ChessboardPosition(col, row));
                if (minDis <= distance && distance <= maxDis)
                    rangeList[row*colLimit + col] = 1;
            }
        }

        showRangeByRangeList(rangeList);
    }
コード例 #14
0
ファイル: ChessMove.cs プロジェクト: klenkiew/learn-chess
 public ChessMove(ChessboardPosition from, ChessboardPosition to)
 {
     From = from;
     To   = to;
 }
コード例 #15
0
 /// <summary>
 /// 计算两个位置的距离
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public int Distance(ChessboardPosition position)
 {
     return Math.Abs(x - position.x) + Math.Abs(y - position.y);
 }
コード例 #16
0
    // todo : 弃用
    public Unit(int unitID, ChessboardPosition targetPosition)
    {
        this._curCell = Chessboard.GetCell(targetPosition);

        Skill_1 = null;
        Skill_2 = null;
        Skill_3 = null;

        switch (unitID)
        {
            case 1:
                Skill_1 = new Skill_1_1(this);
                Skill_2 = new Skill_1_2(this);
                break;
        }

        // Test
        this._sysId = "Unit_0001_01";
        this._cfg = UnitManager.getInatance().getUnitCfgBySysId(sysId);
        UnitAttribute = new CardAttribute();
        this._curHp = UnitAttribute.hp;
        this._maxHp = UnitAttribute.hp;
        //
        this.createUnitPrefab();
        Chessboard.addChildOnLayer(this._unitGo, BattleConsts.BattleFieldLayer_Unit, targetPosition.y, targetPosition.x);
        //unitSprite = new UnitUI(this, targetPosition);
        this._id = IDProvider.getInstance().applyUnitId(this);
        UnitManager.getInatance().registerUnit(this);
        this._buffList = new List<BuffDataDriven>();
        InterpreterManager.getInstance().registerLightUserData(this);
        this.setUpdateViewFlag(true);
        // 生成技能
        // test
        if ( a == 0 )
        {
            InterpreterManager.getInstance().initSkill("skill1", this);
            a = 1;
        }
        this.initAttributes();
    }
コード例 #17
0
ファイル: CGame.cs プロジェクト: jie65535/ChineseChess
 private void DrawChessman(Graphics g, Chessman chessman, ChessboardPosition pos)
 {
     DrawImageByCentre(g, _ResHelper.GetChessmanBitmap(chessman.Type, chessman.Camp), GetChessboardGridPoint(pos));
 }
コード例 #18
0
 /// <summary>
 /// 得到x,y坐标表示的cell
 /// </summary>
 /// <param name="position">左下角为(0, 0)</param>
 /// <returns></returns>
 public static Cell GetCell(ChessboardPosition position)
 {
     try
     {
         return cellArray[position.x, position.y];
     }
     catch (Exception)
     {
         return null;
     }
 }
コード例 #19
0
 public Chessman(ChessType type, ChessCamp camp, ChessboardPosition position)
 {
     Type     = type;
     Camp     = camp;
     Position = position;
 }
コード例 #20
0
 /// <summary>
 /// 记录selected cell的移动路径
 /// </summary>
 /// <param name="targetPosition"></param>
 public static void RecordMovePath(ChessboardPosition targetPosition)
 {
     Debug.Log("Record");
     int index;
     if (!RecordingMovePath)
     {
         //当移到初始点时开始记录移动路径
         if (SelectedCell.Position.Distance(targetPosition) == 0)
         {
             GetCell(targetPosition).SetBackgroundColor(Cell.HighLightMovableColor);
             RecordingMovePath = true;
         }
     }
     else
     {
         if (GetCell(targetPosition).UnitOnCell != null) return;              //格子上已有单位
         index = ListMovePath.IndexOf(targetPosition);
         if (ListMovePath.Count >= SelectedCell.UnitOnCell.UnitAttribute.motility && index == -1) return;            //超过单位的机动
         if (ListMovePath.Count == 0)
         {
             //应与初始点相邻
             if (SelectedCell.Position.Adjacent(targetPosition))
             {
                 GetCell(targetPosition).SetBackgroundColor(Cell.HighLightMovableColor);
                 ListMovePath.Add(targetPosition);
             }
             else {
                 return;
             }
         }
         else if (index == -1 && ListMovePath[ListMovePath.Count - 1].Adjacent(targetPosition))
         {
             //应与上一个选择的点相邻
             Chessboard.GetCell(targetPosition).SetBackgroundColor(Cell.HighLightMovableColor);
             ListMovePath.Add(targetPosition);
         }
         else if ((index = ListMovePath.IndexOf(targetPosition)) != -1)
         {
             ChessboardPosition lastPos = ListMovePath[ListMovePath.Count - 1];
             if (lastPos.x != targetPosition.x || lastPos.y != targetPosition.y)
             {
                 for (int i = index + 1; i < ListMovePath.Count;)
                 {
                     lastPos = ListMovePath[i];
                     ListMovePath.RemoveAt(index);
                     Chessboard.GetCell(lastPos).SetBackgroundColor(Cell.MovableColor);
                 }
             }
         }
     }
 }
コード例 #21
0
 /// <summary>
 /// 计算两个位置的距离
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public int Distance(ChessboardPosition position)
 {
     return Math.Abs(col - position.col) + Math.Abs(row - position.row);
 }
コード例 #22
0
 public IEnumerable <ChessMove> GetPossibleMoves(ChessboardPosition currentPosition)
 {
     return(components.SelectMany(moveType => moveType.GetPossibleMoves(currentPosition)).Distinct());
 }