Esempio n. 1
0
 private void NetTrix_Activated(object sender, System.EventArgs e)
 {
     //        This event occurs when the window receives back the focus after losing it to another window
     //        So, we redraw the whole game field
     //        Clear the game field
     PicBackground.Invalidate();
     Application.DoEvents();
     GameField.Redraw();
     if (NextBlock != null)
     {
         NextBlock.Show(PicNextBlock.Handle);
     }
 }
Esempio n. 2
0
        private void tmrGameClock_Tick(object sender, System.EventArgs e)
        {
            int erasedLines;

            if (stillProcessing)
            {
                return;
            }
            stillProcessing = true;

            //Manage the falling block
            if (!CurrentBlock.Down())
            {
                if (CurrentBlock.Top() == 0)
                {
                    tmrGameClock.Enabled = false;
                    CmdStart.Enabled     = true;
                    MessageBox.Show("GAME OVER", ".NETTrix", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    stillProcessing = false;
                    return;
                }
                //increase score based on # of deleted lines
                erasedLines = GameField.CheckLines();
                if (erasedLines > 0)
                {
                    score += 100 * erasedLines;
                    lblScoreValue.Text = score.ToString();
                    //Clear the game field and force the window to re-paint
                    PicBackground.Invalidate();
                    Application.DoEvents();
                    GameField.Redraw();
                }

                //Replace the current block...
                CurrentBlock = new Block(new Point(GameField.SquareSize * 6, 0), NextBlock.BlockType);
                CurrentBlock.Show(PicBackground.Handle);

                //Create the Next block
                NextBlock.Hide(PicNextBlock.Handle);
                NextBlock = new Block(new Point(20, 10), Block.BlockTypes.Undefined);
                NextBlock.Show(PicNextBlock.Handle);
            }
            stillProcessing = false;
        }
Esempio n. 3
0
        private void CmdStart_Click(object sender, System.EventArgs e)
        {
            tmrGameClock.Enabled = true;
            CmdStart.Enabled     = false;
            lblScoreValue.Text   = "0";

            // Clean the game field
            PicBackground.Invalidate();
            Application.DoEvents();
            GameField.Reset();
            GameField.Redraw();

            // Create and show the current and next blocks
            CurrentBlock = new Block(new Point(GameField.SquareSize * 6, 50), Block.BlockTypes.Undefined);
            CurrentBlock.Show(PicBackground.Handle);

            NextBlock = new Block(new Point(20, 10), Block.BlockTypes.Undefined);
            NextBlock.Show(PicNextBlock.Handle);
        }