Ejemplo n.º 1
0
        public void SetShape(ITetrisShape shape, Color color)
        {
            var startingY = -shape.Points.Select(p => p.Y).Max() - 1;
            var location  = new Point((_gameGrid.Width - 1) / 2, startingY);

            _movingShape = new PositionedShape(shape, color, location);
        }
Ejemplo n.º 2
0
        private void tmTick_Tick(object sender, EventArgs e)
        {
            if (_currentShape == null)
            return;

              if (_currentShape.CanMove(MovingDirections.Down))
              {
            //Move the shape down
            _currentShape.Move(MovingDirections.Down);
              }
              else
              {
            //Shape can't be moved down, check for cleared rows
            CheckRows();

            //Continue when the game is not over yet
            if (!_isGameOver)
            {
              //Assign pending shape to current shape
              _currentShape = GenerateRandomShape(false);

              //Create new pending shape
              if (_pendingShape != null)
            _pendingShape.ResetCells();
              _pendingShape = GenerateRandomShape(true);

              //Remap action for new shape
              MapCustomActions();
            }
              }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reset the board and start the game
        /// </summary>
        private void GameStart()
        {
            //Stop ticking
              tmTick.Stop();

              //Remove shape
              sheet1.RemoveShape("rectGameOver");
              //Clear ranges
              _previewRange.ResetCellType();
              _gameRange.ResetCellType();

              //Create random shapes
              _currentShape = GenerateRandomShape(false);

              _pendingShape = GenerateRandomShape(true);
              sheet1.Cells[2, 12].Text = "0";
              _isGameOver = false;
              _isPaused = false;

              //Map custom action
              MapCustomActions();

              //Start ticking
              tmTick.Start();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stop everything, show Game Over
        /// </summary>
        private void GameOver()
        {
            tmTick.Stop();
              sheet1.AddShape(_rectGameOver);
              _isGameOver = true;

              _currentShape = null;
              _pendingShape = null;

              //Because _currentShape is now null, calling MapCustomAction again will act as remove custom the custom actions
              MapCustomActions();
        }
Ejemplo n.º 5
0
 public RotateShape(ITetrisShape shape)
 {
     _currentShape = shape;
 }
Ejemplo n.º 6
0
 public MoveShape(ITetrisShape shape, MovingDirections direction)
 {
     _currentShape = shape;
     _movingDirection = direction;
 }