예제 #1
0
        private void btnEnter_Click(object sender, EventArgs e)  //进入游戏界面
        {
            TetrisForm tetris = new TetrisForm(MyMap, this);

            tetris.Disposed += Show;//子窗口关闭时,显示菜单
            tetris.Show();
            this.Hide();
        }
예제 #2
0
파일: Program.cs 프로젝트: ArtemK123/Tetris
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            TetrisForm TetrisGame = new TetrisForm();

            Application.Run(TetrisGame);
        }
예제 #3
0
 public void addNewForm()
 {
     activeForm = nextForm;
     tetrisForms.Add(activeForm);
     nextForm = getRandomForm();
     if (isGameOver()) {
         gameOver();
     }
 }
예제 #4
0
 public void newGame()
 {
     resetGame(MAXX,MAXY);
     activeForm = getRandomForm();
     tetrisForms.Add(activeForm);
     nextForm = getRandomForm();
     HasNewPoints = true;
     gameState = new ActiveState(this);
     timer.Start();
 }
예제 #5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var shapeFactory    = new TetrisShapeFactory(new Random());
            var colorFactory    = new ColorFactory(new Random());
            var gameGrid        = new GameGrid(8, 20);
            var previewGameGrid = new GameGrid(5, 5);
            var gameGridMgr     = new GameGridShapeDecorator(gameGrid);
            var gameController  = new GameController(gameGridMgr);
            var scoreManager    = new ScoreManager();

            Action updatePreviewPane = () =>
            {
                previewGameGrid.Clear();
                var nextShape  = shapeFactory.PeekNext();
                var nextColour = colorFactory.PeekNext();
                previewGameGrid.TryAdd(
                    Array.ConvertAll(nextShape.Points,
                                     p => new ColouredPoint(nextColour, p.Move(new Point((previewGameGrid.Width - 1) / 2, 3)))));
            };

            var form = new TetrisForm();

            form.PreviewGrid    = previewGameGrid;
            form.GameGrid       = gameGridMgr;
            form.GameController = gameController;
            form.ScoreManager   = scoreManager;

            gameGridMgr.SetShape(shapeFactory.GetNext(), colorFactory.GetNext());
            updatePreviewPane();

            Timer ticky = new Timer()
            {
                Interval = 500,
            };

            ticky.Tick += (a, b) =>
            {
                if (!gameGridMgr.MoveDown())
                {
                    if (!gameGridMgr.CommitShape())
                    {
                        ticky.Stop();
                        return;
                    }
                    gameGridMgr.SetShape(shapeFactory.GetNext(), colorFactory.GetNext());
                    updatePreviewPane();
                    scoreManager.ProcessShapeLanded();
                }
                var rows = gameGridMgr.ClearFullRows();
                if (rows > 0)
                {
                    scoreManager.ProcessRowsRemoved(rows);
                }

                form.Refresh();
            };
            ticky.Start();


            Application.Run(form);
        }