Exemplo n.º 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();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method <c>HoldBlock()</c>
        /// sets the heldBlock to the current block, and then sets the current block to
        /// the next block.
        /// </summary>
        public void HoldBlock()
        {
            if (HeldBlock.Count == 0)
            {
                _heldShape = _shapeFactory.BuildShape(_shape);

                for (int i = 0; i < 4; i++)
                {
                    Blocks.Remove(x => x.GridX == _shape.ShapeBlocks[i].GridX &&
                                  x.GridY == _shape.ShapeBlocks[i].GridY);
                }

                _shape = _nextShape;
                _shape.CenterShape();

                Blocks.AddRange(_shape.ShapeBlocks);
                _nextShape = _shapeFactory.BuildRandomShape();
                NextBlock.Clear();
                NextBlock.AddRange(_nextShape.ShapeBlocks);
                HeldBlock.AddRange(_heldShape.ShapeBlocks);
            }
            else
            {
                HeldBlock.Clear();
                var tempShape = _heldShape;
                _heldShape = _shapeFactory.BuildShape(_shape);

                for (int i = 0; i < 4; i++)
                {
                    Blocks.Remove(x => x.GridX == _shape.ShapeBlocks[i].GridX &&
                                  x.GridY == _shape.ShapeBlocks[i].GridY);
                }

                _shape = tempShape;
                _shape.CenterShape();
                Blocks.AddRange(_shape.ShapeBlocks);
                HeldBlock.AddRange(_heldShape.ShapeBlocks);
            }
        }