Exemplo n.º 1
0
    private void CreateSelect(PiecePoint point)
    {
        var selectObj = Instantiate(selectPrefab, selectBox.transform);
        var select    = selectObj.transform.GetComponent <Mark>();

        select.InitPiecePoint(point);
    }
Exemplo n.º 2
0
 public void OnClick(PiecePoint point)
 {
     if (point != null && CurrentColor == MyColor)
     {
         point = MyColor == PieceColor.Red ? point : point.SymmetryPoint;
         if (selectPiece != null && SelectPoints.Contains(point))
         {
             var record = pieceBoard.GetChessRecord(selectPiece, point);
             MovePieceTest(record);
         }
         else
         {
             var piece = pieceBoard.GetPieceOnBoard(point);
             if (piece != null && piece.PieceInfo.PieceColor == CurrentColor)
             {
                 selecter.Select(piece);
                 PlaySound("capture");
                 return;
             }
             else if (selectPiece != null)
             {
                 PlaySound("uncapture");
             }
         }
     }
     else if (selectPiece != null)
     {
         PlaySound("uncapture");
     }
     selecter.UnSelect();
 }
Exemplo n.º 3
0
    public void UpdateVisibleArea()
    {
        var backgroundTexture = new Texture2D(Width, Height);
        var maskTexture       = new Texture2D(Width, Height);

        for (var i = 0; i < Width; i++)
        {
            for (var j = 0; j < Height; j++)
            {
                var point = new PiecePoint(i, j);
                if (visiblePoints.Contains(point))
                {
                    backgroundTexture.SetPixel(i, j, Trans);
                    maskTexture.SetPixel(i, j, Gray);
                }
                else
                {
                    backgroundTexture.SetPixel(i, j, Gray);
                    maskTexture.SetPixel(i, j, Trans);
                }
            }
        }
        backgroundTexture.filterMode = FilterMode.Bilinear;
        boardBackground.texture      = backgroundTexture;
        backgroundTexture.Apply();
        maskTexture.filterMode = FilterMode.Point;
        boardMask.texture      = maskTexture;
        maskTexture.Apply();
    }
Exemplo n.º 4
0
 private void DestroyPiece(PiecePoint point)
 {
     if (pieces.ContainsKey(point))
     {
         Destroy(pieces[point].gameObject);
     }
 }
Exemplo n.º 5
0
    private void CreateRecord(PiecePoint point)
    {
        var recordObj = Instantiate(recordPrefab, recordBox.transform);
        var record    = recordObj.transform.GetComponent <Mark>();

        record.InitPiecePoint(point);
    }
Exemplo n.º 6
0
 public Piece GetPieceOnBoard(PiecePoint point)
 {
     if (pieces.ContainsKey(point))
     {
         return(pieces[point]);
     }
     return(null);
 }
Exemplo n.º 7
0
    private ChessRecord DecodeRecord(string[] messages)
    {
        if (messages[0] != "move")
        {
            return(null);
        }
        var sourcePoint = new PiecePoint(int.Parse(messages[1]), int.Parse(messages[2]));
        var index       = int.Parse(messages[3]);
        var selectPiece = pieceBoard.GetPieceOnBoard(sourcePoint).AllBasePieces[index];
        var targetPoint = new PiecePoint(int.Parse(messages[4]), int.Parse(messages[5]));
        var record      = pieceBoard.GetChessRecord(selectPiece, targetPoint);

        return(record);
    }
Exemplo n.º 8
0
 private void UpdateSelects(PiecePoint piecePoint = null, HashSet <PiecePoint> selectPoints = null)
 {
     DestroySelects();
     if (piecePoint != null)
     {
         CreateSelect(piecePoint);
     }
     if (selectFlag && selectPoints != null)
     {
         foreach (var point in selectPoints)
         {
             CreateSelect(point);
         }
     }
 }
Exemplo n.º 9
0
 private void UpdateBoard()
 {
     DestroyPieces();
     for (var x = 0; x < GameParams.BoardWidth; x++)
     {
         for (var y = 0; y < GameParams.BoardHeight; y++)
         {
             var point = new PiecePoint(x, y);
             var info  = board.GetPieceInfo(point);
             if (!info.IsBlank())
             {
                 var piece = CreatePiece(point, info);
                 pieces[point] = piece;
             }
         }
     }
 }
Exemplo n.º 10
0
 private void OnClick(PiecePoint point)
 {
     GameController.Instance.OnClick(point);
 }
Exemplo n.º 11
0
 public void Select(PiecePoint piecePoint, HashSet <PiecePoint> selectPoints)
 {
     UpdateSelects(piecePoint, selectPoints);
 }
Exemplo n.º 12
0
    public void InitChessPiece(PiecePoint point, PieceInfo info)
    {
        var piece = new ChessPiece(point, info);

        InitChessPiece(piece);
    }
Exemplo n.º 13
0
 public ChessRecord GetChessRecord(ChessPiece selectPiece, PiecePoint targetPoint)
 {
     return(board.GetChessRecord(selectPiece, targetPoint));
 }
Exemplo n.º 14
0
 private Piece CreatePiece(PiecePoint point, PieceInfo info)
 {
     return(CreatePiece(new ChessPiece(point, info)));
 }
Exemplo n.º 15
0
 public void InitPiecePoint(PiecePoint point)
 {
     PiecePoint = point;
 }
Exemplo n.º 16
0
 public bool IsPointInArea(PiecePoint point)
 {
     return(point.X >= MinX && point.X <= MaxX && point.Y >= MinY && point.Y <= MaxY);
 }