Esempio n. 1
0
        public List <Point> GetPositionsOrDefault(CellGrid grid)
        {
            Debug.Assert(grid != null, "Cannot activate BombBlock on a null CellGrid.");

            var activatedPoint  = GridQuery.ToPoint(grid, this);
            var activationQueue = new Queue <Point>();
            var choppingBlock   = new List <Point>();

            activationQueue.Enqueue(activatedPoint);

            while (activationQueue.Count > 0)
            {
                var processing = activationQueue.Dequeue();

                if (!choppingBlock.Contains(processing))
                {
                    var surrounding = GridQuery.GetSurrounding(grid, processing, true);

                    var surroundingBombs =
                        from point in surrounding
                        where grid.Columns[point.x][point.y].Type == BlockType.Bomb
                        select point;

                    var surroundingOthers =
                        from point in surrounding
                        where grid.Columns[point.x][point.y].Type != BlockType.Bomb
                        select point;

                    foreach (var point in surroundingBombs)
                    {
                        activationQueue.Enqueue(point);
                    }

                    foreach (var point in surroundingOthers)
                    {
                        if (!choppingBlock.Contains(point))
                        {
                            choppingBlock.Add(point);
                        }
                    }

                    choppingBlock.Add(processing);
                }
            }
            var soundManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <SoundManager>();

            Debug.Assert(soundManager != null, "Could not locate SoundManager");
            soundManager.PlaySound(this.Type);

            return(choppingBlock);
        }
Esempio n. 2
0
        private void Update()
        {
            if (scoreManager.ObjectiveCount <= 0)
            {
                SceneManager.LoadScene("GameWon", LoadSceneMode.Single);
            }
            else if (scoreManager.Moves <= 0)
            {
                SceneManager.LoadScene("GameOver", LoadSceneMode.Single);
            }

            var interaction = controls.GetInteraction();

            if (interaction != null && cellGrid.Events.Count == 0)
            {
                var point     = GridQuery.ToPoint(this.visualGrid, interaction);
                var cell      = cellGrid.Columns[point.x][point.y];
                var positions = cell.GetPositionsOrDefault(cellGrid);

                if (positions != null)
                {
                    this.scoreManager.Moves--;
                    foreach (var position in positions)
                    {
                        if (cellGrid.Columns[position.x][position.y].Type == this.scoreManager.ObjectiveType)
                        {
                            this.scoreManager.ObjectiveCount--;
                        }
                    }

                    CellGridOperation.RemoveCells(cellGrid, positions);
                }
            }
            else if (cellGrid.Events.Count == 0)
            {
                CellGridOperation.Fill(cellGrid);
            }
            else if (cellGrid.Events.Count > 0)
            {
                this.visualGrid.Sync(cellGrid);
            }

            this.visualGrid.Cascade();
        }
Esempio n. 3
0
        private void OnDrawGizmos()
        {
            var cellGrid = new CellGrid(gridWidth, gridHeight);

            CellGridOperation.Fill(cellGrid);

            foreach (var column in cellGrid.Columns)
            {
                foreach (var cell in column)
                {
                    var point  = GridQuery.ToPoint(cellGrid, cell);
                    var center = new Vector3(point.x, point.y);
                    var size   = new Vector3(1, 1, 1);

                    Gizmos.color = Color.yellow;
                    Gizmos.DrawWireCube(center, size);
                }
            }
        }
Esempio n. 4
0
        public List <Point> GetPositionsOrDefault(CellGrid grid)
        {
            Debug.Assert(grid != null, "Cannot activate BasicBlock on a null CellGrid.");

            var cellPoint = GridQuery.ToPoint(grid, this);
            var cell      = grid.Columns[cellPoint.x][cellPoint.y];
            var queue     = new Queue <Point>();

            queue.Enqueue(cellPoint);

            var positions = new List <Point>();

            while (queue.Count > 0)
            {
                var position    = queue.Dequeue();
                var currentCell = grid.Columns[position.x][position.y];

                if (!positions.Contains(position) && currentCell.Type == cell.Type)
                {
                    positions.Add(position);

                    var surroundingPositions = GridQuery.GetSurrounding(grid, position, false);
                    foreach (var point in surroundingPositions)
                    {
                        if (!queue.Contains(point))
                        {
                            queue.Enqueue(point);
                        }
                    }
                }
            }
            if (positions.Count > 1)
            {
                var soundManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <SoundManager>();
                Debug.Assert(soundManager != null, "Could not locate SoundManager");
                soundManager.PlaySound(this.Type);

                return(positions);
            }

            return(null);
        }