Exemplo n.º 1
0
        public GridPosition FindGridPosition(IBallController ballInGrid, BallMagnitude magnitude, float angleOfImpact)
        {
            int offsetX = 0;
            int offsetY = 0;

            var magnitudeScale = magnitude.GetScale();

            if (angleOfImpact >= NORTH_EAST && angleOfImpact < SOUTH_EAST)
            {
                // Right side
                offsetX = (int)(1 * magnitudeScale);
            }
            else if (angleOfImpact >= SOUTH_EAST && angleOfImpact < SOUTH_WEST)
            {
                // Bottom side
                offsetY = (int)(1 * magnitudeScale);
            }
            else if (angleOfImpact >= SOUTH_WEST && angleOfImpact < NORTH_WEST)
            {
                // Left side
                offsetX = -1;
            }
            var gridPosition = ballInGrid.GridPosition;

            return(new GridPosition(gridPosition.X + offsetX, gridPosition.Y + offsetY));
        }
Exemplo n.º 2
0
        public void StickBallToCeiling(IBallController incomingBall)
        {
            var gridPosition = _ballFactory.GetGridPositionFromWorldPosition(incomingBall.Position);

            Debug.Log("Sticking ball to ceiling at : " + incomingBall.Position + " -> " + gridPosition);
            _ballGrid.Append(incomingBall, gridPosition);
        }
Exemplo n.º 3
0
 public void Append(IBallController newBall, GridPosition gridPosition)
 {
     AddBallToGrid(newBall, gridPosition);
     HandleMatches(gridPosition);
     HandleOrphanedBalls();
     CheckForWin();
 }
Exemplo n.º 4
0
 public PlayerScoredBallState(IBallController ballController, PlayerIndex playerIndex, IGameManager gameManager)
 {
     _ballController = ballController;
     _playerIndex = playerIndex;
     _gameManager = gameManager;
     GameScore = gameManager["GameScore"] as GameScore;
 }
Exemplo n.º 5
0
        private void AddBallToGrid(IBallController newBall, GridPosition gridPosition)
        {
            if (!_ballArray.IsValidPosition(gridPosition))
            {
                Logging.Instance.Log(LogLevel.Warning,
                                     string.Format("Attempted to add at invalid grid position: {0}", gridPosition.ToString()));
            }
            if (_ballArray[gridPosition.X, gridPosition.Y] != null)
            {
                Logging.Instance.Log(LogLevel.Warning,
                                     string.Format("Overlapping at position: {0}", gridPosition.ToString()));
            }

            _ballPositionHandler.AppendAt(_ballArray, newBall, gridPosition);
            newBall.MarkDirty();
            _activeBalls.Add(newBall);

            Logging.Instance.Log(LogLevel.Debug,
                                 string.Format("Appending to grid : {0},{1} type: {2}", gridPosition.X, gridPosition.Y,
                                               newBall.BallType));

            var worldPosition = _ballFactory.GetWorldPositionFromGrid(gridPosition);

            newBall.SetActiveInGrid(gridPosition, worldPosition, _ballContainer.transform);
        }
Exemplo n.º 6
0
    public GameModel
        (IPlayer player,
        IBallController ballController,
        IInputController input,
        ILevelConfiguration levelConfiguration,
        IControllerConfig controllerConfig,
        IGameCicle gameCicle,
        IBonusManager bonusManager,
        IFactory <Vector3, IBlock> blockFactory,
        IScoreController scoreController,
        ILifeController lifeController)
    {
        Player             = player;
        BallController     = ballController;
        Input              = input;
        LevelConfiguration = levelConfiguration;
        ControllerConfig   = controllerConfig;
        GameCicle          = gameCicle;
        BonusManager       = bonusManager;
        BlockFactory       = blockFactory;
        ScoreController    = scoreController;
        LifeController     = lifeController;

        SetListeners(true);

        GoToStart();
    }
Exemplo n.º 7
0
        private GridPosition GetGridPosition(IBallController ballController, float yOffset)
        {
            var position     = ballController.gameObject.transform.localPosition;
            int x            = (int)Math.Round(position.x);
            int y            = (int)Math.Round(Math.Abs(position.y - yOffset));
            var gridPosition = new GridPosition(x, y);

            Debug.Log(position + " => " + gridPosition);
            return(gridPosition);
        }
Exemplo n.º 8
0
 private void AddExtraPositionsForHugeMagnitude(IBallController[,] ballArray, IBallController newBall,
                                                GridPosition gridPosition)
 {
     ballArray[gridPosition.X + 3, gridPosition.Y]     = newBall;
     ballArray[gridPosition.X + 3, gridPosition.Y + 1] = newBall;
     ballArray[gridPosition.X + 3, gridPosition.Y + 2] = newBall;
     ballArray[gridPosition.X + 3, gridPosition.Y + 3] = newBall;
     ballArray[gridPosition.X + 2, gridPosition.Y + 3] = newBall;
     ballArray[gridPosition.X + 1, gridPosition.Y + 3] = newBall;
     ballArray[gridPosition.X + 1, gridPosition.Y + 3] = newBall;
 }
        public void TestBallsInA_L_AreNotOrphaned()
        {
            var ballControllers = new IBallController[5, 5];

            ballControllers[2, 0] = MakeBall();
            ballControllers[2, 1] = MakeBall();
            ballControllers[1, 1] = MakeBall();
            ballControllers[1, 2] = MakeBall();

            var orphanedBalls = _orphanedBallFinder.Find(ballControllers);

            Assert.AreEqual(0, orphanedBalls.Count);
        }
        private static IBallController[,] CreateGridFilledWithType(BallType type, int gridSize)
        {
            var gridFilledWithType = new IBallController[gridSize, gridSize];

            for (int x = 0; x < gridFilledWithType.GetLength(0); x++)
            {
                for (int y = 0; y < gridFilledWithType.GetLength(1); y++)
                {
                    gridFilledWithType[x, y] = CreateSubstitueBall(type, x, y);
                }
            }
            return(gridFilledWithType);
        }
 public override bool ActivateEffect(IBallController ball)
 {
     if (ball.GetObjectiveType() == tileModel.GetObjectiveType() && !effectActivated)
     {
         ActivateEffect(true);
         return(true);
     }
     else if (effectActivated && ball.GetObjectiveType() != tileModel.GetObjectiveType())
     {
         ActivateEffect(false);
         return(true);
     }
     return(false);
 }
        public void TestBallsOnCeiling_AreNotOrphaned()
        {
            var ballControllers = new IBallController[5, 5];

            ballControllers[0, 0] = MakeBall();
            ballControllers[1, 0] = MakeBall();
            ballControllers[2, 0] = MakeBall();
            ballControllers[3, 0] = MakeBall();
            ballControllers[4, 0] = MakeBall();

            var orphanedBalls = _orphanedBallFinder.Find(ballControllers);

            Assert.AreEqual(0, orphanedBalls.Count);
        }
        public void TestEmptyGrid_OnlyMatchesTarget()
        {
            var matchedBallSetFinder = new MatchedBallSetFinder();
            var ballControllers      = new IBallController[5, 5];

            var targetPosition = new GridPosition(0, 0);
            var ball1          = CreateSubstitueBall(BallType.Red, 0, 0);

            ballControllers[0, 0] = ball1;

            var matches = matchedBallSetFinder.FindPath(targetPosition, ballControllers);

            Assert.AreEqual(1, matches.Count);
            Assert.AreSame(ball1, matches[0]);
        }
        public void TestBallsDiagonal_AreOrphaned()
        {
            var ballControllers = new IBallController[5, 5];

            ballControllers[3, 0] = MakeBall();
            ballControllers[2, 1] = MakeBall();
            ballControllers[3, 2] = MakeBall();
            ballControllers[4, 3] = MakeBall();

            var orphanedBalls = _orphanedBallFinder.Find(ballControllers);

            Assert.AreEqual(3, orphanedBalls.Count);
            Assert.Contains(new GridPosition(2, 1), orphanedBalls);
            Assert.Contains(new GridPosition(3, 2), orphanedBalls);
            Assert.Contains(new GridPosition(4, 3), orphanedBalls);
        }
Exemplo n.º 15
0
 private bool AddActivations()
 {
     for (int x = 0; x < model.Width; x++)
     {
         for (int y = 0; y < model.Height; y++)
         {
             IBallController ball = model.GetBrick(x, y);
             TileController  tile = model.GetTile(x, y);
             if (tile.HasEffect())
             {
                 EffectActivationCommand command = new EffectActivationCommand(ball, tile);
                 PrepareEffectActivation(command);
             }
         }
     }
     return(effectActivationCommands.Count > 0);
 }
Exemplo n.º 16
0
 private bool AddObjectivesToFill()
 {
     for (int x = 0; x < model.Width; x++)
     {
         for (int y = 0; y < model.Height; y++)
         {
             IBallController ball = model.GetBrick(x, y);
             TileController  tile = model.GetTile(x, y);
             if (ball.GetObjectiveType() != ObjectiveType.NONE && ball.GetObjectiveType() == tile.GetObjectiveType())
             {
                 BallFillObjectiveCommand command = new BallFillObjectiveCommand(this, ball, tile);
                 PrepareBrickFillObjective(command);
             }
         }
     }
     return(objectiveCommands.Count > 0);
 }
Exemplo n.º 17
0
    private void CreateBalls(CubeModel data)
    {
        for (int x = 0; x < data.X_SIZE; x++)
        {
            for (int y = 0; y < data.Y_SIZE; y++)
            {
                for (int z = 0; z < data.Z_SIZE; z++)
                {
                    IBallController ball = BallCreator.GetBall(data.balls[x, y, z], SizeRatio, false);
                    ball.Init(x, y, z, this);



                    interior[x, y, z] = ball;
                }
            }
        }
    }
Exemplo n.º 18
0
        private void DestroyOneBall(IBallController ball, float delay)
        {
            var ballPosition = ball.Position;
            var newExplosion = _simpleObjectPool.GetObjectFromPool();

            newExplosion.transform.SetParent(transform);
            newExplosion.transform.position = ballPosition;

            var planetSprite = ball.CurrentBallSprite;

            var ballDestroyEffect = newExplosion.GetComponent <BallDestroyEffect>();

            ballDestroyEffect.RePlayEffect(delay, planetSprite, ball.HasPowerGem);
            _floatingScoreEffectGenerator.ShowScore(GameConstants.ScorePerBall, ballPosition, delay);
            if (ball.HasPowerGem)
            {
                _powerGemParticleEffectGenerator.GenerateParticles(delay, ballPosition);
            }
        }
Exemplo n.º 19
0
        protected override void Update()
        {
            var raycastHit = Physics2D.Raycast(_camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (raycastHit.collider != null)
            {
                var newController = raycastHit.transform.gameObject.GetComponent <IBallController>();
                if (newController != null)
                {
                    if (_currentController != newController)
                    {
                        _currentController = newController;
                    }
                }
            }
            if (Input.GetMouseButtonDown(1))
            {
                Debug.Log("ball at : " + _currentController.GridPosition);
            }
        }
Exemplo n.º 20
0
    public override void SetData(BoardData data)
    {
        boardData = data;
        board     = new BoardPosition[boardData.X_SIZE, boardData.Y_SIZE];
        for (int x = 0; x < boardData.X_SIZE; x++)
        {
            for (int y = 0; y < boardData.Y_SIZE; y++)
            {
                Vector3 position = GetWorldPosition(x, y);

                TileController tile = TileCreator.CreateTile(boardData.tiles[x, y], position, SizeRatio);
                tile.transform.SetParent(transform, false);

                IBallController ball = BallCreator.GetBall(boardData.balls[x, y], SizeRatio);
                ball.Init(x, y, this);

                board[x, y] = new BoardPosition(tile, ball);
            }
        }
    }
Exemplo n.º 21
0
        public void AppendAt(IBallController[,] ballArray, IBallController newBall, GridPosition gridPosition)
        {
            ballArray[gridPosition.X, gridPosition.Y] = newBall;
            var ballMagnitude = newBall.Magnitude;

            if (ballMagnitude == BallMagnitude.Medium)
            {
                AddExtraPositionsForStandardMagnitude(ballArray, newBall, gridPosition);
            }
            else if (ballMagnitude == BallMagnitude.Large)
            {
                AddExtraPositionsForStandardMagnitude(ballArray, newBall, gridPosition);
                AddExtraPositionsForLargeMagnitude(ballArray, newBall, gridPosition);
            }
            else if (ballMagnitude == BallMagnitude.Huge)
            {
                AddExtraPositionsForStandardMagnitude(ballArray, newBall, gridPosition);
                AddExtraPositionsForLargeMagnitude(ballArray, newBall, gridPosition);
                AddExtraPositionsForHugeMagnitude(ballArray, newBall, gridPosition);
            }
        }
Exemplo n.º 22
0
    public static BoardData GetBoardData(BoardPosition[,] board)
    {
        BoardData data   = new BoardData();
        int       X_SIZE = board.GetLength(0);
        int       Y_SIZE = board.GetLength(1);

        data.balls = new BallData[X_SIZE, Y_SIZE];
        data.tiles = new TileData[X_SIZE, Y_SIZE];

        for (int x = 0; x < X_SIZE; x++)
        {
            for (int y = 0; y < Y_SIZE; y++)
            {
                IBallController ball = board[x, y].ball;
                TileController  tile = board[x, y].tile;
                data.balls[x, y] = new BallData(ball.GetBallType(), ball.GetObjectiveType());
                data.tiles[x, y] = new TileData(tile.GetObjectiveType(), tile.tileType);
            }
        }
        return(data);
    }
Exemplo n.º 23
0
 public BallFillObjectiveCommand(Turn turn, IBallController ball, TileController tile)
 {
     this.ball = ball;
     this.tile = tile;
     this.turn = turn;
 }
Exemplo n.º 24
0
 public virtual bool ActivateEffect(IBallController ball)
 {
     return(false);
 }
 public BallCollisionEventArgs(IBallController incomingBall, IBallController ballInGrid, float angleOfImpact)
 {
     IncomingBall  = incomingBall;
     BallInGrid    = ballInGrid;
     AngleOfImpact = angleOfImpact;
 }
Exemplo n.º 26
0
 internal void AddBrick(IBallController brickModel, int x, int y)
 {
     board[x, y].ball = brickModel;
 }
Exemplo n.º 27
0
 public bool ActivateEffect(IBallController ball)
 {
     return(effectManager.ActivateEffect(ball));
 }
Exemplo n.º 28
0
 public StartBallState(IBallController controller, IGameManager gameManager, PlayerIndex playerIndex)
 {
     _controller = controller;
     _gameManager = gameManager;
     _playerIndex = playerIndex;
 }
Exemplo n.º 29
0
 public void StickBallToCeiling(IBallController incomingBall)
 {
     _ballGridController.StickBallToCeiling(incomingBall);
 }
Exemplo n.º 30
0
        public PlayingBallState(IBallController ballController, IGameManager gameManager)
        {
            _ballController = ballController;
            _gameManager = gameManager;

        }
Exemplo n.º 31
0
 public BallMoveCommand(IBallController ball, Direction direction)
 {
     this.ball      = ball;
     this.direction = direction;
 }
Exemplo n.º 32
0
 public EffectActivationCommand(IBallController ball, TileController tile)
 {
     this.ball = ball;
     this.tile = tile;
 }
Exemplo n.º 33
0
 internal BoardPosition(TileController tile, IBallController ball)
 {
     this.tile = tile;
     this.ball = ball;
 }