using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace RussiaBlock
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblDisplay;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblPreSee;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem mnuStart;
private bool isGameOver;
private bool isNeedChange=false;
private RBlock currentRBlock;
private RBlock nextRBlock;
private string direction="";
private Block[,] area=new Block[20,31];
private Thread myThread;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lblDisplay = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblPreSee = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.mnuStart = new System.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lblDisplay
//
this.lblDisplay.BackColor = System.Drawing.Color.Black;
this.lblDisplay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblDisplay.Location = new System.Drawing.Point(16, 16);
this.lblDisplay.Name = "lblDisplay";
this.lblDisplay.Size = new System.Drawing.Size(400, 600);
this.lblDisplay.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblPreSee);
this.groupBox1.ForeColor = System.Drawing.Color.Lime;
this.groupBox1.Location = new System.Drawing.Point(432, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 152);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "方块预览";
//
// lblPreSee
//
this.lblPreSee.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.lblPreSee.Location = new System.Drawing.Point(8, 24);
this.lblPreSee.Name = "lblPreSee";
this.lblPreSee.Size = new System.Drawing.Size(112, 112);
this.lblPreSee.TabIndex = 0;
//
// groupBox2
//
this.groupBox2.ForeColor = System.Drawing.Color.Lime;
this.groupBox2.Location = new System.Drawing.Point(432, 216);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(128, 144);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "得分情况";
//
// groupBox3
//
this.groupBox3.ForeColor = System.Drawing.Color.Lime;
this.groupBox3.Location = new System.Drawing.Point(432, 432);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(128, 144);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "操作说明";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuStart});
this.menuItem1.Text = "Game";
//
// mnuStart
//
this.mnuStart.Index = 0;
this.mnuStart.Text = "Start";
this.mnuStart.Click += new System.EventHandler(this.mnuStart_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(570, 624);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.lblDisplay);
this.Controls.Add(this.groupBox3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "俄罗斯方块";
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void PlayGame()
{
while(!isGameOver)
{
Thread.Sleep(100);
lock(this)
{
ReduceLine();
this.lblDisplay.Refresh();
Graphics g=Graphics.FromHwnd(this.lblDisplay.Handle);
g.DrawRectangle(new Pen(Color.Green),0,0,397,597);
//消去一行
ReduceLine();
//画出已经到达底部的方块
for(int i=0;i<20;i++)
for(int j=1;j<31;j++)
{
if(area[i,j]!=null)
{
g.FillRectangle(new SolidBrush(area[i,j].BlockColor),area[i,j].BlockX,area[i,j].BlockY,20,20);
g.DrawRectangle(new Pen(Color.Red),area[i,j].BlockX,area[i,j].BlockY,20,20);
}
}
//画出方块
if(this.MoveDown())//当前是否可以下移方块
{
bool flagR=true;
bool flagL=true;
//判断能否进行左移
for(int t=0;t<this.currentRBlock.block.Length;t++)
{
///??????????????????
//area[this.currentRBlock.block[t].BlockX/20+1,29-this.currentRBlock.block[t].BlockY/20]!=null||
if(this.currentRBlock.block[t].BlockX/20<19)
if(area[this.currentRBlock.block[t].BlockX/20+1,29-this.currentRBlock.block[t].BlockY/20]!=null)
flagR=false;
if(this.currentRBlock.block[t].BlockX+20==400)
flagR=false;
}
for(int t=0;t<this.currentRBlock.block.Length;t++)
{
//area[this.currentRBlock.block[t].BlockX/20-1,29-this.currentRBlock.block[t].BlockY/20]!=null||
if(this.currentRBlock.block[t].BlockX/20>0)
if(area[this.currentRBlock.block[t].BlockX/20-1,29-this.currentRBlock.block[t].BlockY/20]!=null)
flagL=false;
if(this.currentRBlock.block[t].BlockX==0)
flagL=false;
}
for(int i=0;i<currentRBlock.block.Length;i++)
{
// MessageBox.Show(""+rblock.block.Length);
g.FillRectangle(new SolidBrush(currentRBlock.block[i].BlockColor),currentRBlock.block[i].BlockX,currentRBlock.block[i].BlockY,20,20);
g.DrawRectangle(new Pen(Color.Red),currentRBlock.block[i].BlockX,currentRBlock.block[i].BlockY,20,20);
currentRBlock.block[i].BlockY+=20;
//左右移动方块
if(this.direction=="Left")
{
if(flagL)
currentRBlock.block[i].BlockX-=20;
}
if(this.direction=="Right")
{
if(flagR)
currentRBlock.block[i].BlockX+=
C#俄罗斯方块小游戏(vs2003)
需积分: 0 171 浏览量
2008-06-06
12:38:44
上传
评论
收藏 70KB RAR 举报
dengcun
- 粉丝: 9
- 资源: 15