Esempio n. 1
0
        private void LayoutForm_KeyDown(object sender, KeyEventArgs e)
        {
            var strKeyPress = e.KeyCode.ToString();
            if (!_isGameOver) {
                switch (strKeyPress.ToUpper()) {
                    case "A":
                        if (_aShape.ShapeMoving) {
                            _rectangleShape = _aShape.MoveShapeLeft(10, _gameGrid.GetGameGrid());
                        }
                        break;
                    case "D":
                        if (_aShape.ShapeMoving) {
                            _rectangleShape = _aShape.MoveShapeRight(10, _gameGrid.GetGameGrid());
                        }
                        break;
                    case "W":
                        if (_aShape.ShapeMoving) {
                            _rectangleShape = _aShape.FlipShape("right", _gameGrid.GetGameGrid());
                        }
                        break;
                    case "Q":
                        _gameTimer.Stop();
                        SetUpGame();
                        DrawStart();
                        break;
                    case "X":
                        Close();
                        break;
                    case "ESCAPE":
                        if (_isGamePaused) {
                            _gameTimer.Start();
                            _isGamePaused = false;
                        }
                        else {
                            _gameTimer.Stop();
                            _isGamePaused = true;
                            var gpause = _startScreen.GetGraphics();
                            _startScreen.Erase();

                            for (var i = 0; i < _numberOfRows; i++) {
                                for (var k = 0; k < _numberOfCols; k++) {
                                    gpause.DrawRectangle(new Pen(Color.White, 0.01f), _rectangleGameGrid[i][k]);
                                }
                            }

                            gpause.FillRectangle(new SolidBrush(Color.Black), 31, 103, 105, 28);
                            gpause.DrawRectangle(new Pen(Color.White, 0.01f), 31, 103, 105, 28);
                            gpause.DrawString("Pause", new Font(Retrofont.Families[0], 18), new SolidBrush(Color.White),
                                30, 100);

                            _startScreen.Flip();
                        }
                        break;
                    case "R":
                        DrawGameOver();
                        break;
                    case "SPACE":
                        if (_aShape.ShapeMoving) {
                            _gameTimer.Interval = _dropRate;
                            IsDropped = true;
                        }
                        break;
                }
            }
            else {
                if (strKeyPress.ToUpper() == "SPACE") {
                    SetUpGame();
                    _shapeType = GetShapeType();
                    _aShape = new Shape(_shapeType, _mainScreen.ScreenWidth, _mainScreen.ScreenHeight, false);
                    _nextShapeType = GetShapeType();

                    _aShape.ShapeMoving = true;
                    _isGameOver = false;
                    _gameTimer.Interval = _gameSpeed;
                    _gameTimer.Enabled = true;
                    _gameTimer.Start();
                }
            }
        }
Esempio n. 2
0
        private void menuNewGame_Click(object sender, EventArgs e)
        {
            SetUpGame();
            _shapeType = GetShapeType();
            _aShape = new Shape(_shapeType, _mainScreen.ScreenWidth, _mainScreen.ScreenHeight, false);
            _nextShapeType = GetShapeType();

            _aShape.ShapeMoving = true;
            _isGameOver = false;
            _gameTimer.Interval = _gameSpeed;
            _gameTimer.Enabled = true;
            _gameTimer.Start();
        }
Esempio n. 3
0
        private void GameTimer_Tick(object sender, EventArgs e)
        {
            if (_aBtnClicked) {
            }
            if (_startBtnPressed) {
                SetUpGame();

                _shapeType = GetShapeType();
                _aShape = new Shape(_shapeType, _mainScreen.ScreenWidth, _mainScreen.ScreenHeight, false);
                // _nextShapeType = GetShapeType();
                _nextShapeType = 1;

                _aShape.ShapeMoving = true;
                _isGameOver = false;
                _gameTimer.Interval = _gameSpeed;
                _gameTimer.Enabled = true;
                _gameTimer.Start();
                _startBtnPressed = false;
                return;
            }
            if (_aShape != null) {
                if (_aShape.ShapeMoving) {
                    if (_dropBtnPressed) {
                        _gameTimer.Interval = _dropRate;
                        _dropBtnPressed = false;
                    }
                    _rectangleShape = _aShape.MoveShapeDown(_dropRate, _gameGrid.GetGameGrid());
                    DrawScreen();
                }

                else {
                    int xCoordinate;
                    int yCoordinate;

                    for (var i = 0; i < 4; i++) {
                        if (_rectangle.Contains(_rectangleShape[i])) {
                            continue;
                        }
                        _isGameOver = true;
                        break;
                    }
                    if (!_isGameOver) {
                        var intYCoordinates = new int[4];

                        for (var i = 0; i < 4; i++) {
                            xCoordinate = _rectangleShape[i].X;
                            yCoordinate = _rectangleShape[i].Y;
                            intYCoordinates[i] = yCoordinate/10;

                            _gameGrid.SetShapeLocation(yCoordinate/10, xCoordinate/10, _rectangleShape[i], _shapeType);
                        }

                        Array.Sort(intYCoordinates);
                        for (var i = 0; i < 4; i++) {
                            _isRowFull = true;

                            for (var j = 0; j < _numberOfCols; j++) {
                                if (_gameGrid.IsGridLocationEmpty(intYCoordinates[i], j)) {
                                    _isRowFull = false;
                                    break;
                                }
                            }
                            if (_isRowFull) {
                                for (var k = intYCoordinates[i]; k > 0; k--) {
                                    for (var l = 0; l < _numberOfCols; l++) {
                                        _gameGrid.DropRowsDown(k, l);
                                    }
                                }

                                _gameGrid.SetTopRow();

                                UpdateScore(intYCoordinates[i]);
                                _bonusHeight = _drawingAreaCanvas.Height - 1;
                            }
                        }
                        _shapeType = _nextShapeType;
                        _aShape = new Shape(_shapeType, _mainScreen.ScreenWidth, _mainScreen.ScreenHeight, false);
                        _nextShapeType = GetShapeType();

                        _aShape.ShapeMoving = true;

                        _gameTimer.Interval = _gameSpeed;
                        IsDropped = false;
                    }
                    else {
                        _gameTimer.Stop();

                        DrawGameOver();
                    }
                }
            }
        }