Exemple #1
0
        /// <summary>
        /// Spawns all Pieces for a ChessTeam
        /// </summary>
        /// <param name="mgr">EntityManager used for spawning</param>
        /// <param name="team">Team to spawn for</param>
        private static void SpawnChessTeam(EntityManager mgr, ChessTeam team)
        {
            quaternion rotation = team.Equals(ChessTeam.White) ? Quaternion.identity : Quaternion.Euler(0, 180, 0);
            int        y        = 0;
            int        z        = team.Equals(ChessTeam.White) ? 0 : 7;

            // 1 King
            SpawnChessPiece(mgr, team, ChessPiece.King, new float3(4, y, z), rotation);
            // 1 Queen
            SpawnChessPiece(mgr, team, ChessPiece.Queen, new float3(3, y, z), rotation);
            // 2 Rooks
            SpawnChessPiece(mgr, team, ChessPiece.Rook, new float3(0, y, z), rotation);
            SpawnChessPiece(mgr, team, ChessPiece.Rook, new float3(7, y, z), rotation);
            // 2 Bishops
            SpawnChessPiece(mgr, team, ChessPiece.Bishop, new float3(2, y, z), rotation);
            SpawnChessPiece(mgr, team, ChessPiece.Bishop, new float3(5, y, z), rotation);
            // 2 Knights
            SpawnChessPiece(mgr, team, ChessPiece.Knight, new float3(1, y, z), rotation);
            SpawnChessPiece(mgr, team, ChessPiece.Knight, new float3(6, y, z), rotation);
            // 8 Pawns
            z = team.Equals(ChessTeam.White) ? 1 : 6;
            for (int i = 0; i < 8; i++)
            {
                SpawnChessPiece(mgr, team, ChessPiece.Pawn, new float3(i, y, z), rotation);
            }
        }
Exemple #2
0
 public GameParams(ChessTeam localTeam, bool showMovePreviews, float timerDuration = 0, bool showClock = false)
 {
     this.localTeam        = localTeam;
     this.showMovePreviews = showMovePreviews;
     this.timerDuration    = timerDuration;
     this.showClock        = timerDuration > 0 ? false : showClock;
 }
Exemple #3
0
        /// <summary>
        /// Spawns a Chess-Piece
        /// </summary>
        /// <param name="mgr">EntityManager</param>
        /// <param name="team">Team for Piece</param>
        /// <param name="piece">Type of Piece to Spawn</param>
        /// <param name="position">Position for Piece</param>
        /// <param name="rotation">Rotation for Piece</param>
        /// <returns>Spawned Entity</returns>
        private static Entity SpawnChessPiece(EntityManager mgr, ChessTeam team, ChessPiece piece, float3 position, quaternion rotation)
        {
            Entity pieceEntity = mgr.CreateEntity(pieceArchetype);

            mgr.SetComponentData(pieceEntity, new Translation {
                Value = position
            });
            mgr.SetComponentData(pieceEntity, new Rotation {
                Value = rotation
            });
            mgr.SetComponentData(pieceEntity, new Scale {
                Value = 1.5f
            });
            mgr.SetComponentData(pieceEntity, new Team(team));
            mgr.SetComponentData(pieceEntity, new Piece(piece));
            RenderMesh renderInfo = new RenderMesh
            {
                castShadows    = ShadowCastingMode.On,
                receiveShadows = true,
                mesh           = PieceMeshes[piece]
            };

            renderInfo.material = TeamMaterials[team]; // Set Material (Color) for Team
            mgr.SetSharedComponentData(pieceEntity, renderInfo);
#if UNITY_EDITOR
            mgr.SetName(pieceEntity, string.Format("{0}_{1}", piece.ToString(), team.ToString())); // Set name to be shown in EntityDebugger
#endif
            return(pieceEntity);
        }
Exemple #4
0
    void Construct(ChessTeam team, GridIndex gridIndex, ChessBoard board)
    {
        this.board = board;
        var mesh = AssetDatabase.LoadAssetAtPath <Mesh>("Assets/Free Low Poly Chess Set/Pawn/Mesh/pawn.fbx");

        base.Construct(mesh, team, gridIndex, board);
    }
Exemple #5
0
    public ActionManager(ChessBoard board)
    {
        this.board = board;

        buildedData.Rebuild(board);
        actionTeam  = ChessTeam.White;
        actionState = new UnselectedState(this);
    }
 public static ChessTeam Invert(this ChessTeam @this)
 {
     if (@this == ChessTeam.Black)
     {
         return(ChessTeam.White);
     }
     else
     {
         return(ChessTeam.Black);
     }
 }
Exemple #7
0
 public bool IsChecked(ChessTeam team)
 {
     if (checkedTeam.HasValue)
     {
         return(checkedTeam.Value == team || doubleCheck);
     }
     else
     {
         return(false);
     }
 }
Exemple #8
0
 void SwitchActionTeam()
 {
     if (actionTeam == ChessTeam.White)
     {
         actionTeam = ChessTeam.Black;
     }
     else
     {
         actionTeam = ChessTeam.White;
     }
 }
Exemple #9
0
 public void CanAttack(ChessTeam team, bool bCan = true)
 {
     if (bCan)
     {
         underAttack |= GetMask(team);
     }
     else
     {
         underAttack &= ~GetMask(team);
     }
 }
Exemple #10
0
    protected void Construct(Mesh mesh, ChessTeam team, GridIndex myIndex, ChessBoard board)
    {
        base.Construct();

        this.mesh  = mesh;
        this.team  = team;
        this.board = board;

        this.myIndex = myIndex;
        var loc = board.QueryLocation(myIndex);

        gameObject.transform.localPosition = loc;
    }
Exemple #11
0
    /// <summary>
    /// 设置棋子信息
    /// </summary>
    /// <param name="teamInfo"></param>
    public void SetChessInfo(ChessTeam teamInfo)
    {
        TeamInfo = teamInfo;
        ChessId  = teamInfo.id;
        team     = teamInfo.teamType == 0 ? Team.BlueTeam : Team.RedTeam;

        HeroInfo   = ConfigMgr.Ins.ConfigChessHeroInfo.Find(hero => hero.id == teamInfo.heroId);
        hpMaxValue = HeroInfo.hpMaxValue;
        chessHp    = hpMaxValue;
        chessAtk   = HeroInfo.atk;

        SetTeamColor();
    }
Exemple #12
0
    public T SpawnActor <T>(GridIndex gridIndex, ChessTeam team) where T : Pieces
    {
        var go = Object.Instantiate(Empty);

        go.name = typeof(T).Name;

        var component = go.AddActorComponent <T>(team, gridIndex, board);

        board[gridIndex] = component;

        go.transform.SetParent(board.transform, false);

        return(component);
    }
Exemple #13
0
 public Bishop(ChessTeam team) : base(team)
 {
     Type = PieceType.Bishop;
     if (allowedMotionVectors.Count == 0)
     {
         for (int move = 1; move < ChessBoard.Size; move++)                  //1 to 7 squares in a given direction
         {
             allowedMotionVectors.Add(new Vector2D(move, move));
             allowedMotionVectors.Add(new Vector2D(move, -move));
             allowedMotionVectors.Add(new Vector2D(-move, move));
             allowedMotionVectors.Add(new Vector2D(-move, -move));
         }
     }
 }
Exemple #14
0
    uint GetMask(ChessTeam team)
    {
        switch (team)
        {
        case ChessTeam.Black:
            return(0x1);

        case ChessTeam.White:
            return(0x2);

        default:
            return(0);
        }
    }
Exemple #15
0
    void AttackMask(GridIndex index, ChessTeam team, ChessBoard board)
    {
        this[index].CanAttack(team);

        if (board[index] is King)
        {
            if (checkedTeam.HasValue)
            {
                doubleCheck = true;
            }
            else
            {
                checkedTeam = board[index].Team;
            }
        }
    }
        public DirectionalChessPiece(ChessTeam team) : base(team)
        {
            switch (team)
            {
            case ChessTeam.White:
                ForwardDirection = WhiteForwardDirection;
                break;

            case ChessTeam.Black:
                ForwardDirection = BlackForwardDirection;
                break;

            default:
                // Default is impossible
                break;
            }
        }
Exemple #17
0
        //gets the path of movement for a captured piece from the board to the trough
        //expects points to be in 23x17 form
        private List <Point2D> getCapturedPath(Point2D start)        //change capturedTeam type
        {
            Point2D   startPoint  = pointConversion(start);
            ChessTeam team        = board.PieceAt(start).Team;
            int       numCaptured = board.NumCapturedPieces(team);

            List <Point2D> path = new List <Point2D>();

            if (team == ChessTeam.White)
            {
                path = getCapturedPathWithTeam(startPoint, whiteRemovalDir, whiteEmptyCol, whiteCapturedCol, whiteCapturedStart + whiteCapturedAddDir * numCaptured);
            }
            else    //team == ChessTeam.Black
            {
                path = getCapturedPathWithTeam(startPoint, blackRemovalDir, blackEmptyCol, blackCapturedCol, blackCapturedStart + blackCapturedAddDir * numCaptured);
            }
            return(path);
        }
Exemple #18
0
        // Checks if the specified location is in check for the specified team
        public bool inCheck(Point2D checkPoint, ChessTeam Turn)
        {
            int i, j;

            for (i = 0; i < ChessBoard.Size; i++)
            {
                for (j = 0; j < ChessBoard.Size; j++)
                {
                    var piece = board.PieceAt(i, j);
                    if (piece != null && piece.Team != Turn)
                    {
                        if (IsCheckMoveValid(new Point2D(i, j), checkPoint))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);              //TODO: remove this
        }
Exemple #19
0
 public Queen(ChessTeam team) : base(team)
 {
     Type = PieceType.Queen;
     if (allowedMotionVectors.Count == 0)
     {
         for (int move = 1; move < ChessBoard.Size; move++)                      //1 to 7 squares in a given direction
         {
             // Bishop moves
             allowedMotionVectors.Add(new Vector2D(move, move));
             allowedMotionVectors.Add(new Vector2D(move, -move));
             allowedMotionVectors.Add(new Vector2D(-move, move));
             allowedMotionVectors.Add(new Vector2D(-move, -move));
             // Rook moves
             allowedMotionVectors.Add(new Vector2D(move, 0));
             allowedMotionVectors.Add(new Vector2D(-move, 0));
             allowedMotionVectors.Add(new Vector2D(0, move));
             allowedMotionVectors.Add(new Vector2D(0, -move));
         }
     }
 }
Exemple #20
0
    void Construct(ChessTeam team, GridIndex gridIndex, ChessBoard board)
    {
        var mesh = AssetDatabase.LoadAssetAtPath <Mesh>("Assets/Free Low Poly Chess Set/Knight/Mesh/knight.fbx");

        base.Construct(mesh, team, gridIndex, board);
    }
Exemple #21
0
 /// <summary>
 /// Creates a Team
 /// </summary>
 /// <param name="team">Value for Team</param>
 public Team(ChessTeam team)
 {
     Value = team;
 }
Exemple #22
0
 public bool IsUnderAttack(ChessTeam team)
 {
     return((underAttack & GetMask(team)) != 0);
 }
Exemple #23
0
 public T SpawnActor <T>(int x, int y, ChessTeam team) where T : Pieces => SpawnActor <T>(new GridIndex(x, y), team);
Exemple #24
0
 public ChessPiece(ChessTeam team)
 {
     Team     = team;
     HasMoved = false;
     CanJump  = false;
 }
Exemple #25
0
 public Pawn(ChessTeam team) : base(team)
 {
     Type = PieceType.Pawn;
 }
Exemple #26
0
 public Knight(ChessTeam team) : base(team)
 {
     Type    = PieceType.Knight;
     CanJump = true;
 }
Exemple #27
0
 public bool IsUnderAttack(GridIndex index, ChessTeam team)
 {
     return(this[index].IsUnderAttack(team));
 }
Exemple #28
0
 //access the number of captured pieces on a team
 public int NumCapturedPieces(ChessTeam team)
 {
     return(capturedPiecesByTeam[team].Count);
 }
Exemple #29
0
 public King(ChessTeam team) : base(team)
 {
     Type = PieceType.King;
 }