예제 #1
0
        public TetrisGamePanel(int row, int col, Worksheet ws)
        {
            InitializeComponent();


            if (GameSheet == null)
            {
                GameSheet = ws;
            }
            RowNum         = row;
            ColNum         = col;
            this.Wplane    = new GamePlane(ws, row, col);
            this.GameTimer = new Timer();

            #region Event Define
            GameTimer.Interval = 120;
            {
                Globals.ThisAddIn.Application.WindowResize += Application_WindowResize;
                GameTimer.Tick    += GameTimer_Tick;
                Wplane.ClearRows  += Wplane_ClearRows;
                Wplane.GameFailed += Wplane_GameFailed;
            }
            #endregion

            RandomNum = new Random();

            CurrentType       = RandomNum.Next(7);
            NextType          = RandomNum.Next(7);
            this.Deactivate  += PauseGame;
            StepWise          = DefStepWise;
            GameTimer.Enabled = false;

            this.CurrentBlock = new Gameblock(ws, col / 2 * Gwidth, -1 * Gwidth, Gwidth, CurrentType, 1);
            textBox1.Text     = Heading + StringShow[NextType];
        }
예제 #2
0
 public Gameblock(Gameblock ts, int x = -1, int y = -1, int width = -1, int ty = -1, int ori = -1)
     : base(x == -1 ? ts.Xcor : x, y == -1 ? ts.Ycor : y, width <= 0 ? ts.Width : width,
            (BlockType)(ty < 0 ? ts.Type : ty % 7)
            , ori == -1 ? ts.Oritation : ori)
 {
     workingsheet = ts.workingsheet;
 }
예제 #3
0
 private int Wplane_GameFailed(int Args)
 {
     MessageBox.Show("You lost and the score is " + Score.ToString());
     foreach (Shape s in this.GameSheet.Shapes)
     {
         s.Delete();
     }
     Wplane            = new GamePlane(GameSheet, RowNum, ColNum);
     this.CurrentBlock = new Gameblock(GameSheet, ColNum / 2 * Gwidth, -1 * Gwidth, Gwidth, 1, 1);
     Wplane.Show();
     CurrentBlock.Show();
     return(Args);
 }
예제 #4
0
 private void GameTimer_Tick(object sender, EventArgs e)
 {
     if (!Wplane.HasPoints(CurrentBlock.DownPoints(StepWise)))
     {
         CurrentBlock.Y += StepWise;
     }
     else
     {
         CurrentBlock.Y = (CurrentBlock.Y / Gwidth + 1) * Gwidth;
         Wplane.AddBlock(CurrentBlock);
         CurrentType   = NextType;
         NextType      = RandomNum.Next(7);
         CurrentBlock  = new Gameblock(GameSheet, ColNum / 2 * Gwidth, -1 * Gwidth, Gwidth, CurrentType, 1);
         textBox1.Text = Heading + StringShow[NextType];
         CurrentBlock.Show();
     }
 }
예제 #5
0
        public void AddBlock(Gameblock gb)
        {
            if (gb != null)
            {
                App app = this.Workingsheet.Application;
                app.ScreenUpdating = false;
                Shape[] shapes = gb.BlockShape;
                foreach (Shape s in shapes)
                {
                    int x = (int)s.Left;
                    int y = (int)s.Top;
                    this.BlocksShape[y / RowWidth][x / RowWidth] = s;
                    SetValue(y / RowWidth + 1, x / RowWidth + 1, 1);
                }
                int stop  = 0;
                int count = 0;
                for (int i = 0; i < RowNum; ++i)
                {
                    if (IsFUllRow(i + 1))
                    {
                        if (stop == 0)
                        {
                            stop = i;
                        }
                        this.SpaceData[i] = 0;
                        for (int j = 0; j < ColNum; ++j)
                        {
                            this.BlocksShape[i][j]?.Delete();
                        }
                        count++;
                    }
                    else
                    {
                        if (stop != 0)
                        {
                            break;
                        }
                    }
                }
                if (count != 0)
                {
                    for (int r = stop + count - 1; r >= 0; --r)
                    {
                        if (r - count < 0)
                        {
                            for (int j = 0; j < ColNum; ++j)
                            {
                                this.BlocksShape[r][j] = null;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < ColNum; ++j)
                            {
                                this.BlocksShape[r][j] = this.BlocksShape[r - count][j];
                                if (this.BlocksShape[r][j] != null)
                                {
                                    BlocksShape[r][j].Top += count * RowWidth;
                                }
                            }
                        }
                    }
                    for (int r = stop + count - 1; r >= 0; --r)
                    {
                        this.SpaceData[r] = r - count < 0 ? 0 : this.SpaceData[r - count];
                    }
                }


                if (count != 0)
                {
                    ClearRows?.Invoke(count);
                }


                app.ScreenUpdating = true;

                if (this.SpaceData[0] > 0)
                {
                    this.GameFailed?.Invoke(0);
                    return;
                }
            }
        }