📄 gatetris.cs
字号:
}
}
private void gridPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawRectangle(SystemPens.ControlDark,0,0,gridPanel.Width-1,
gridPanel.Height-1);
}
private void controlPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(SystemPens.ControlDark,0,0,controlPanel.Width-1,0);
e.Graphics.DrawLine(SystemPens.ControlDark,controlPanel.Width-1,0,
controlPanel.Width-1,controlPanel.Height-1);
e.Graphics.DrawLine(SystemPens.ControlDark,0,controlPanel.Height-1,
controlPanel.ClientRectangle.Width-1,controlPanel.Height-1);
}
private void gridPanel_Resize(object sender, System.EventArgs e)
{
gridPanel.Width = grid.Width+2;
gridPanel.Height = grid.Height+2;
}
private void controlPanel_Resize(object sender, System.EventArgs e)
{
int width = Math.Max(6 * grid.settings.squareWidth + 18,130);
controlPanel.Width = width;
}
private void preview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(!grid.gameOver && grid.gameStarted)
DrawPreview(grid.GetNextFigure(), e.Graphics);
else
e.Graphics.Clear(controlPanel.BackColor);
}
void UpdateScore(object sender, EventArgs e)
{
int sc = grid.score;
int lin = grid.lines;
byte lev = grid.level;
score.Text = sc.ToString();
lines.Text = lin.ToString();
level.Text = "LEVEL " + lev.ToString();
}
void UpdateNextFigure(object sender, EventArgs e)
{
preview.Invalidate();
}
void NewGame(object sender, EventArgs e)
{
int lev = grid.settings.startLevel;
paused.Text = "Playing";
score.Text = "0";
lines.Text = "0";
level.Text = "LEVEL " + lev.ToString();
grid.lines = 0;
grid.Refresh();
grid.Focus();
}
void EndGame(object sender, EventArgs e)
{
paused.Text = "";
preview.Invalidate();
score.Text = "0";
lines.Text = "0";
level.Text = "";
//check if we have to add this player to the hall of fame
BestPlayersCollection coll = GetBestPlayers();
Player select = AddToBestPlayers(coll);
if(select != null)
{
//serialize and show top 10 players
coll.Save("Top10.dat");
ShowBestPlayers(select);
}
grid.lines = 0;
grid.score = 0;
grid.level = grid.settings.startLevel;
}
void PauseGame(object sender, EventArgs e)
{
if(grid.timer.Enabled)
{
paused.Text = "Playing";
}
else
{
paused.Text = "Paused";
}
}
#endregion
#region Properties
[Browsable(false)]
public TetrisGrid TetrisGrid
{
get{return grid;}
}
#endregion
#region 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.gridPanel = new System.Windows.Forms.Panel();
this.controlPanel = new System.Windows.Forms.Panel();
this.level = new System.Windows.Forms.Label();
this.lines = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.paused = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.preview = new System.Windows.Forms.Label();
this.sc = new System.Windows.Forms.Label();
this.score = new System.Windows.Forms.Label();
this.controlPanel.SuspendLayout();
this.SuspendLayout();
//
// gridPanel
//
this.gridPanel.Dock = System.Windows.Forms.DockStyle.Left;
this.gridPanel.DockPadding.All = 1;
this.gridPanel.Location = new System.Drawing.Point(2, 2);
this.gridPanel.Name = "gridPanel";
this.gridPanel.Size = new System.Drawing.Size(238, 468);
this.gridPanel.TabIndex = 0;
this.gridPanel.Resize += new System.EventHandler(this.gridPanel_Resize);
this.gridPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.gridPanel_Paint);
//
// controlPanel
//
this.controlPanel.Controls.AddRange(new System.Windows.Forms.Control[] {
this.level,
this.lines,
this.label1,
this.paused,
this.label2,
this.preview,
this.sc,
this.score});
this.controlPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.controlPanel.DockPadding.All = 1;
this.controlPanel.Location = new System.Drawing.Point(240, 2);
this.controlPanel.Name = "controlPanel";
this.controlPanel.Size = new System.Drawing.Size(262, 468);
this.controlPanel.TabIndex = 1;
this.controlPanel.Resize += new System.EventHandler(this.controlPanel_Resize);
this.controlPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.controlPanel_Paint);
//
// level
//
this.level.Dock = System.Windows.Forms.DockStyle.Bottom;
this.level.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.level.ForeColor = System.Drawing.Color.Brown;
this.level.Location = new System.Drawing.Point(1, 444);
this.level.Name = "level";
this.level.Size = new System.Drawing.Size(260, 23);
this.level.TabIndex = 8;
this.level.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lines
//
this.lines.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.lines.Location = new System.Drawing.Point(8, 56);
this.lines.Name = "lines";
this.lines.Size = new System.Drawing.Size(112, 16);
this.lines.TabIndex = 7;
this.lines.Text = "0";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 6;
this.label1.Text = "Lines:";
//
// paused
//
this.paused.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.paused.Location = new System.Drawing.Point(8, 192);
this.paused.Name = "paused";
this.paused.Size = new System.Drawing.Size(64, 23);
this.paused.TabIndex = 5;
this.paused.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.label2.Location = new System.Drawing.Point(8, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 24);
this.label2.TabIndex = 3;
this.label2.Text = "Next Figure:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// preview
//
this.preview.BackColor = System.Drawing.SystemColors.Control;
this.preview.Location = new System.Drawing.Point(8, 96);
this.preview.Name = "preview";
this.preview.Size = new System.Drawing.Size(112, 96);
this.preview.TabIndex = 2;
this.preview.Paint += new System.Windows.Forms.PaintEventHandler(this.preview_Paint);
//
// sc
//
this.sc.BackColor = System.Drawing.SystemColors.Control;
this.sc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.sc.Location = new System.Drawing.Point(8, 8);
this.sc.Name = "sc";
this.sc.Size = new System.Drawing.Size(48, 16);
this.sc.TabIndex = 1;
this.sc.Text = "Score:";
this.sc.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// score
//
this.score.BackColor = System.Drawing.SystemColors.Control;
this.score.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.score.Location = new System.Drawing.Point(8, 24);
this.score.Name = "score";
this.score.Size = new System.Drawing.Size(112, 16);
this.score.TabIndex = 0;
this.score.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// TetrisGridContainer
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.controlPanel,
this.gridPanel});
this.DockPadding.All = 2;
this.Name = "TetrisGridContainer";
this.Size = new System.Drawing.Size(504, 472);
this.controlPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
#region Fields
private System.Windows.Forms.Panel gridPanel;
private System.Windows.Forms.Panel controlPanel;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label score;
private System.Windows.Forms.Label preview;
private System.Windows.Forms.Label sc;
private System.Windows.Forms.Label paused;
private System.Windows.Forms.Label label2;
public TetrisGrid grid;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lines;
private System.Windows.Forms.Label level;
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -