Ejemplo n.º 1
0
    public void Undo(object sender, EventArgs e)
    {
        if (GameModel.State == GameState.GameOver)
        {
            GameOverPanel.Disable();
            SpriteState state = new SpriteState {
                pressedSprite = _restartButtonNormalHoverStateSprite
            };
            _restartButton.GetComponent <Button>().spriteState  = state;
            _restartButton.GetComponent <Button>().image.sprite = _restartButtonNormalStateSprite;
            GameModel.State = GameState.Idle;
        }
        if (GameModel.State == GameState.Win)
        {
            WinPanel.Disable();
            SpriteState state = new SpriteState {
                pressedSprite = _restartButtonNormalHoverStateSprite
            };
            _restartButton.GetComponent <Button>().spriteState  = state;
            _restartButton.GetComponent <Button>().image.sprite = _restartButtonNormalStateSprite;
            GameModel.State = GameState.Idle;
        }
        if (GameModel.State == GameState.Idle)
        {
            EventSystem.OnUndoInvoke();
            for (int i = 0; i < GameModel.AllCells.Count; i++)
            {
                if (GameModel.AllCells[i].isReadyToDestroy)
                {
                    CellView cellView = GetCellViewById(GameModel.AllCells[i].id);
                    Debug.Log("<color=\"red\">DESTROY: " + cellView.CellData.ToString() + "</color>");
                    GameModel.UnregisterCell(cellView.CellData.id, true);
                    cellView.Kill();
                    i--;
                    _cellViews.RemoveAll(c => c.CellData.id == cellView.CellData.id);
                }
            }

            RefreshField();
        }
        else
        {
            Debug.Log("Undo DENIED!");
        }
    }