Ejemplo n.º 1
0
        private void RemoveBlocks()
        {
            List <List <Tile> > blocks = FindBlocks();

            foreach (List <Tile> block in blocks)
            {
                foreach (Tile tile in block)
                {
                    if (FadingTiles.Count > 0)
                    {
                        FadingTiles.Remove(tile);
                    }
                    TileArray[tile.Col, tile.Row].Figure = null;
                }
            }

            ((GameplayScreen)ScreenManager.Instance.CurrentScreen).CurrentTime += 1;
            if (((GameplayScreen)ScreenManager.Instance.CurrentScreen).CurrentTime > ((GameplayScreen)ScreenManager.Instance.CurrentScreen).TimeLimit)
            {
                ((GameplayScreen)ScreenManager.Instance.CurrentScreen).CurrentTime = ((GameplayScreen)ScreenManager.Instance.CurrentScreen).TimeLimit;
            }

            ((GameplayScreen)ScreenManager.Instance.CurrentScreen).Score.Text = "SCORE: " + (10 * score).ToString();
            AdditionalState = FieldStates.TilesStoppedMoving;

            for (int i = Settings.ColsCount - 1; i >= 0; --i)
            {
                for (int j = Settings.RowsCount - 1; j >= 0; --j)
                {
                    if (TileArray[i, j].Figure == null)
                    {
                        Tile firstAbove = FindFirstAbove(i, j);
                        if (firstAbove != null)
                        {
                            AdditionalState = FieldStates.TilesMoving;
                            TileArray[firstAbove.Col, firstAbove.Row].Figure = null;
                            firstAbove.InitiateMovement(TileArray[i, j].Position, 4);
                            firstAbove.Background.Position = TileArray[i, j].Background.Position;
                            firstAbove.Col  = i;
                            firstAbove.Row  = j;
                            TileArray[i, j] = firstAbove;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            // Attention: a handful of brain cells has been sacrificed to Satan
            // In order to make fancy swapping animation work properly;
            // It's time to kick switches and chew bubblegum... and I'm all outta gum

            switch (MainState)
            {
            case FieldStates.RemovingTiles:
                switch (AdditionalState)
                {
                case FieldStates.TilesFading:
                    if (FadingTiles.Last().Figure.Alpha != 0.0f)
                    {
                        foreach (Tile tile in FadingTiles)
                        {
                            RemoveEffect.Apply(tile.Figure);
                        }
                    }
                    else
                    {
                        AdditionalState = FieldStates.RemovingTiles;
                    }
                    break;

                case FieldStates.RemovingTiles:
                    RemoveBlocks();
                    break;

                case FieldStates.TilesStoppedMoving:
                    FillTiles();
                    if (FindBlocks().Count > 0)
                    {
                        BlocksFadeout();
                        AdditionalState = FieldStates.TilesFading;
                    }
                    else if (MovesAvailable())
                    {
                        MainState = AdditionalState = FieldStates.Idle;
                    }
                    else
                    {
                        ((GameplayScreen)ScreenManager.Instance.CurrentScreen).IsGameFinished = true;
                    }
                    break;
                }
                break;

            case FieldStates.Swapping:
                switch (AdditionalState)
                {
                case FieldStates.SwappingBack:
                    MainState           = AdditionalState = FieldStates.Idle;
                    CurrentSelectedTile = PreviousSelectedTile = null;
                    break;

                case FieldStates.TilesStoppedMoving:
                    if (FindBlocks().Count == 0)
                    {
                        CurrentSelectedTile.InitiateMovement(PreviousSelectedTile.Position);
                        PreviousSelectedTile.InitiateMovement(CurrentSelectedTile.Position);
                        SwapTiles(ref CurrentSelectedTile, ref PreviousSelectedTile);
                        AdditionalState = FieldStates.SwappingBack;
                    }
                    else
                    {
                        BlocksFadeout();
                        MainState           = FieldStates.RemovingTiles;
                        CurrentSelectedTile = PreviousSelectedTile = null;
                    }
                    break;
                }
                break;

            case FieldStates.Idle:
                if (PreviousSelectedTile != null)
                {
                    ClickEffect.Restore(PreviousSelectedTile.Figure);
                    if (IsAdjacent(CurrentSelectedTile, PreviousSelectedTile))
                    {
                        CurrentSelectedTile.InitiateMovement(PreviousSelectedTile.Position);
                        PreviousSelectedTile.InitiateMovement(CurrentSelectedTile.Position);
                        SwapTiles(ref CurrentSelectedTile, ref PreviousSelectedTile);
                        MainState       = FieldStates.Swapping;
                        AdditionalState = FieldStates.TilesMoving;
                        break;
                    }
                    else
                    {
                        if (CurrentSelectedTile == PreviousSelectedTile)
                        {
                            CurrentSelectedTile = null;
                        }
                        PreviousSelectedTile = null;
                    }
                }

                if (CurrentSelectedTile != null)
                {
                    ClickEffect.Apply(CurrentSelectedTile.Figure);
                }
                break;
            }

            // So many field states, so little time :)

            foreach (Tile tile in TileArray)
            {
                tile.Update(gameTime);
            }
        }