Beispiel #1
0
        /// <summary>
        /// Method <c> RestartGame</c> Restarts the game, setting all state to default,
        /// and clears all items that would be bound to the gui.
        /// </summary>

        public void RestartGame()
        {
            // reset game variables
            _timeInterval = 500;
            _gameOver     = false;
            _paused       = false;
            PauseMessage  = "";
            Score         = 0;
            Level         = 1;

            // clear collections
            Blocks.Clear();
            NextBlock.Clear();
            HeldBlock.Clear();
            GameBoard.ClearGrid();

            _timer.Interval = new TimeSpan(0, 0, 0, 0, _timeInterval);

            // create shapes
            _shape     = _shapeFactory.BuildRandomShape();
            _nextShape = _shapeFactory.BuildRandomShape();
            NextBlock.AddRange(_nextShape.ShapeBlocks);
            Blocks.AddRange(_shape.ShapeBlocks);

            _timer.Start();
        }
Beispiel #2
0
 /// <summary>
 /// Constructor <c> Tetris</c> instantiates tetris with all the default conditions
 /// </summary>
 public Tetris()
 {
     _shapeFactory   = new ShapeFactory(GameBoard.Grid);
     Blocks          = new ObservableCollection <BlockModel>();
     NextBlock       = new ObservableCollection <BlockModel>();
     HeldBlock       = new ObservableCollection <BlockModel>();
     _timer          = new DispatcherTimer();
     _timer.Interval = new TimeSpan(0, 0, 0, 0, _timeInterval);
     _timer.Tick    += GameTimer_Tick;
     _shape          = _shapeFactory.BuildRandomShape();
     _shape.CenterShape();
     _nextShape = _shapeFactory.BuildRandomShape();
     NextBlock.AddRange(_nextShape.ShapeBlocks);
     Blocks.AddRange(_shape.ShapeBlocks);
     Score = 0;
     Level = 1;
     _timer.Start();
 }