Exemplo n.º 1
0
        private void btnEnter_Click(object sender, EventArgs e)  //进入游戏界面
        {
            TetrisForm tetris = new TetrisForm(MyMap, this);

            tetris.Disposed += Show;//子窗口关闭时,显示菜单
            tetris.Show();
            this.Hide();
        }
Exemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            TetrisForm TetrisGame = new TetrisForm();

            Application.Run(TetrisGame);
        }
Exemplo n.º 3
0
 public void addNewForm()
 {
     activeForm = nextForm;
     tetrisForms.Add(activeForm);
     nextForm = getRandomForm();
     if (isGameOver()) {
         gameOver();
     }
 }
Exemplo n.º 4
0
 public void newGame()
 {
     resetGame(MAXX,MAXY);
     activeForm = getRandomForm();
     tetrisForms.Add(activeForm);
     nextForm = getRandomForm();
     HasNewPoints = true;
     gameState = new ActiveState(this);
     timer.Start();
 }
Exemplo n.º 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);
        }