Home > Net >  Tetris, interface
Tetris, interface

Time:09-24

Public partial class Form1: Form
{
Private MyRect _currentMyRect;//are working in the square;
Private MyRect _nextMyRect;//the next square
Private Point startlocation=new Point (GameField. Length * 8, 0);
Private bool stillRuning=false;


Public _click ()
{
SetStyle (ControlStyles. UserPaint, true);
SetStyle (ControlStyles. AllPaintingInWmPaint, true);
InitializeComponent();
///InitGameData ();
}

Private void Form1_Load (object sender, EventArgs e)
{
GameField. Backcolor=pictureBox1. Backcolor;
GameField. WinHandle=pictureBox1. Handle;
Timer1. Interval=1000;

}

Private void Form1_Paint (object sender, PaintEventArgs e)
{



}
Private void Form1_Activated_1 (object sender, EventArgs e)
{
PictureBox1. Invalidate ();
Application.doevents ();
GameField. The Redraw ();
}


///
///rewrite ProcessDialogKey can press the keys identified
///

///
///
Protected override bool ProcessDialogKey (Keys keyData)
{

If (keyData=https://bbs.csdn.net/topics/=Keys. The Up | | keyData==Keys. Down | |

KeyData=https://bbs.csdn.net/topics/=Keys. Left | | keyData==Keys. Right)

return false;

The else

Return to base. ProcessDialogKey (keyData);

}
///
///whether buttons around and under the press, press the execution, the blank space key implement the transformation function,
///

///
///
Private void Form1_KeyDown (object sender, KeyEventArgs e)
{
The switch (e.K eyCode)
{
Case Keys. Down:
While (_currentMyRect. RDown ());
break;
Case Keys. Left:
_currentMyRect. RLeft ();
break;
Case Keys. Right:
_currentMyRect. RRight ();
break;
Deformation of case Keys. The Up://
_currentMyRect. RChange ();
break;
Case Keys. Space:
Timer1 Enabled=! Timer1. Enabled;
if (! Timer1. Enabled)
MessageBox. Show (" pause ");
break;
}
PictureBox1. Focus ();

}


///
///every time trigger, the first to arrive at the bottom, the second to refresh
///

///
///
Private void Timer1_Tick (object sender, EventArgs e)
{

if (! StillRuning)
return;
if (! _currentMyRect. RDown ())
{
//the game
If (_currentMyRect. The Top ()==0)
{
Timer1. Enabled=false;
Timer1. Stop ();
StillRuning=false;
MessageBox. Show (" game over ");
}

Int eraseLines=GameField. CheckLines ();
If (eraseLines & gt; 0)
{
PictureBox1. Invalidate ();
Application.doevents ();
GameField. The Redraw ();
}
_currentMyRect=new MyRect (startlocation, _nextMyRect _typeShape);
_currentMyRect. The Draw (GameField. WinHandle);
_nextMyRect=new MyRect (new Point (80, 50), _nextMyRect. _typeShape);
//_nextMyRect. The Draw (GameField. WinHandle);

}
_currentMyRect. RDown ();
//this. Invalidate ();
Thread.sleep (1000);
}
///
///start button is pressed, after constantly produce diamonds, and down square,
///

///
///
Private void btn_start_Click (object sender, EventArgs e)
{
//_list_All=new List (a);
If (_currentMyRect==null)
{
_currentMyRect=new MyRect startlocation, MyRect. TypeShape. (Undefined);
_currentMyRect. The Draw (GameField. WinHandle);
_nextMyRect=new MyRect (new Point (80, 50), MyRect. TypeShape. Undefined);
StillRuning=true;
Btn_start. Enabled=false;
//timer1. Enabled=true;
Timer1. Start ();
}
The else
{
Timer1. Enabled=true;
}

}
Private void stop_Click (object sender, EventArgs e)
{
Timer1. Stop ();
Timer1. The Dispose ();
//stop. Enabled=false;
Btn_start. Enabled=true;
Timer1. Enabled=false;
}
}
The class Square
{
Public Point _point;
Public Size _size;
Public Color _forecolor;
Public Color _backcolor;
Public Square (Size, Size, Color forecolor, Color backcolor)
{
_size=size;
_backcolor=backcolor;
_forecolor=forecolor;
}
Public void the Draw (IntPtr winHandle)
{
Graphics Graphics=Graphics. FromHwnd (winHandle);
GraphicsPath path=new GraphicsPath ();
A Rectangle Rectangle=new Rectangle (_point, _size);
Path. AddRectangle (rectangle);
Color colors=new Color [] [] {_backcolor};
PathGradientBrush pb=new PathGradientBrush (path);
Pb. CenterColor=_forecolor;
Pb. SurroundColors=colors;
Graphics. FillPath (pb, path);

}
Public void Erase (IntPtr winHandle)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#