Esempio n. 1
0
        public bool CanPieceMove(PieceEntity piece, BoardMovementDirection direction)
        {
            var targetPosition = piece.Position + DirectionToOffset(direction);

            return(_board.IsPieceInBoard(piece.Piece, targetPosition) &&
                   !_board.IsPieceColliding(piece.Piece, targetPosition));
        }
Esempio n. 2
0
        private void PlacePieceInBoard(bool toGround)
        {
            if (toGround)
            {
                _board.EmbedPieceAtGround(_piece);
            }

            else
            {
                _board.EmbedPiece(_piece);
            }

            RemoveEntity(_piece);
            _piece = null;

            _createFallingPieceTimer.Restart();
            _fallInterval.Stop();

            _board.ExtractFullRows().ForEach(row =>
            {
                var dissolvingRow = new DissolvingRowEntity(_dissolvingBoardRowRenderer, row);
                AddEntity(dissolvingRow);
                _score += 5;
            });

            _board.DropRowsDown();
            _score += 1;
        }
Esempio n. 3
0
 public Piece(PieceEntity entity)
 {
     title      = entity.Title;
     p4cmlink   = entity.p4cmlink;
     artist     = entity.Artist;
     uploadDate = entity.uploadDate;
     blobName   = entity.blobName;
     owner      = entity.Owner;
 }
Esempio n. 4
0
        private void CreateFallingPiece()
        {
            _piece = new PieceEntity(_pieceRenderer, _boardRenderer, _nextPiece);
            AddEntity(_piece);

            _nextPiece = PieceTemplate.GetRandomPiece();

            _fallInterval.Start();
        }
Esempio n. 5
0
    public override void SetData(Vector2Int squareIndex, Vector2Int previousSquareIndex, PieceType pieceType, TeamColor teamColor, bool movedFirstTime,
                                 IMovable movementType, PieceEntity pieceEntity)
    {
        base.SetData(squareIndex, previousSquareIndex, pieceType, teamColor, movedFirstTime, movementType, pieceEntity);

        if (TeamColor == TeamColor.Black)
        {
            InverseDirectionOfMoves();
        }
    }
Esempio n. 6
0
        public Piece savePiece(Piece piece)
        {
            piece.uploadDate = DateTime.Now;
            PieceEntity    entity    = EntityMediator.getTableEntity(piece);
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(piece.title);

            blockBlob.UploadTextAsync(JsonConvert.SerializeObject(piece));
            TableOperation insertOperation = TableOperation.InsertOrReplace(entity);

            t_reference.Execute(insertOperation);
            return(piece);
        }
Esempio n. 7
0
    public static void CreatePiecePrefabAndInitialize(Vector2Int squareIndex, PieceType pieceType, TeamColor teamColor,
                                                      ChessGridInfo grid, ChessPlayer player)
    {
        Piece       newPiece = CreateChessPiece(squareIndex, pieceType, grid, player);
        PieceEntity entity   = PieceFactory.CreatePiecePrefab(pieceType.ToString()).GetComponent <PieceEntity>();

        IMovable pieceMovementType = PieceFactory.GetMovementType(pieceType.ToString()) == MovementType.MovesInLine ?
                                     new MoveInLine() as IMovable : new Jump();

        newPiece.SetData(squareIndex, squareIndex, pieceType, teamColor, false, pieceMovementType, entity);
        player.AddPiece(newPiece);
    }
Esempio n. 8
0
 public virtual void SetData(Vector2Int squareIndex, Vector2Int previousSquareIndex, PieceType pieceType, TeamColor teamColor, bool movedFirstTime,
                             IMovable movementType, PieceEntity pieceEntity)
 {
     SquareIndex         = squareIndex;
     PreviousSquareIndex = previousSquareIndex;
     PieceType           = pieceType;
     TeamColor           = teamColor;
     Movement            = movementType;
     entity = pieceEntity;
     entity?.InitializeEntity(Board.CalculateBoardPositionFromSquareIndex(SquareIndex), TeamColor);
     MovedFirstTime = movedFirstTime;
     AvailableMoves = new List <Move>();
     States         = new List <PieceState>();
 }
Esempio n. 9
0
        public override void Enter()
        {
            _board = new BoardEntity(_boardRenderer);
            AddEntity(_board);

            _piece = new PieceEntity(_pieceRenderer, _boardRenderer, PieceTemplate.GetRandomPiece());
            AddEntity(_piece);

            _nextPiece = PieceTemplate.GetRandomPiece();

            _fallInterval.Start();

            InputManager.Instance.BindAction(Keys.Left, MovePieceLeft);
            InputManager.Instance.BindAction(Keys.Right, MovePieceRight);
            InputManager.Instance.BindAction(Keys.Down, MovePieceGround);
            InputManager.Instance.BindAction(Keys.Space, RotatePiece);
        }
Esempio n. 10
0
    public void CreateRandomBoardLayout()
    {
        System.Random random          = new System.Random();
        int           numberOfSquares = ChessGridInfo.GRID_SIZE * ChessGridInfo.GRID_SIZE - 1;

        for (int i = 0; i < boardLayout.GetNumberOfPieces(); i++)
        {
            PieceType pieceType = boardLayout.GetChessPieceType(i);
            TeamColor teamColor = boardLayout.GetChessPieceTeamColor(i);

            int         index = random.Next(0, numberOfSquares);
            PieceEntity other = pieceEntities.SingleOrDefault(x =>
                                                              Board.CalculateSquareIndexFromBoardPosition(x.gameObject.transform.position) == squares[index]);
            pieceEntities.Remove(other);
            other?.Die();

            PieceEntity piece = ChessGameController.PieceFactory.CreatePiecePrefab(pieceType.ToString()).GetComponent <PieceEntity>();
            pieceEntities.Add(piece);
            piece.InitializeEntity(Board.CalculateBoardPositionFromSquareIndex(squares[index]), teamColor);
        }
    }
Esempio n. 11
0
 public Point GetGroundPosition(PieceEntity piece)
 {
     return(_board.GetGroundPosition(piece.Piece, piece.Position));
 }