コード例 #1
0
        static public void PlayGame()
        {
            Hud.Score = 0;
            level     = 1;
            int dropSpeed = 20;

            isPlaying = true;

            TetrisBlock activeBlock = new TetrisBlock();

            playField = new PlayField();

            Engine.ClearScreen();
            SetCursorPosition(0, 0);

            while (isPlaying)
            {
                tick++;

                KeyInputCheck(activeBlock, playField);

                if (tick % (dropSpeed - level) == 0)
                {
                    activeBlock.YPos++;
                    tick = 0;
                }

                if (playField.CollisionCheck(activeBlock))
                {
                    playField.UpdateField(activeBlock);
                    playField.ScoreCheck();

                    // game over
                    if (playField.CollisionCheck(activeBlock) && isPlaying)
                    {
                        HighScores.CheckHighScore(Hud.Score);
                        isPlaying = false;
                    }
                }

                Hud.DrawHud();
                playField.DrawPlayField(xOffset, yOffset);
                activeBlock.DrawBlock(xOffset + activeBlock.XPos, yOffset + activeBlock.YPos);

                Thread.Sleep(40);
            }

            // remove keyboard input glitch
            Engine.GlitchFix();
        }
コード例 #2
0
        //private NewRecordDialog NRDialog;
        //private RecordsForm RForm;

        //private Image PausedImage, GameOverImage;
        #endregion /Переменные


        #region Инициализация формы
        public GameForm()
        {
            _game = new Game();             // создаем новую игру

            //Saver.Load();

            _playField          = new PlayField(20, 10);  // создаем игровое поле
            _nextShape          = new GameBoard(2, 4);    // создаем поле для следующей фигуры
            _game.StateChanged += Game_StateChanged;

            _game.StateChanged += Game_StateChanged;

            InitializeComponent();

            NewGame();
        }
コード例 #3
0
        private void Start()
        {
            gameController = GameController.Instance;
            levelManager   = LevelManager.Instance;

            gameDate      = (GameData.DevScripts.GameData)gameController.GameData.Data;
            playerManager = LevelManager.Instance.PlayerManager;

            objectPool = ObjectPool.GetPoolByName("ObjectPoints");

            playField = new PlayField(size);

            // define events
            playField.DestroyLineEvent += LineDestroy;
            playField.DropLineEvent    += LineDrop;

            playField.CreateObjectEvent += ObjectCreate;
            playField.ChangeObjectEvent += ObjectUpdate;
            playField.FixObjectEvent    += ObjectFix;

            playField.CantCreateObjectEvent += CannotCreateDropObject;
        }
コード例 #4
0
        private static void KeyInputCheck(TetrisBlock activeBlock, PlayField playField)
        {
            string pauseText = @"
      ___     |      ___     |      ___     |      ___     |      ___     
     /\--\    |     /\--\    |     /\__\    |     /\--\    |     /\--\    
    /##\--\   |    /##\--\   |    /#/--/    |    /##\--\   |    /##\--\   
   /#/\#\--\  |   /#/\#\--\  |   /#/--/     |   /#/\#\--\  |   /#/\#\--\  
  /##\-\#\--\ |  /##\-\#\--\ |  /#/--/  ___ |  _\#\-\#\--\ |  /##\-\#\--\ 
 /#/\#\-\#\__\| /#/\#\-\#\__\| /#/__/  /\__\| /\-\#\-\#\__\| /#/\#\-\#\__\
 \/__\#\/#/--/| \/__\#\/#/--/| \#\--\ /#/--/| \#\-\#\-\/__/| \#\-\#\-\/__/
      \##/--/ |      \##/--/ |  \#\--/#/--/ |  \#\-\#\__\  |  \#\-\#\__\  
       \/__/  |      /#/--/  |   \#\/#/--/  |   \#\/#/--/  |   \#\-\/__/  
              |     /#/--/   |    \##/--/   |    \##/--/   |    \#\__\    
              |     \/__/    |     \/__/    |     \/__/    |     \/__/    
";

            if (KeyAvailable)
            {
                ConsoleKeyInfo key = ReadKey();

                if (key.Key == ConsoleKey.Escape)
                {
                    isPlaying = false;
                }

                if (key.Key == ConsoleKey.Enter && pauseMenu == false)
                {
                    Engine.ClearScreen();
                    Engine.DrawTitle(pauseText, 10);
                    pauseMenu = true;
                    ReadKey();
                }

                if (key.Key == ConsoleKey.Enter && pauseMenu == true)
                {
                    Engine.ClearScreen();
                    pauseMenu = false;
                }

                if (key.Key == ConsoleKey.RightArrow)
                {
                    if ((activeBlock.XPos < playField.XWith - (activeBlock.Shape.GetLength(1) + 1)))
                    {
                        activeBlock.XPos += 2;
                        if (playField.CollisionCheck(activeBlock))
                        {
                            activeBlock.XPos -= 2;
                        }
                    }
                }

                if (key.Key == ConsoleKey.LeftArrow)
                {
                    if (activeBlock.XPos >= 1)
                    {
                        activeBlock.XPos -= 2;
                        if (playField.CollisionCheck(activeBlock))
                        {
                            activeBlock.XPos += 2;
                        }
                    }
                }

                if (key.Key == ConsoleKey.UpArrow)
                {
                    activeBlock.RotateShape();
                }

                if (key.Key == ConsoleKey.DownArrow)
                {
                    tick = 1;
                    activeBlock.YPos++;
                }

                if (key.Key == ConsoleKey.Spacebar)
                {
                    while (!playField.CollisionCheck(activeBlock))
                    {
                        activeBlock.YPos++;
                        Hud.Score++;
                    }

                    playField.UpdateField(activeBlock);
                    playField.ScoreCheck();

                    // game over
                    if (playField.CollisionCheck(activeBlock))
                    {
                        HighScores.CheckHighScore(Hud.Score);
                        isPlaying = false;
                    }
                }
            }
        }