Ejemplo n.º 1
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            mainWindow.Dispatcher.Invoke(new Action(() =>
            {
                if (MoveDown())
                {
                    return;
                }
                else
                {
                    //下落完成
                    Insert(nowBlock, top, left);

                    nowBlock = nextBlock;
                    top      = 0;
                    left     = column / 2 - nowBlock.size / 2;

                    nextBlock.Remove(mainWindow.nextBlockCanvas);
                    nextBlock = GameBlock.NewBlock();
                    nextBlock.Draw(mainWindow.nextBlockCanvas, 6, 6, fillBrush1, edgeBrush1, 1, 1);

                    UpdateBoard();

                    if (!CanInsert(nowBlock, top, left))
                    {
                        timer.Stop();
                        MessageBox.Show("游戏结束");
                        nowBlock = null;
                        File.WriteAllText("score", highScore.ToString());
                        Clear();
                    }
                    else
                    {
                        nowBlock.Draw(mainWindow.gameCanvas, row, column, fillBrush1, edgeBrush1, top, left);
                        //更新interval
                        timer.Stop();
                        timer.Interval = Math.Max(minInterval, initInterval - score * gapInterval);
                        timer.Start();
                    }
                }
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在top, left位置插入一个block
        /// </summary>
        public void Insert(GameBlock block, int top, int left)
        {
            lock (block)
            {
                for (int i = 0; i < block.size; i++)
                {
                    for (int j = 0; j < block.size; j++)
                    {
                        if (block.block[i, j] == 1)
                        {
                            board[top + i, left + j] = 1;
                        }
                    }
                }

                block.Remove(mainWindow.gameCanvas);
            }
        }