public static void SaveScore(HighScoresTable instance)
 {
     using (var stream = File.Open("scores.dat", FileMode.Create))
     {
         var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         binaryFormatter.Serialize(stream, instance);
         stream.Close();
     }
 }
        public void CompleteCb()
        {
            if (_gameController.GameOver)
            {
                _stateLabel.Caption       = "Game Over";
                _stateLabel.IsVisible     = true;
                _startPauseButton.Caption = "New Game";
            }
            else
            {
                _stateLabel.IsVisible = false;
            }

            _highScoresTable.AddScore(_gameController.Score);
            HighScoresTable.SaveScore(_highScoresTable);
            _scoresPresenter.IsVisible = true;
        }
        public QuadrapasselScene(Settings settings) : base(settings)
        {
            _gameController  = new GameController(settings.GameSettings);
            _highScoresTable = HighScoresTable.LoadScores();

            _gameController.ShapeLanded  += ShapeLandedCb;
            _gameController.PauseChanged += PauseChangedCb;
            _gameController.Complete     += CompleteCb;
            _gameController.Started      += StartedCb;

            _gameController.SetMozaic();

            _gameArea = new UIGameArea(_gameController)
            {
                PositionX = UIBlock.Size,
                PositionY = UIBlock.Size
            };
            _previewArea = new UIPreviewArea(_gameController)
            {
                PositionX = UIBlock.Size + _gameArea.Width + UIBlock.Size,
                PositionY = UIBlock.Size
            };

            _scoresPresenter = new UIScoresPresenter(_highScoresTable)
            {
                PositionX = UIBlock.Size,
                PositionY = UIBlock.Size,
                Width     = _gameArea.Width,
                Height    = _gameArea.Height,
                IsVisible = false
            };

            _scoreNameLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 7 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "Score"
            };
            _scoreLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 8 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "0"
            };

            _linesNameLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 10 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "Lines"
            };
            _linesLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 11 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "0"
            };

            _levelNameLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 13 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "Level"
            };
            _levelLabel = new UILabel
            {
                PositionX        = 2 * UIBlock.Size + _gameArea.Width,
                PositionY        = 14 * UIBlock.Size,
                Width            = 5 * UIBlock.Size,
                Height           = 1 * UIBlock.Size,
                OutlineThickness = 0,
                Caption          = "0"
            };
            _startPauseButton = new UIButton
            {
                PositionX = 2 * UIBlock.Size + _gameArea.Width,
                PositionY = 16 * UIBlock.Size,
                Width     = 5 * UIBlock.Size,
                Height    = 2 * UIBlock.Size,
                Caption   = "Start",
                Action    = PlayButtonClick
            };
            _scoresButton = new UIButton
            {
                PositionX = 2 * UIBlock.Size + _gameArea.Width,
                PositionY = 19 * UIBlock.Size,
                Width     = 5 * UIBlock.Size,
                Height    = 2 * UIBlock.Size,
                Caption   = "High Scores",
                Action    = ShowScores
            };
            _stateLabel = new UILabel
            {
                PositionX        = _gameArea.PositionX,
                PositionY        = _gameArea.PositionY,
                Width            = _gameArea.Width,
                Height           = _gameArea.Height,
                FontSize         = 2 * UIBlock.Size,
                OutlineThickness = 2,
                Caption          = "Test",
                IsVisible        = false
            };
        }