Re: Redraw problem - please help
- From: "Publicjoe" <mike@xxxxxxxxxxxxxxx>
- Date: Tue, 21 Jun 2005 14:53:31 +0100
Thanks Bob, I will Stop doing it and put a panel in its place. This has
given me a small amount of amusement as I should have known better. It is
nice to laugh at yourself from time to time, to prve we are all human.
Cheers
Mike
"Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eiOtmBmdFHA.1036@xxxxxxxxxxxxxxxxxxxxxxx
> I *know* you've posted on this group before and you still haven't read the
> #1 GDI+ FAQ page <sigh>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Publicjoe" <mike@xxxxxxxxxxxxxxx> wrote in message
> news:%23HDdbvkdFHA.3808@xxxxxxxxxxxxxxxxxxxxxxx
> > Hi all,
> >
> > I am creating a tetris clone, but I have a problem, when I change apps
and
> > then go back to it. Any blocks sitting at the bottom of the screen do
not
> > get redrawn until the timer goes off, It is best to run the app in order
> > to
> > see the problem, I am enclosing all of the code in order to build the
> > application.
> >
> > Any help would be appreciated
> >
> > Cheers
> >
> > Mike
> >
> > //------ Block.cs ------//
> >
> > using System;
> > using System.Drawing;
> >
> > namespace Tetris
> > {
> > /// <summary>
> > /// Summary description for Blocks.
> > /// </summary>
> > public class Block
> > {
> > public Block()
> > {
> > }
> >
> > public Color BlockColour;
> > public int CurrentX;
> > public int CurrentY;
> > private int[,] BlockMatrix = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0,
0},
> > {0, 0, 0, 0}};
> >
> > public void Create()
> > {
> > System.Random randomNumber = new System.Random();
> >
> > int intBlockType;
> > intBlockType = randomNumber.Next() % 7;
> >
> > switch (intBlockType)
> > {
> > case 0:
> > {
> > BlockColour = Color.Blue;
> > BlockMatrix[1, 0] = 1;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[1, 3] = 1;
> > }
> > break;
> >
> > case 1:
> > {
> > BlockColour = Color.Red;
> > BlockMatrix[2, 1] = 1;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[2, 2] = 1;
> > }
> > break;
> >
> > case 2:
> > {
> > BlockColour = Color.Green;
> > BlockMatrix[1, 0] = 1;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[2, 0] = 1;
> > }
> > break;
> >
> > case 3:
> > {
> > BlockColour = Color.Yellow;
> > BlockMatrix[1, 0] = 1;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[2, 2] = 1;
> > }
> > break;
> >
> > case 4:
> > {
> > BlockColour = Color.Purple;
> > BlockMatrix[1, 0] = 1;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[2, 1] = 1;
> > BlockMatrix[2, 2] = 1;
> > }
> > break;
> >
> > case 5:
> > {
> > BlockColour = Color.DarkSalmon;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[2, 1] = 1;
> > BlockMatrix[2, 0] = 1;
> > }
> > break;
> >
> > case 6:
> > {
> > BlockColour = Color.YellowGreen;
> > BlockMatrix[1, 1] = 1;
> > BlockMatrix[1, 2] = 1;
> > BlockMatrix[1, 0] = 1;
> > BlockMatrix[2, 1] = 1;
> > }
> > break;
> >
> > default:
> > break;
> > }
> > }
> >
> > public void Rotate()
> > {
> > int[,] TempMatrix= {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0,
0,
> > 0, 0}};
> >
> > for( int q = 0; q <= 3; q++ )
> > {
> > for( int w = 0; w <= 3; w++ )
> > {
> > TempMatrix[q, w] = BlockMatrix[w, 3 - q];
> > }
> > }
> >
> > BlockMatrix = TempMatrix;
> > }
> >
> > public void Unrotate()
> > {
> > for( int q = 1; q <= 3; q++ )
> > {
> > Rotate();
> > }
> > }
> >
> > public string ReturnBlock()
> > {
> > //Return String with block coordinates delimited by //#//
> > string ReturnString = "";
> >
> > for( int q = 0; q <= 3; q++ )
> > {
> > for( int w = 0; w <= 3; w++ )
> > {
> > if (BlockMatrix[q, w] == 1)
> > {
> > if (ReturnString != "")
> > {
> > ReturnString = ReturnString + "#";
> > }
> >
> > ReturnString += (q + CurrentX).ToString() + "," + (w +
> > CurrentY).ToString();
> > }
> > }
> > }
> >
> > return ReturnString;
> > }
> >
> > public void MoveLeft()
> > {
> > CurrentX = CurrentX - 1;
> > }
> >
> > public void MoveRight()
> > {
> > CurrentX = CurrentX + 1;
> > }
> >
> > public void MoveDown()
> > {
> > CurrentY = CurrentY + 1;
> > }
> > }
> > }
> >
> > //------ End of Block.cs ------//
> >
> > //------ Form1.cs ------//
> >
> > using System;
> > using System.Drawing;
> > using System.Collections;
> > using System.Windows.Forms;
> >
> > namespace Tetris
> > {
> > /// <summary>
> > /// Summary description for Form1.
> > /// </summary>
> > public class Form1 : System.Windows.Forms.Form
> > {
> > private System.ComponentModel.IContainer components;
> > private System.Windows.Forms.Label txtScore;
> > private System.Windows.Forms.Label label1;
> > private System.Windows.Forms.Label GameOver;
> > private System.Windows.Forms.Button cmdPause;
> > private System.Windows.Forms.GroupBox GroupBox2;
> > private System.Windows.Forms.TextBox TextBox1;
> > private System.Windows.Forms.Label txtLines;
> > private System.Windows.Forms.PictureBox pictureBox1;
> > private System.Windows.Forms.PictureBox PlayArea;
> > private System.Windows.Forms.Button cmdStart;
> > private System.Windows.Forms.GroupBox GroupBox1;
> > private System.Windows.Forms.Label txtPaused;
> > private System.Windows.Forms.Timer Timer1;
> >
> > private const int PLAYAREAX = 9;
> > private const int PLAYAREAY = 18;
> >
> > private Block CurrentBlock;
> > private Block NextBlock;
> > private int[,] InternalPlayArea = new int[11, 20];
> > private bool Locked = false;
> > private bool Paused = false;
> > private int Score = 0;
> > private int Lines = 0;
> > private int Level = 0;
> >
> > public Form1()
> > {
> > InitializeComponent();
> >
> > // Enable Double Buffering to remove flicker
> > this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
> > this.SetStyle(ControlStyles.UserPaint, true);
> > this.SetStyle(ControlStyles.DoubleBuffer, true);
> >
> > CreateNextBlock();
> >
> > // Game Initialisation
> > InitGame();
> > }
> >
> > // Clean up any resources being used.
> > protected override void Dispose( bool disposing )
> > {
> > if( disposing )
> > {
> > if (components != null)
> > {
> > components.Dispose();
> > }
> > }
> > base.Dispose( disposing );
> > }
> >
> > #region Windows Form Designer generated code
> > /// <summary>
> > /// Required method for Designer support - do not modify
> > /// the contents of this method with the code editor.
> > /// </summary>
> > private void InitializeComponent()
> > {
> > this.components = new System.ComponentModel.Container();
> > this.Timer1 = new System.Windows.Forms.Timer(this.components);
> > this.txtPaused = new System.Windows.Forms.Label();
> > this.GroupBox1 = new System.Windows.Forms.GroupBox();
> > this.cmdStart = new System.Windows.Forms.Button();
> > this.PlayArea = new System.Windows.Forms.PictureBox();
> > this.pictureBox1 = new System.Windows.Forms.PictureBox();
> > this.txtLines = new System.Windows.Forms.Label();
> > this.TextBox1 = new System.Windows.Forms.TextBox();
> > this.GroupBox2 = new System.Windows.Forms.GroupBox();
> > this.cmdPause = new System.Windows.Forms.Button();
> > this.GameOver = new System.Windows.Forms.Label();
> > this.label1 = new System.Windows.Forms.Label();
> > this.txtScore = new System.Windows.Forms.Label();
> > this.GroupBox1.SuspendLayout();
> > this.GroupBox2.SuspendLayout();
> > this.SuspendLayout();
> > //
> > // Timer1
> > //
> > this.Timer1.Tick += new System.EventHandler(this.Timer1_Tick);
> > //
> > // txtPaused
> > //
> > this.txtPaused.Font = new System.Drawing.Font("Microsoft Sans
Serif",
> > 15.75F);
> > this.txtPaused.ForeColor = System.Drawing.Color.Red;
> > this.txtPaused.Location = new System.Drawing.Point(8, 224);
> > this.txtPaused.Name = "txtPaused";
> > this.txtPaused.Size = new System.Drawing.Size(88, 32);
> > this.txtPaused.TabIndex = 10;
> > this.txtPaused.Text = "Paused";
> > this.txtPaused.TextAlign =
> > System.Drawing.ContentAlignment.MiddleCenter;
> > this.txtPaused.Visible = false;
> > //
> > // GroupBox1
> > //
> > this.GroupBox1.Controls.Add(this.txtScore);
> > this.GroupBox1.Location = new System.Drawing.Point(4, 8);
> > this.GroupBox1.Name = "GroupBox1";
> > this.GroupBox1.Size = new System.Drawing.Size(96, 40);
> > this.GroupBox1.TabIndex = 8;
> > this.GroupBox1.TabStop = false;
> > this.GroupBox1.Text = "Score";
> > //
> > // cmdStart
> > //
> > this.cmdStart.Location = new System.Drawing.Point(16, 328);
> > this.cmdStart.Name = "cmdStart";
> > this.cmdStart.TabIndex = 1;
> > this.cmdStart.Text = "&Start";
> > this.cmdStart.Click += new System.EventHandler(this.Start_Click);
> > //
> > // PlayArea
> > //
> > this.PlayArea.Anchor = System.Windows.Forms.AnchorStyles.Right;
> > this.PlayArea.BackColor =
> > System.Drawing.SystemColors.ControlLightLight;
> > this.PlayArea.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D;
> > this.PlayArea.Location = new System.Drawing.Point(104, 8);
> > this.PlayArea.Name = "PlayArea";
> > this.PlayArea.Size = new System.Drawing.Size(210, 392);
> > this.PlayArea.TabIndex = 0;
> > this.PlayArea.TabStop = false;
> > //
> > // pictureBox1
> > //
> > this.pictureBox1.BackColor =
> > System.Drawing.SystemColors.ControlLightLight;
> > this.pictureBox1.BorderStyle =
> > System.Windows.Forms.BorderStyle.Fixed3D;
> > this.pictureBox1.Location = new System.Drawing.Point(4, 128);
> > this.pictureBox1.Name = "pictureBox1";
> > this.pictureBox1.Size = new System.Drawing.Size(92, 88);
> > this.pictureBox1.TabIndex = 11;
> > this.pictureBox1.TabStop = false;
> > //
> > // txtLines
> > //
> > this.txtLines.Font = new System.Drawing.Font("Microsoft Sans
Serif",
> > 9.75F, System.Drawing.FontStyle.Bold);
> > this.txtLines.Location = new System.Drawing.Point(8, 16);
> > this.txtLines.Name = "txtLines";
> > this.txtLines.Size = new System.Drawing.Size(80, 16);
> > this.txtLines.TabIndex = 0;
> > this.txtLines.TextAlign =
> > System.Drawing.ContentAlignment.MiddleCenter;
> > //
> > // TextBox1
> > //
> > this.TextBox1.Location = new System.Drawing.Point(144, 80);
> > this.TextBox1.Name = "TextBox1";
> > this.TextBox1.TabIndex = 1;
> > this.TextBox1.Text = "TextBox1";
> > //
> > // GroupBox2
> > //
> > this.GroupBox2.Controls.Add(this.txtLines);
> > this.GroupBox2.Location = new System.Drawing.Point(4, 64);
> > this.GroupBox2.Name = "GroupBox2";
> > this.GroupBox2.Size = new System.Drawing.Size(96, 40);
> > this.GroupBox2.TabIndex = 9;
> > this.GroupBox2.TabStop = false;
> > this.GroupBox2.Text = "Lines";
> > //
> > // cmdPause
> > //
> > this.cmdPause.Enabled = false;
> > this.cmdPause.Location = new System.Drawing.Point(16, 368);
> > this.cmdPause.Name = "cmdPause";
> > this.cmdPause.TabIndex = 4;
> > this.cmdPause.Text = "&Pause";
> > this.cmdPause.Click += new System.EventHandler(this.Pause_Click);
> > //
> > // GameOver
> > //
> > this.GameOver.Font = new System.Drawing.Font("Microsoft Sans
Serif",
> > 20F);
> > this.GameOver.ForeColor = System.Drawing.Color.Red;
> > this.GameOver.Location = new System.Drawing.Point(8, 256);
> > this.GameOver.Name = "GameOver";
> > this.GameOver.Size = new System.Drawing.Size(88, 64);
> > this.GameOver.TabIndex = 2;
> > this.GameOver.Text = "Game Over!";
> > this.GameOver.TextAlign =
> > System.Drawing.ContentAlignment.MiddleCenter;
> > this.GameOver.Visible = false;
> > //
> > // label1
> > //
> > this.label1.Location = new System.Drawing.Point(8, 112);
> > this.label1.Name = "label1";
> > this.label1.Size = new System.Drawing.Size(88, 16);
> > this.label1.TabIndex = 12;
> > this.label1.Text = "Next Block";
> > //
> > // txtScore
> > //
> > this.txtScore.Font = new System.Drawing.Font("Microsoft Sans
Serif",
> > 10F, System.Drawing.FontStyle.Bold);
> > this.txtScore.Location = new System.Drawing.Point(8, 16);
> > this.txtScore.Name = "txtScore";
> > this.txtScore.Size = new System.Drawing.Size(80, 16);
> > this.txtScore.TabIndex = 0;
> > this.txtScore.TextAlign =
> > System.Drawing.ContentAlignment.MiddleCenter;
> > //
> > // Form1
> > //
> > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> > this.ClientSize = new System.Drawing.Size(320, 405);
> > this.Controls.Add(this.label1);
> > this.Controls.Add(this.pictureBox1);
> > this.Controls.Add(this.PlayArea);
> > this.Controls.Add(this.cmdPause);
> > this.Controls.Add(this.GroupBox2);
> > this.Controls.Add(this.GroupBox1);
> > this.Controls.Add(this.TextBox1);
> > this.Controls.Add(this.GameOver);
> > this.Controls.Add(this.txtPaused);
> > this.Controls.Add(this.cmdStart);
> > this.KeyPreview = true;
> > this.Name = "Form1";
> > this.Text = "Tetris";
> > this.KeyDown += new
> > System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
> > this.GroupBox1.ResumeLayout(false);
> > this.GroupBox2.ResumeLayout(false);
> > this.ResumeLayout(false);
> > }
> > #endregion
> >
> > /// <summary>
> > /// The main entry point for the application.
> > /// </summary>
> > [STAThread]
> > static void Main()
> > {
> > Application.Run(new Form1());
> > }
> >
> > private void Form1_KeyDown(object sender,
> > System.Windows.Forms.KeyEventArgs e)
> > {
> > switch( e.KeyCode )
> > {
> > case Keys.Left:
> > {
> > if( CanMove(CurrentBlock, -1, 0) == true )
> > {
> > DrawBlock(CurrentBlock, "Clear");
> > CurrentBlock.MoveLeft();
> > DrawBlock(CurrentBlock, "Draw");
> > }
> > }
> > break;
> >
> > case Keys.Right:
> > {
> > if( CanMove(CurrentBlock, 1, 0) == true )
> > {
> > DrawBlock(CurrentBlock, "Clear");
> > CurrentBlock.MoveRight();
> > DrawBlock(CurrentBlock, "Draw");
> > }
> > }
> > break;
> >
> > case Keys.Up:
> > {
> > DrawBlock(CurrentBlock, "Clear");
> > CurrentBlock.Rotate();
> > if( CanMove(CurrentBlock, 0, 0) == true )
> > {
> > DrawBlock(CurrentBlock, "Draw");
> > }
> > else
> > {
> > CurrentBlock.Unrotate();
> > DrawBlock(CurrentBlock, "Draw");
> > }
> > }
> > break;
> >
> > case Keys.Down:
> > {
> > for( int i = CurrentBlock.CurrentY; i <= PLAYAREAY; i++ )
> > {
> > if( CanMove(CurrentBlock, 0, 1) == true )
> > {
> > DrawBlock(CurrentBlock, "Clear");
> > CurrentBlock.MoveDown();
> > DrawBlock(CurrentBlock, "Draw");
> > }
> > }
> >
> > Locked = false; // Override Locked
> > }
> > break;
> >
> > default:
> > break;
> > }
> > }
> >
> > private void Pause_Click(object sender, System.EventArgs e)
> > {
> > if( Paused == false )
> > {
> > Paused = true;
> > Timer1.Stop();
> > txtPaused.Visible = true;
> > }
> > else
> > {
> > Timer1.Start();
> > Paused = false;
> > txtPaused.Visible = false;
> > }
> > }
> >
> > private void Timer1_Tick(object sender, System.EventArgs e)
> > {
> > //Check if we can go down - else create new block
> > if( CanMove(CurrentBlock, 0, 1) == true )
> > {
> > DrawBlock(CurrentBlock, "Clear");
> > CurrentBlock.MoveDown();
> > DrawBlock(CurrentBlock, "Draw");
> > Locked = false;
> > }
> > else
> > {
> > if( Locked == true )
> > {
> > //Game Over
> > GameOver.Visible = true;
> > Timer1.Enabled = false;
> > cmdStart.Enabled = true;
> > cmdPause.Enabled = false;
> > }
> > else
> > {
> > DrawBlock(CurrentBlock, "Lock");
> > CheckForLine();
> > CurrentBlock = NextBlock;
> > CurrentBlock.CurrentX = 4;
> > CreateNextBlock();
> > DrawBlock(CurrentBlock, "Draw");
> > Locked = true;
> > }
> > }
> > }
> >
> > private void Start_Click(object sender, System.EventArgs e)
> > {
> > InitGame();
> >
> > CreateNewBlock();
> > Timer1.Interval = 800;
> > Timer1.Enabled = true;
> > cmdStart.Enabled = false;
> > cmdPause.Enabled = true;
> > CreateNextBlock();
> > DrawBlock(CurrentBlock, "Draw");
> > }
> >
> > // Graphical Routines (Draw / Clear )
> > public void ClearBox(int intX, int intY)
> > {
> > Graphics g = PlayArea.CreateGraphics();
> > SolidBrush B = new SolidBrush(Color.White);
> > Rectangle rect = new Rectangle(4 + intX * 20, 4 + intY * 20, 19,
19);
> >
> > g.FillRectangle(B, rect);
> > }
> >
> > public void DrawBox(int intX, int intY, Color intColor)
> > {
> > Graphics g = PlayArea.CreateGraphics();
> > Pen P = new Pen(Color.Black);
> > SolidBrush B = new SolidBrush(intColor);
> >
> > Rectangle rect = new Rectangle(4 + intX * 20, 4 + intY * 20, 18,
18);
> >
> > g.FillRectangle(B, rect);
> > g.DrawRectangle(P, rect);
> > }
> >
> > // Block Manipulation Routines
> > public void DrawBlock(Block theBlock, string Directive)
> > {
> > int[,] WorkArray = new int[4, 2];
> > string[] WorkArray2;
> > string[] WorkArray3;
> >
> > int i;
> >
> > WorkArray2 =
> > System.Text.RegularExpressions.Regex.Split(theBlock.ReturnBlock(), "#");
> >
> > for(i = 0; i <= 3; i++)
> > {
> > WorkArray3 =
> > System.Text.RegularExpressions.Regex.Split(WorkArray2[i], ",");
> > WorkArray[i, 0] = Convert.ToInt16(WorkArray3[0]);
> > WorkArray[i, 1] = Convert.ToInt16(WorkArray3[1]);
> > }
> >
> > for( i = 0; i <= 3; i++ )
> > {
> > switch (Directive)
> > {
> > case "Clear":
> > ClearBox(WorkArray[i, 0], WorkArray[i, 1]);
> > InternalPlayArea[WorkArray[i, 0], WorkArray[i, 1]] = 0;
> > break;
> > case "Draw":
> > DrawBox(WorkArray[i, 0], WorkArray[i, 1],
> > theBlock.BlockColour);
> > InternalPlayArea[WorkArray[i, 0], WorkArray[i, 1]] =
> > theBlock.BlockColour.ToArgb();
> > break;
> > case "Lock":
> > DrawBox(WorkArray[i, 0], WorkArray[i, 1],
> > theBlock.BlockColour);
> > InternalPlayArea[WorkArray[i, 0], WorkArray[i, 1]] =
> > theBlock.BlockColour.ToArgb() - 1;
> > break;
> > }
> > }
> >
> > // Draw Stationary Blocks
> > for( i = 0; i <= PLAYAREAX; i++ )
> > {
> > for( int j = 0; j <= PLAYAREAY; j++ )
> > {
> > if( InternalPlayArea[i, j] != 0 )
> > DrawBox( i, j, Color.FromArgb(InternalPlayArea[i, j]) );
> > }
> > }
> >
> > DrawNextBlock();
> > }
> >
> > private bool CanMove(Block theblock, int intXdir, int intYdir)
> > {
> > int[,] WorkArray = new int[4, 2];
> > bool bCanMove;
> >
> > // Push coordinated to proposed ones
> > string[] WorkArray2;
> > string[] WorkArray3;
> >
> > WorkArray2 =
> > System.Text.RegularExpressions.Regex.Split(theblock.ReturnBlock(), "#");
> >
> > int i;
> >
> > for( i = 0; i <= 3; i++ )
> > {
> > WorkArray3 =
> > System.Text.RegularExpressions.Regex.Split(WorkArray2[i], ",");
> > WorkArray[i, 0] = Convert.ToInt16(WorkArray3[0]);
> > WorkArray[i, 1] = Convert.ToInt16(WorkArray3[1]);
> > }
> >
> > for( i = 0; i <= 3; i++ )
> > {
> > WorkArray[i, 0] = WorkArray[i, 0] + intXdir;
> > WorkArray[i, 1] = WorkArray[i, 1] + intYdir;
> > }
> >
> > // Perform Checks
> > bCanMove = true;
> >
> > // First check screen left/right boundaries
> > if( bCanMove == true )
> > {
> > for( i = 0; i <= 3; i++ )
> > {
> > if( (WorkArray[i, 0] < 0) || (WorkArray[i, 0] > PLAYAREAX) )
> > {
> > bCanMove = false;
> > }
> > }
> > }
> >
> > // Next check screen up/down boundaries
> > if( bCanMove == true )
> > {
> > for( i = 0; i <= 3; i++ )
> > {
> > if( (WorkArray[i, 1] < 0) || (WorkArray[i, 1] > PLAYAREAY) )
> > {
> > bCanMove = false;
> > }
> > }
> > }
> >
> > // Finally check if we trying to occupy a space which is already
full
> > if( bCanMove == true )
> > {
> > for( i = 0; i <= 3; i++ )
> > {
> > if( (InternalPlayArea[WorkArray[i, 0], WorkArray[i, 1]] != 0)
&&
> > (InternalPlayArea[WorkArray[i, 0], WorkArray[i, 1]] !=
> > theblock.BlockColour.ToArgb()) )
> > {
> > bCanMove = false;
> > }
> > }
> > }
> > return bCanMove;
> > }
> >
> > private void CheckForLine()
> > {
> > // Check lines by working from bottom up
> > int i;
> > int j;
> > int k;
> > int BoxCount;
> > int LineCount;
> >
> > // Color NewColor;
> > i = PLAYAREAY;
> > LineCount = 0;
> >
> > while( i > 0 )
> > {
> > BoxCount = 0;
> > for( j = 0; j <= PLAYAREAX; j++ )
> > {
> > if( InternalPlayArea[j, i] != 0 )
> > {
> > BoxCount++;
> > }
> > }
> >
> > if( BoxCount == 10 )
> > {
> > LineCount++;
> >
> > // Clear Line
> > for( k = i; k >= 1; k-- )
> > {
> > for( j = 0; j <= PLAYAREAX; j++ )
> > {
> > InternalPlayArea[j, k] = InternalPlayArea[j, k - 1];
> >
> > if( InternalPlayArea[j, k] == 0 )
> > {
> > ClearBox(j, k);
> > }
> > else
> > {
> > DrawBox(j, k, Color.FromArgb(InternalPlayArea[j, k]));
> > }
> > }
> > }
> > }
> > else
> > {
> > i--;
> > }
> > }
> >
> > switch (LineCount)
> > {
> > case 1: Score = Score + 10; break;
> > case 2: Score = Score + 50; break;
> > case 3: Score = Score + 250; break;
> > case 4: Score = Score + 400; break;
> > }
> >
> > Lines = Lines + LineCount;
> >
> > //Increase the speed every ten lines, down to 100ms
> > if( (Lines > 0) && (Timer1.Interval > 100) )
> > {
> > if( Lines >= ((Level * 10) + 10) )
> > {
> > Level++;
> > Timer1.Interval = Timer1.Interval - 50;
> > }
> > }
> >
> > txtScore.Text = System.String.Format(Score.ToString(), "#,##0");
> > txtLines.Text = System.String.Format(Lines.ToString(), "#,##0");
> > }
> >
> > private void InitGame()
> > {
> > GameOver.Visible = false;
> > Timer1.Enabled = false;
> >
> > for( int i = 0; i <= PLAYAREAX; i++ )
> > {
> > for( int j = 0; j <= PLAYAREAY; j++ )
> > {
> > InternalPlayArea[i, j] = 0;
> > }
> > }
> >
> > PlayArea.CreateGraphics().Clear(Color.White);
> >
> > Score = 0;
> > Lines = 0;
> > txtScore.Text = 0.ToString();
> > txtLines.Text = 0.ToString();
> >
> > this.KeyPreview = true;
> > }
> >
> > private void CreateNewBlock()
> > {
> > CurrentBlock = new Block();
> > CurrentBlock.Create();
> > CurrentBlock.CurrentX = 4;
> > CurrentBlock.CurrentY = 0;
> > }
> >
> > private void CreateNextBlock()
> > {
> > NextBlock = new Block();
> > NextBlock.Create();
> > NextBlock.CurrentX = 0;
> > NextBlock.CurrentY = 0;
> > }
> >
> > /*protected override void OnPaint(PaintEventArgs e)
> > {
> > if( CurrentBlock != null )
> > DrawBlock(CurrentBlock, "Draw");
> > }*/
> >
> > private void DrawNextBlock()
> > {
> > // Clear box
> > Graphics g = pictureBox1.CreateGraphics();
> > SolidBrush B = new SolidBrush(Color.White);
> >
> > Rectangle rect = new Rectangle(0,0,100,100);
> >
> > g.FillRectangle(B, rect);
> >
> > // Now draw next block
> > int[,] WorkArray = new int[4, 2];
> >
> > string[] WorkArray2 =
> > System.Text.RegularExpressions.Regex.Split(NextBlock.ReturnBlock(),
"#");
> >
> > for( int i = 0; i <= 3; i++ )
> > {
> > string[] WorkArray3 =
> > System.Text.RegularExpressions.Regex.Split(WorkArray2[i], ",");
> > WorkArray[i, 0] = Convert.ToInt16(WorkArray3[0]);
> > WorkArray[i, 1] = Convert.ToInt16(WorkArray3[1]);
> >
> > Pen P = new Pen(Color.Black);
> > B = new SolidBrush(NextBlock.BlockColour);
> >
> > rect = new Rectangle( 8+WorkArray[i, 0]*20,1+ WorkArray[i, 1]*20,
> > 18, 18);
> >
> > g.FillRectangle(B, rect);
> > g.DrawRectangle(P, rect);
> > }
> > }
> > }
> > }
> >
> >
> > //------ End of Form1.cs ------//
> >
> >
>
>
.
- Follow-Ups:
- Re: Redraw problem - please help
- From: Bob Powell [MVP]
- Re: Redraw problem - please help
- From: Bob Powell [MVP]
- Re: Redraw problem - please help
- References:
- Redraw problem - please help
- From: Publicjoe
- Re: Redraw problem - please help
- From: Bob Powell [MVP]
- Redraw problem - please help
- Prev by Date: Re: Redraw problem - please help
- Next by Date: Re: Redraw problem - please help
- Previous by thread: Re: Redraw problem - please help
- Next by thread: Re: Redraw problem - please help
- Index(es):
Loading