软件工程之二 俄罗斯方块
来源:互联网 发布:美丽折淘宝客辅助器 编辑:程序博客网 时间:2024/06/05 09:49
为方便阅读,特将下载链接放置到前面
附件:
游戏链接:http://pan.baidu.com/s/1bnbBXcb
游戏运行可能所需的运行库:http://rj.baidu.com/soft/detail/15910.html?ald
一、游戏前言
本游戏采用C#语言制作。因为C#语言的灵活性高,C#使得C++程序员可以高效的开发程序,而绝不损失C/C++原有的强大的功能。因为这种继承关系,C#与C/C++具有极大的相似性,熟悉类似语言的开发者可以很快的转向C#。C#只允许类的单继承,而通过接口实现多继承。这样,它能像Java一样方便。与此同时,C#面向对象的程度比Java高,其中的基本类型都是面向对象的,具有比Java更强大的功能,其执行速度比Java快。所以,用C#做同样的游戏既方便,又有比JAVA更快的运行效果。
二、功能需求
l 完成一个俄罗斯方块游戏的基本要求。即,游戏开始/暂停,方块生成,方块翻转,方块自动降落,方块手动加速下降。
l 计分系统:消除1行1分,一次消除2行3分,一次消除3行5分,一次消除4行8分。
l 画面背景修改。调用颜色修改类,实现背景颜色、方块颜色、边框颜色等颜色类的修改。
l 游戏的暂停。按空格键获取游戏中断,
l 方块及各种变换的需求:
本游戏需要有7种方块,而每种方块还可以进行旋转。每种方块每行每列最多只有4个小方块。可以将它们放在一个n*m的区域内,该区域可以看作是有许多个等面积小方块构成的区域,而这些区域的状态只有两种,被方块占据或空闲。因此,对于整个游戏区域的空间是占据或空闲,可以用一位数来标识。对于7种方块和它们旋转后的形态我们可以用不同的标识进行标记。对于旋转,游戏中所有方块都是按照逆时针旋转的规则进行的,而且在旋转过程中它们不会因为旋转而下降,总会保持在同一高度。任何方块经过一个旋转周期还会变回原型。
l 操作的需求:
向上键
产生方块旋转操作,方块并非任何情况都能旋转,如果旋转后与小方格矩阵显示的方块有冲突或超出边界时,均不能发生旋转。因此首先要判断是否有足够的空间进行旋转。然后选择是否旋转。
向下键
产生方块加速下落操作,如果方块已经到达游戏区域底部或者已经有其他方块遮挡,则方块停止下降。
向左键
产生下落方块左移操作。首先要判断此方块是否能够发生左移,当越界或被其他显示方块阻挡时,则不能左移。
向右键
产生下落方块右移操作。首先要判断此方块是否能够发生右移,当越界或被其他显示方块阻挡时,则不能右移。
三、游戏流程图
游戏运行驱动流程图:
四、游戏代码
由于游戏采用C#制作,根据C#的特性,给出所有代码也无法加载运行,所以游戏制作成exe文件在百度云上可供下载游玩。
游戏链接:http://pan.baidu.com/s/1bnbBXcb
游戏运行可能所需的运行库:http://rj.baidu.com/soft/detail/15910.html?ald
Main:
using System;
using System.Windows.Forms;
namespace 俄罗斯方块
{
internal sealed class Program
{
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
MainForm:(游戏界面编程)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace 俄罗斯方块
{
public partial class MainForm : Form
{
public static Label[,] juzhen_lbl=new Label[12,17] ;
public static bool[,] juzhen_Bool=new bool[12,17] ;
public MainForm()
{
InitializeComponent();
随机();
加载提示面板();
显示提示();
代替();
}
static public System.Drawing.Color 背景色=Color .Black;
static public System.Drawing.Color 前景色=Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
static public System.Drawing.Color 边框色=Color.LimeGreen;
static public System.Drawing.Color 提示色=Color.Green;
void MainFormLoad(object sender, EventArgs e)//排列矩阵,窗体加载时执行
{
for(int i=0;i<12;i++)
for(int j=0;j<17;j++)
{
juzhen_lbl[i,j]=new Label ();
juzhen_lbl[i,j].Size = new System.Drawing.Size(25, 25);//每个格子的大小
juzhen_lbl[i,j].Location = new System.Drawing.Point(i*26,j*26);//每个格子的位置
this.Controls.Add(juzhen_lbl[i,j]);
}
从新加载();
边框();
}
void 从新加载()
{
for(int i=1;i<=10;i++)
for(int j=1;j<=15;j++)
{
juzhen_Bool[i,j]=false;
juzhen_lbl[i,j].BackColor=背景色;
}
}
void 边框()
{
for(int i=0;i<12;i++) //设置边框与边框颜色
{
juzhen_Bool[i,16]=true;
juzhen_lbl[i,16].BackColor=边框色;
juzhen_lbl[i,0].BackColor=边框色;
}
for(int i=0;i<17;i++) //设置边框与边框颜色
{
juzhen_Bool[0,i]=true;
juzhen_lbl[0,i].BackColor=边框色;
juzhen_Bool[11,i]=true;
juzhen_lbl[11,i].BackColor=边框色;
}
}
int X=5,Y=1,x=5,y=1;
public void 刷新()
{
for(int i=1;i<=10;i++)
for(int j=1;j<=15;j++)
if(juzhen_Bool[i,j])
{
juzhen_lbl[i,j].BackColor=前景色;
}
边框();
}
public static Label[,] tishi=new Label[5,5];
void 加载提示面板()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
tishi[i,j]=new Label();
tishi[i,j].Size=new System.Drawing.Size(20,20);
tishi[i,j].Location = new System.Drawing.Point(i*21+320,j*21+20);
tishi[i,j].BackColor=提示色;
}
}
void 代替()
{
随机形状=随机形状_dt; T=T_dt; L=L_dt; 反L=反L_dt; Z=Z_dt; 反Z=反Z_dt; I=I_dt;
}
void Button1Click(object sender, EventArgs e)
{
//button3.BackgroundImage = global::俄罗斯方块2014_10_12.Resource1.e2;
timer1 .Enabled=!timer1 .Enabled;
if(button1.Text=="开始")
{
button1.Text="暂停";
}
else if(button1.Text=="暂停")
{
button1.Text="开始";
}
}
void Timer1Tick(object sender, EventArgs e)
{
Y++;
if(Y==2)
{
随机();
显示提示();
}
落下();
if(判断('下'))
{
timer2.Start();
timer1.Stop();
}
刷新();
}
//int 边界左,边界右,边界下=15;//左右边界判断;
protected override bool ProcessDialogKey( Keys keyData)
{
switch (keyData)
{
case Keys.Up:
if(判断('旋'))
{
旋转();
switch(随机形状)
{
case 1:
旋转(ref T,4);break;
case 3:
旋转(ref L,4);break;
case 4:
旋转(ref 反L,4);break;
case 5:
旋转(ref I,2);break;
case 6:
旋转(ref Z,2);break;
case 7:
旋转(ref 反Z,2);break;
}
落下();
}
break;
case Keys.Down:
if(!timer2.Enabled)
{
Y++;
if(Y==2)
{
随机();
显示提示();
}
落下();
if(判断('下'))
{
停止();
if(Y>2){
x=5;X=5;y=1;Y=1;代替();
}
else{
timer1.Stop();
DialogResult 游戏结束 = MessageBox.Show("游戏结束,恭喜您获得" + 分数 + "分。\n 请从新开始游戏\n\n制作人:伍蔚帆 刘冕\n \n 如有问题,请联系QQ:727208706 1365366987\n ");//默认自带OK按钮
if(游戏结束==DialogResult.OK)
{
从新开始();
}
}
}
刷新();
}
break;
case Keys.Left:
if(判断('左'))
{
X--;
落下();
if(判断('下'))
{
timer1.Stop();
timer2.Start();
}
刷新();
}
break;
case Keys.Right:
if(判断('右'))
{
X++;
落下();
if(判断('下'))
{
timer1.Stop();
timer2.Start();
}
刷新();
}
break;
case Keys.Space: //空格键
//timer1 .Enabled=!timer1 .Enabled;
Button1Click(null,null);
break;
}
return true;
}//调用键盘按键
void 旋转(ref int n,int m)//m为形状为n的种类个数;
{
if(n<m)
n++;
else
n=1;
}
int 时间=0 ;
void Timer2Tick(object sender, EventArgs e)
{
时间 ++;
if(时间>3)
{
if(判断('下'))
{
停止();
if(Y>2){
x=X=5;y=Y=1;代替();
timer1.Start();
timer2.Stop();
}
else{
timer1.Stop();
timer2.Stop();
DialogResult 游戏结束 = MessageBox.Show("游戏结束,恭喜您获得" + 分数 + "分。\n 请从新开始游戏\n\n制作人:伍蔚帆 刘冕\n \n 如有问题,请联系QQ:727208706 1365366987\n ");
if(游戏结束==DialogResult.OK)
{
从新开始();
}
}
}
else{
timer1.Start();
timer2.Stop();
}
时间=0;
}
}
void 从新开始()
{
x=5;X=5;y=1;Y=1;
从新加载();
随机();
显示提示();
代替();
分数=0;
textBox1.Text="得分:\r\n"+分数.ToString();
}
void Button2Click(object sender, EventArgs e)
{
timer1.Stop();
timer2.Stop();
从新开始();
}
void Button3Click(object sender, EventArgs e)
{
timer1.Stop();
游戏设置窗口 shezhi=new 游戏设置窗口();
shezhi.button3.BackColor=背景色;
shezhi.button4.BackColor=前景色;
shezhi.button5.BackColor=边框色;
shezhi.button6.BackColor=提示色;
shezhi.ShowDialog();
}
void Button3MouseEnter(object sender, EventArgs e)//鼠标进入button3时执行
{
button3.BackgroundImage = global::俄罗斯方块.Resource1.e2;
}
void Button3MouseLeave(object sender, EventArgs e)//鼠标离开button3时执行
{
button3.BackgroundImage = global::俄罗斯方块.Resource1.e1;
}
void Button3MouseDown(object sender, MouseEventArgs e)//鼠标按下
{
button3.BackgroundImage = global::俄罗斯方块.Resource1.e3;
}
void Button2MouseEnter(object sender, EventArgs e)//鼠标进入
{
button2.BackgroundImage = global::俄罗斯方块.Resource1.q2;
}
void Button2MouseLeave(object sender, EventArgs e)
{
button2.BackgroundImage = global::俄罗斯方块.Resource1.q1;
}
void Button2MouseDown(object sender, MouseEventArgs e)
{
button2.BackgroundImage = global::俄罗斯方块.Resource1.q3;
}
void Button2MouseUp(object sender, MouseEventArgs e)//鼠标弹起
{
button2.BackgroundImage = global::俄罗斯方块.Resource1.q2;
}
void Button1MouseEnter(object sender, EventArgs e)
{
button1.BackgroundImage = global::俄罗斯方块.Resource1.w2;
}
void Button1MouseLeave(object sender, EventArgs e)
{
button1.BackgroundImage = global::俄罗斯方块.Resource1.w1;
}
void Button1MouseDown(object sender, MouseEventArgs e)
{
button1.BackgroundImage = global::俄罗斯方块.Resource1.w3;
}
void Button1MouseUp(object sender, MouseEventArgs e)
{
button1.BackgroundImage = global::俄罗斯方块.Resource1.w2;
}
}
}
MainFormDes:(游戏界面按键连接)
namespace 俄罗斯方块
{
partial class MainForm
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// timer1
//
timer1.Interval = 500;
timer1.Tick += new System.EventHandler(this.Timer1Tick);
//
// button1
//
this.button1.BackgroundImage = global::俄罗斯方块.Resource1.w1;
this.button1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
this.button1.Location = new System.Drawing.Point(318, 400);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 35);
this.button1.TabIndex = 0;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1Click);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Button1MouseDown);
this.button1.MouseEnter += new System.EventHandler(this.Button1MouseEnter);
this.button1.MouseLeave += new System.EventHandler(this.Button1MouseLeave);
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Button1MouseUp);
//
// timer2
//
this.timer2.Tick += new System.EventHandler(this.Timer2Tick);
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.Control;
this.textBox1.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.textBox1.ForeColor = System.Drawing.Color.Black;
this.textBox1.Location = new System.Drawing.Point(318, 259);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(120, 52);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "得分:";
//
// button2
//
this.button2.BackgroundImage = global::俄罗斯方块.Resource1.q1;
this.button2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button2.Location = new System.Drawing.Point(318, 360);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 35);
this.button2.TabIndex = 4;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.Button2Click);
this.button2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Button2MouseDown);
this.button2.MouseEnter += new System.EventHandler(this.Button2MouseEnter);
this.button2.MouseLeave += new System.EventHandler(this.Button2MouseLeave);
this.button2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Button2MouseUp);
//
// label1
//
this.label1.Image = ((System.Drawing.Image)(resources.GetObject("label1.Image")));
this.label1.Location = new System.Drawing.Point(318, 106);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 150);
this.label1.TabIndex = 5;
//
// button3
//
this.button3.BackgroundImage = global::俄罗斯方块.Resource1.e1;
this.button3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button3.Location = new System.Drawing.Point(318, 320);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(120, 35);
this.button3.TabIndex = 6;
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.Button3Click);
this.button3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Button3MouseDown);
this.button3.MouseEnter += new System.EventHandler(this.Button3MouseEnter);
this.button3.MouseLeave += new System.EventHandler(this.Button3MouseLeave);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(441, 442);
this.Controls.Add(this.button3);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(447, 470);
this.MinimumSize = new System.Drawing.Size(447, 470);
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "俄罗斯方块";
this.Load += new System.EventHandler(this.MainFormLoad);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Timer timer2;
public static System.Windows.Forms.Timer timer1;
}
}
形状:(控制俄罗斯方块的移动和变形)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace 俄罗斯方块
{
public partial class MainForm : Form
{
Random 随机数=new Random ();int T,L,反L,I,Z,反Z,随机形状; int T_dt,L_dt,反L_dt,I_dt,Z_dt,反Z_dt,随机形状_dt;
void 随机()
{
随机形状_dt=随机数.Next(1,8);
switch(随机形状_dt)
{
case 1:T_dt=随机数.Next(1,5);break ;
case 2:break;//田字形不用。
case 3:L_dt=随机数.Next(1,5);break ;
case 4:反L_dt=随机数.Next(1,5);break ;
case 5:I_dt=随机数.Next(1,3);break ;
case 6:Z_dt=随机数.Next(1,3);break ;
case 7:反Z_dt=随机数.Next(1,3);break ;
}
}
void 形状(int x1,int y1,int x2,int y2,int x3,int y3, int X1,int Y1,int X2,int Y2,int X3,int Y3,char 消除)
{
if(消除=='随')
{
juzhen_lbl[x,y].BackColor=背景色;//
juzhen_lbl[x1,y1].BackColor=背景色;//int x1,int y1
juzhen_lbl[x2,y2].BackColor=背景色;//int x2,int y2
juzhen_lbl[x3,y3].BackColor=背景色;//int x3,int y3
juzhen_lbl[x=X,y=Y].BackColor=前景色;//
juzhen_lbl[X1,Y1].BackColor=前景色;// int X1,int Y1
juzhen_lbl[X2,Y2].BackColor=前景色;// int X2,int Y3
juzhen_lbl[X3,Y3].BackColor=前景色;// int X3,int Y3
}
else if(消除=='消')//旋转时先让原来的形状消除
{
juzhen_lbl[X,Y].BackColor=背景色;
juzhen_lbl[X1,Y1].BackColor=背景色;
juzhen_lbl[X2,Y2].BackColor=背景色;
juzhen_lbl[X3,Y3].BackColor=背景色;
}else if(消除=='提')
{
this.Controls.Remove(tishi[v,c]);
this.Controls.Remove(tishi[v1,c1]);
this.Controls.Remove(tishi[v2,c2]);
this.Controls.Remove(tishi[v3,c3]);
this.Controls.Add(tishi[v=X+(5-X)-3,c=Y]);
this.Controls.Add(tishi[v1=X1+(5-X)-3,c1=Y1]);
this.Controls.Add(tishi[v2=X2+(5-X)-3,c2=Y2]);
this.Controls.Add(tishi[v3=X3+(5-X)-3,c3=Y3]);
}
}//形状格子数为4个时用这个方法
int v=0,v1=0,v2=0,v3=0,c=0,c1=0,c2=0,c3=0;
bool 判断(int X1,int Y1,int X2,int Y2,int X3,int Y3,char b)//判断下、左、右一格是否为true;
{
switch(b)
{
case '下':return juzhen_Bool[X,Y+1] || //按方向键下键或自动下移时判断
juzhen_Bool[X1,Y1+1]||
juzhen_Bool[X2,Y2+1]||
juzhen_Bool[X3,Y3+1];
case '左':return ! juzhen_Bool[X-1,Y]&& //按左方向键时判断
! juzhen_Bool[X1-1,Y1]&&
! juzhen_Bool[X2-1,Y2]&&
! juzhen_Bool[X3-1,Y3];
case '右':return ! juzhen_Bool[X+1,Y]&& //按右方向键时判断
! juzhen_Bool[X1+1,Y1]&&
! juzhen_Bool[X2+1,Y2]&&
! juzhen_Bool[X3+1,Y3];
case '旋':return ! juzhen_Bool[X-1,Y-1]&& //按旋转键时判断
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X+1,Y+1];
default:return false;
}
}
void 停止(int X1,int Y1,int X2,int Y2,int X3,int Y3)//
{
juzhen_Bool[X,Y]=true;
juzhen_Bool[X1,Y1]=true;
juzhen_Bool[X2,Y2]=true;
juzhen_Bool[X3,Y3]=true;
}
void T字形上(char 消除)
{
形状(x-1,y, x+1,y, x,y-1, X-1,Y, X+1,Y, X,Y-1,消除);
}
void T字形右(char 消除)
{
形状(x,y-1, x,y+1, x+1,y, X,Y-1, X,Y+1, X+1,Y,消除);
}
void T字形下(char 消除)
{
形状(x,y-1, x+1,y-1, x-1,y-1, X,Y-1, X+1,Y-1, X-1,Y-1,消除);
}
void T字形左(char 消除)
{
形状(x-1,y, x,y+1, x,y-1, X-1,Y, X,Y+1, X,Y-1,消除);
}
void 田字形(char 消除)
{
形状(x,y-1, x+1,y-1, x+1,y, X,Y-1, X+1,Y-1, X+1,Y ,消除);
}
void L字形上(char 消除)
{
形状(x-1,y, x+1,y-1, x+1,y , X-1,Y, X+1,Y-1, X+1,Y ,消除);
}
void L字形右(char 消除)
{
形状(x,y-1, x,y+1, x+1,y+1 , X,Y-1, X,Y+1, X+1,Y+1 ,消除);
}
void L字形下(char 消除)
{
形状( x-1,y, x+1,y, x-1,y+1 , X-1,Y, X+1,Y, X-1,Y+1 ,消除);
}
void L字形左(char 消除)
{
形状( x-1,y-1, x,y-1, x,y+1, X-1,Y-1, X,Y-1, X,Y+1 ,消除);
}
void 反L字形上(char 消除)
{
形状(x-1,y, x-1,y-1, x+1,y , X-1,Y, X-1,Y-1, X+1,Y ,消除);
}
void 反L字形右(char 消除)
{
形状(x,y-1, x,y+1, x+1,y-1 , X,Y-1, X,Y+1, X+1,Y-1 ,消除);
}
void 反L字形下(char 消除)
{
形状( x-1,y, x+1,y, x+1,y+1 , X-1,Y, X+1,Y, X+1,Y+1 ,消除);
}
void 反L字形左(char 消除)
{
形状( x-1,y+1, x,y-1, x,y+1, X-1,Y+1, X,Y-1, X,Y+1 ,消除);
}
void I字形横(char 消除)
{
形状( x-1,y, x+1,y, x+2,y, X-1,Y, X+1,Y, X+2,Y ,消除);
}
void I字形竖(char 消除)
{
形状(x,y-1, x,y+1, x,y+2, X,Y-1, X,Y+1, X,Y+2,消除);
}
void Z字形横(char 消除)
{
形状(x-1,y-1, x,y-1, x+1,y, X-1,Y-1 , X,Y-1, X+1,Y,消除);
}
void Z字形竖(char 消除)
{
形状(x+1,y-1, x+1,y, x,y+1, X+1,Y-1, X+1,Y, X,Y+1,消除);
}
void 反Z字形横(char 消除)
{
形状(x,y-1, x+1,y-1, x-1,y, X,Y-1, X+1,Y-1, X-1,Y,消除);
}
void 反Z字形竖(char 消除)
{
形状(x-1,y-1, x-1,y, x,y+1, X-1,Y-1, X-1,Y, X,Y+1,消除);
}
void 落下()
{
switch(随机形状)
{
case 1:
switch(T)
{
case 1: T字形上('随');break;
case 2: T字形右('随');break;
case 3: T字形下('随');break;
case 4: T字形左('随');break;
default:break;
}break;
case 2:田字形('随');break;
case 3:
switch(L)
{
case 1:L字形上('随');break;
case 2:L字形右('随');break;
case 3:L字形下('随');break;
case 4:L字形左('随');break;
default:break;
}break;
case 4:
switch(反L)
{
case 1:反L字形上('随');break;
case 2:反L字形右('随');break;
case 3:反L字形下('随');break;
case 4:反L字形左('随');break;
default:break;
}break;
case 5:
switch(I)
{
case 1:I字形横('随');break;
case 2:I字形竖('随');break;
default:break;
}break;
case 6:
switch(Z)
{
case 1:Z字形横('随');break;
case 2:Z字形竖('随');break;
default:break;
}break;
case 7:
switch(反Z)
{
case 1:反Z字形横('随');break;
case 2:反Z字形竖('随');break;
default:break;
}break;
default:break;
}
}
void 显示提示()
{
switch(随机形状_dt)
{
case 1:
switch(T_dt)
{
case 1: T字形上('提');break;
case 2: T字形右('提');break;
case 3: T字形下('提');break;
case 4: T字形左('提');break;
default:break;
}break;
case 2:
田字形('提');break;
case 3:
switch(L_dt)
{
case 1:L字形上('提');break;
case 2:L字形右('提');break;
case 3:L字形下('提');break;
case 4:L字形左('提');break;
default:break;
}break;
case 4:
switch(反L_dt)
{
case 1:反L字形上('提');break;
case 2:反L字形右('提');break;
case 3:反L字形下('提');break;
case 4:反L字形左('提');break;
default:break;
}break;
case 5:
switch(I_dt)
{
case 1:I字形横('提');break;
case 2:I字形竖('提');break;
default:break;
}break;
case 6:
switch(Z_dt)
{
case 1:Z字形横('提');break;
case 2:Z字形竖('提');break;
default:break;
}break;
case 7:
switch(反Z_dt)
{
case 1:反Z字形横('提');break;
case 2:反Z字形竖('提');break;
default:break;
}break;
default:break;
}
}
void 旋转()
{
switch(随机形状)
{
case 1:
switch(T)
{
case 1:T字形上('消');break;
case 2:T字形右('消');break;
case 3:T字形下('消');break;
case 4:T字形左('消');break;
}break;
case 2:
break ;//田字形不用旋转。
case 3:
switch(L)
{
case 1:L字形上('消');break;
case 2:L字形右('消');break;
case 3:L字形下('消');break;
case 4:L字形左('消');break;
default:break;
}break;
case 4:
switch(反L)
{
case 1:反L字形上('消');break;
case 2:反L字形右('消');break;
case 3:反L字形下('消');break;
case 4:反L字形左('消');break;
default:break;
}break;
case 5:
switch(I)
{
case 1:I字形横('消');break;
case 2:I字形竖('消');break;
default:break;
}break;
case 6:
switch(Z)
{
case 1:Z字形横('消');break;
case 2:Z字形竖('消');break;
default:break;
}break;
case 7:
switch(反Z)
{
case 1:反Z字形横('消');break;
case 2:反Z字形竖('消');break;
default:break;
}break;
default:break;
}
}
bool 判断(char b)
{
switch(随机形状)
{
case 1:
switch(b)
{
case '下':
switch(T)
{
case 1:return 判断(X-1,Y, X+1,Y, X,Y-1,'下' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y,'下' );
case 3:return 判断(X,Y-1, X+1,Y-1, X-1,Y-1,'下' );
case 4:return 判断(X-1,Y, X,Y+1, X,Y-1,'下' );
default:return false;
};
case '左':
switch(T)
{
case 1:return 判断(X-1,Y, X+1,Y, X,Y-1,'左' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y,'左' );
case 3:return 判断(X,Y-1, X+1,Y-1, X-1,Y-1,'左');
case 4:return 判断(X-1,Y, X,Y+1, X,Y-1,'左' );
default:return false;
};
case '右':
switch(T)
{
case 1:return 判断(X-1,Y, X+1,Y, X,Y-1,'右' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y,'右' );
case 3:return 判断(X,Y-1, X+1,Y-1, X-1,Y-1,'右' );
case 4:return 判断(X-1,Y, X,Y+1, X,Y-1,'右' );
default:return false;
};
case '旋':
switch(T)
{
case 1:return 判断(0,0,0,0,0,0,'旋' )&&! juzhen_Bool[X,Y+1];
case 2:return 判断(0,0,0,0,0,0,'旋' )&&! juzhen_Bool[X-1,Y];
case 3:return 判断(0,0,0,0,0,0,'旋' )&&! juzhen_Bool[X,Y-1];
case 4:return 判断(0,0,0,0,0,0,'旋' )&&! juzhen_Bool[X+1,Y];
default:return false;
};
default:return false;
}
case 2:
switch(b)
{
case '下':return 判断(X,Y-1,X+1,Y-1,X+1,Y,'下');
case '左':return 判断(X,Y-1,X+1,Y-1,X+1,Y,'左');
case '右':return 判断(X,Y-1,X+1,Y-1,X+1,Y,'右');
default:return false;
}
case 3:
switch(b)
{
case '下':
switch(L)
{
case 1:return 判断(X-1,Y, X+1,Y-1, X+1,Y,'下' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y+1 ,'下' );
case 3:return 判断(X-1,Y, X+1,Y, X-1,Y+1,'下' );
case 4:return 判断(X-1,Y-1, X,Y-1, X,Y+1,'下' );
default:return false;
};
case '左':
switch(L)
{
case 1:return 判断(X-1,Y, X+1,Y-1, X+1,Y,'左' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y+1 ,'左' );
case 3:return 判断(X-1,Y, X+1,Y, X-1,Y+1,'左' );
case 4:return 判断(X-1,Y-1, X,Y-1, X,Y+1,'左' );
default:return false;
};
case '右':
switch(L)
{
case 1:return 判断(X-1,Y, X+1,Y-1, X+1,Y,'右' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y+1 ,'右' );
case 3:return 判断(X-1,Y, X+1,Y, X-1,Y+1,'右' );
case 4:return 判断(X-1,Y-1, X,Y-1, X,Y+1,'右' );
default:return false;
};
case '旋':
switch(L)
{
case 1:return ! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X-1,Y-1]&&
! juzhen_Bool[X,Y-1];
case 2:return ! juzhen_Bool[X-1,Y-1]&&
! juzhen_Bool[X-1,Y]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+1,Y-1];
case 3:return ! juzhen_Bool[X,Y-1]&&
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X-1,Y-1]&&
! juzhen_Bool[X+1,Y+1];
case 4:return ! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X-1,Y]&&
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X-1,Y+1];
default:return false;
};
default:return false;
}
case 4:
switch(b)
{
case '下':
switch(反L)
{
case 1:return 判断(X-1,Y, X-1,Y-1, X+1,Y,'下' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y-1 ,'下' );
case 3:return 判断(X-1,Y, X+1,Y, X+1,Y+1,'下' );
case 4:return 判断(X-1,Y+1, X,Y-1, X,Y+1,'下' );
default:return false;
}
case '左':
switch(反L)
{
case 1:return 判断(X-1,Y, X-1,Y-1, X+1,Y,'左' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y-1 ,'左' );
case 3:return 判断(X-1,Y, X+1,Y, X+1,Y+1,'左' );
case 4:return 判断(X-1,Y+1, X,Y-1, X,Y+1,'左' );
default:return false;
}
case '右':
switch(反L)
{
case 1:return 判断(X-1,Y, X-1,Y-1, X+1,Y,'右' );
case 2:return 判断(X,Y-1, X,Y+1, X+1,Y-1 ,'右' );
case 3:return 判断(X-1,Y, X+1,Y, X+1,Y+1,'右' );
case 4:return 判断(X-1,Y+1, X,Y-1, X,Y+1,'右' );
default:return false;
}
case '旋':
switch(反L)
{
case 1:return ! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X,Y-1];
case 2:return !juzhen_Bool [X-1,Y-1]&&
! juzhen_Bool[X-1,Y]&&
!juzhen_Bool [X-1,Y+1]&&
! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+1,Y+1];
case 3:return ! juzhen_Bool[X,Y-1]&&
!juzhen_Bool[X+1,Y-1]&&
!juzhen_Bool [X,Y+1]&&
!juzhen_Bool[X-1,Y-1]&&
!juzhen_Bool [X-1,Y+1];
case 4:return ! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X-1,Y]&&
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X-1,Y-1];
default:return false;
};
default:return false;
}
case 5:
switch(b)
{
case '下':
switch(I)
{
case 1:return 判断( X-1,Y, X+1,Y, X+2,Y,'下');
case 2:return 判断( X,Y-1, X,Y+1, X,Y+2,'下');
default:return false;
}
case '左':
switch(I)
{
case 1:return 判断( X-1,Y, X+1,Y, X+2,Y,'左');
case 2:return 判断( X,Y-1, X,Y+1, X,Y+2,'左');
default:return false;
}
case '右':
switch(I)
{
case 1:return 判断( X-1,Y, X+1,Y, X+2,Y,'右');
case 2:return 判断( X,Y-1, X,Y+1, X,Y+2,'右');
default:return false;
}
case '旋':
switch(I)
{
case 1:return ! juzhen_Bool[X-1,Y-1]&&
! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X,Y-1]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X+2,Y+1]&&
! juzhen_Bool[X,Y+2];
case 2:return ! juzhen_Bool[X-1,Y-1]&&
!juzhen_Bool [X-1,Y]&&
! juzhen_Bool[X+1,Y+1]&&
! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+2,Y]&&
!juzhen_Bool [X+1,Y+2];
default:return false;
}
default:return false;
}
case 6:
switch(b)
{
case '下':
switch(Z)
{
case 1:return 判断(X-1,Y-1,X,Y-1,X+1,Y,'下');
case 2:return 判断(X+1,Y-1,X+1,Y,X,Y+1,'下');
default:return false;
};
case '左':
switch(Z)
{
case 1:return 判断(X-1,Y-1,X,Y-1,X+1,Y,'左');
case 2:return 判断(X+1,Y-1,X+1,Y,X,Y+1,'左');
default:return false;
};
case '右':
switch(Z)
{
case 1:return 判断(X-1,Y-1,X,Y-1,X+1,Y,'右');
case 2:return 判断(X+1,Y-1,X+1,Y,X,Y+1,'右');
default:return false;
};
case '旋':
switch(Z)
{
case 1:if(Y>2)
return ! juzhen_Bool[X-1,Y-2]&&
! juzhen_Bool[X,Y-2]&&
! juzhen_Bool[X-1,Y]&&
! juzhen_Bool[X+1,Y-1]&&
! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X+1,Y+1];
else return false;
case 2:if(Y>1)
return ! juzhen_Bool[X,Y-1]&&
! juzhen_Bool[X+2,Y-1]&&
! juzhen_Bool[X-1,Y]&&
! juzhen_Bool[X+2,Y]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X+1,Y+1];
else return false;
default:return false;
};
default:return false;
}
case 7:
switch(b)
{
case '下':
switch(反Z)
{
case 1:return 判断(X,Y-1, X+1,Y-1, X-1,Y,'下');
case 2:return 判断(X-1,Y-1, X-1,Y, X,Y+1,'下');
default:return false;
};
case '左':
switch(反Z)
{
case 1:return 判断(X,Y-1, X+1,Y-1, X-1,Y,'左');
case 2:return 判断(X-1,Y-1, X-1,Y, X,Y+1,'左');
default:return false;
};
case '右':
switch(反Z)
{
case 1:return 判断(X,Y-1, X+1,Y-1, X-1,Y,'右');
case 2:return 判断(X-1,Y-1, X-1,Y, X,Y+1,'右');
default:return false;
};
case '旋':
switch(反Z)
{
case 1:if(Y>1)return !juzhen_Bool [X-1,Y-1]&&
! juzhen_Bool[X,Y-2]&&
! juzhen_Bool[X+1,Y-2]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X,Y+1]&&
! juzhen_Bool[X+1,Y];
else return false;
case 2:if(Y>1)return ! juzhen_Bool[X-2,Y-1]&&
! juzhen_Bool[X-2,Y]&&
! juzhen_Bool[X-1,Y+1]&&
! juzhen_Bool[X,Y-1]&&
! juzhen_Bool[X+1,Y]&&
! juzhen_Bool[X+1,Y+1];
else return false;
default:return false;
};
default:return false;
};
default:return false;
}
}
void 停止()
{
switch(随机形状)
{
case 1:
switch(T)
{
case 1:停止(X-1,Y, X+1,Y, X,Y-1);break;
case 2:停止(X,Y-1, X,Y+1, X+1,Y); break;
case 3:停止(X,Y-1, X+1,Y-1, X-1,Y-1);break;
case 4:停止(X-1,Y, X,Y+1, X,Y-1);break;
default:break;
}break;
case 2:
停止(X,Y-1, X+1,Y-1, X+1,Y);break;
case 3:
switch(L)
{
case 1:停止( X-1,Y, X+1,Y-1, X+1,Y);break;
case 2:停止( X,Y-1, X,Y+1, X+1,Y+1 ); break;
case 3:停止( X-1,Y, X+1,Y, X-1,Y+1);break;
case 4:停止( X-1,Y-1, X,Y-1, X,Y+1 );break;
default:break;
}break;
case 4:
switch(反L)
{
case 1:停止( X-1,Y, X-1,Y-1, X+1,Y );break;
case 2:停止( X,Y-1, X,Y+1, X+1,Y-1 ); break;
case 3:停止( X-1,Y, X+1,Y, X+1,Y+1);break;
case 4:停止( X-1,Y+1, X,Y-1, X,Y+1 );break;
default:break;
}break;
case 5:
switch(I)
{
case 1:停止( X-1,Y, X+1,Y, X+2,Y);break;
case 2:停止( X,Y-1, X,Y+1, X,Y+2); break;
default:break;
}break;
case 6:
switch(Z)
{
case 1:停止(X-1,Y-1, X,Y-1, X+1,Y);break;
case 2:停止(X+1,Y-1, X+1,Y ,X,Y+1);break;
default:break;
}break;
case 7:
switch(反Z)
{
case 1:停止(X,Y-1, X+1,Y-1, X-1,Y);break;
case 2:停止(X-1,Y-1, X-1,Y, X,Y+1);break;
default:break;
}break;
}
消除();
switch(消除行数)
{
case 1:分数+=1;break;
case 2:分数+=3;break;
case 3:分数+=5;break;
case 4:分数+=7;break;
}
消除行数=0;
textBox1.Text="得分:\r\n"+分数.ToString();
}
int 消除行数=0,分数=0;
void 消除()
{
for(int i=15;i>=1;i--)
{
bool b=true;
for(int j=1;j<=10;j++)
{
if(!juzhen_Bool[j,i])
{
b=false;
break;
}
}
if(b)
{
for(int k=i;k>=1;k--)
for(int l=1;l<=10;l++)
{
juzhen_Bool[l,k]=juzhen_Bool[l,k-1];
}
消除行数++;
消除();
}
}
for(int n=1;n<=10;n++)
for(int j=1;j<=15;j++)
if( juzhen_Bool[n,j])
{
juzhen_lbl[n,j].BackColor=前景色;
}
else
{
juzhen_lbl[n,j].BackColor=背景色;
juzhen_lbl[n,j].Image =null;
}
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// MainForm
//
this.ClientSize = new System.Drawing.Size(284, 261);
this.Name = "MainForm";
this.Load += new System.EventHandler(this.MainForm_Load);
this.ResumeLayout(false);
}
private void MainForm_Load(object sender, EventArgs e)
{
}
}
}
游戏设置:(用于游戏背景,难度的设置)
namespace 俄罗斯方块
{
partial class 游戏设置窗口
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.label5 = new System.Windows.Forms.Label();
this.button6 = new System.Windows.Forms.Button();
this.SuspendLayout();
// button1
//
this.button1.Location = new System.Drawing.Point(47, 226);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 28);
this.button1.TabIndex = 0;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1Click);
// button2
//
this.button2.Location = new System.Drawing.Point(144, 226);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 28);
this.button2.TabIndex = 1;
this.button2.Text = "取消";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.Button2Click);
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10F);
this.label1.Location = new System.Drawing.Point(43, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 2;
this.label1.Text = "背景色:";
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 10F);
this.label2.Location = new System.Drawing.Point(43, 65);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 2;
this.label2.Text = "前景色:";
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 10F);
this.label3.Location = new System.Drawing.Point(29, 97);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(93, 16);
this.label3.TabIndex = 2;
this.label3.Text = "边框颜色:";
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 10F);
this.label4.Location = new System.Drawing.Point(29, 161);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(93, 16);
this.label4.TabIndex = 2;
this.label4.Text = "游戏难度:";
// button3
//
this.button3.BackColor = System.Drawing.Color.Black;
this.button3.Location = new System.Drawing.Point(113, 27);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(126, 26);
this.button3.TabIndex = 3;
this.button3.UseVisualStyleBackColor = false;
this.button3.Click += new System.EventHandler(this.Button3Click);
// button4
//
this.button4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
this.button4.Location = new System.Drawing.Point(113, 59);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(126, 26);
this.button4.TabIndex = 3;
this.button4.UseVisualStyleBackColor = false;
this.button4.Click += new System.EventHandler(this.Button4Click);
// button5
//
this.button5.BackColor = System.Drawing.Color.LawnGreen;
this.button5.Location = new System.Drawing.Point(113, 91);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(126, 26);
this.button5.TabIndex = 3;
this.button5.UseVisualStyleBackColor = false;
this.button5.Click += new System.EventHandler(this.Button5Click);
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"低级",
"中级",
"高级"});
this.comboBox1.Location = new System.Drawing.Point(113, 159);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 4;
// label5
//
this.label5.Font = new System.Drawing.Font("宋体", 10F);
this.label5.Location = new System.Drawing.Point(14, 130);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(93, 16);
this.label5.TabIndex = 2;
this.label5.Text = "提示框颜色:";
// button6
//
this.button6.BackColor = System.Drawing.Color.Green;
this.button6.Location = new System.Drawing.Point(113, 124);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(126, 26);
this.button6.TabIndex = 3;
this.button6.UseVisualStyleBackColor = false;
this.button6.Click += new System.EventHandler(this.Button6Click);
// 游戏设置窗口
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(259, 266);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "游戏设置窗口";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "游戏设置窗口";
this.Load += new System.EventHandler(this.游戏设置窗口Load);
this.ResumeLayout(false);
}
public System.Windows.Forms.Button button6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.ComboBox comboBox1;
public System.Windows.Forms.Button button5;
public System.Windows.Forms.Button button4;
public System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
}
}
游戏设置窗口:(由所画图形vs2012自动设置,最后根据所需修改)
using System;
using System.Drawing;
using System.Windows.Forms;
namespace 俄罗斯方块
{
/// Description of 游戏设置窗口.
public partial class 游戏设置窗口 : Form
{
public 游戏设置窗口()
{
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private void yanse(Button anniu)
{
colorDialog1.SolidColorOnly=true;
colorDialog1.ShowDialog();
anniu.BackColor=colorDialog1.Color;
}
public void 提示面板刷新()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
MainForm .tishi[i,j].BackColor=button6.BackColor;
}
}
public void 游戏面板刷新()
{
for(int i=1;i<=10;i++)
for(int j=1;j<=15;j++)
if(MainForm.juzhen_Bool[i,j])
{
MainForm.juzhen_lbl[i,j].BackColor=button4.BackColor;
}
else{
MainForm.juzhen_lbl[i,j].BackColor=button3.BackColor;
}
}
void 边框刷新()
{
for(int i=0;i<12;i++) //设置边框与边框颜色
{
MainForm.juzhen_lbl[i,16].BackColor=button5.BackColor;
MainForm.juzhen_lbl[i,0].BackColor=button5.BackColor;
}
for(int i=0;i<17;i++) //设置边框与边框颜色
{
MainForm.juzhen_lbl[0,i].BackColor=button5.BackColor;
MainForm.juzhen_lbl[11,i].BackColor=button5.BackColor;
}
}
void 游戏设置窗口Load(object sender, EventArgs e)
{
}
void Button3Click(object sender, EventArgs e)//背景色
{
yanse(button3);
}
void Button4Click(object sender, EventArgs e)//前景色
{
yanse(button4);
}
void Button5Click(object sender, EventArgs e)//边框色
{
yanse(button5);
}
void Button6Click(object sender, EventArgs e)//提示框颜色
{
yanse(button6);
}
void Button1Click(object sender, EventArgs e)
{
switch(comboBox1.SelectedIndex)
{
case 0:MainForm .timer1.Interval=500;break;
case 1:MainForm.timer1.Interval=250;break ;
case 2:MainForm .timer1.Interval =150;break ;
default:break;
}
MainForm.背景色=button3.BackColor;
MainForm.前景色=button4.BackColor;
MainForm.边框色=button5.BackColor;
MainForm.提示色=button6.BackColor;
提示面板刷新();
游戏面板刷新();
边框刷新 ();
this.Close();
}
void Button2Click(object sender, EventArgs e)
{
this.Close();
}
}
}
program:(按钮转换连接功能,加载按钮图片,并在按动时启动相应的功能)
namespace 俄罗斯方块 {
using System;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource1 {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource1() {
}
/// 返回此类使用的缓存的 ResourceManager 实例。
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("俄罗斯方块.Resource1", typeof(Resource1).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap e1 {
get {
object obj = ResourceManager.GetObject("e1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap e2 {
get {
object obj = ResourceManager.GetObject("e2", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap e3 {
get {
object obj = ResourceManager.GetObject("e3", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap q1 {
get {
object obj = ResourceManager.GetObject("q1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap q2 {
get {
object obj = ResourceManager.GetObject("q2", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap q3 {
get {
object obj = ResourceManager.GetObject("q3", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap w1 {
get {
object obj = ResourceManager.GetObject("w1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap w2 {
get {
object obj = ResourceManager.GetObject("w2", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
internal static System.Drawing.Bitmap w3 {
get {
object obj = ResourceManager.GetObject("w3", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
五、 游戏运行效果
· 游戏画面:
六、心得体会
通过这次的C#游戏编程,我对C#这门新的语言有了一定的了解。它相对于C/C++和JAVA来说,有他们共有的面向对象和面向过程的综合优势。其编程的自由度高,灵活性强。在以后的学习中,可以考虑用C#进行其他平台的游戏制作。
在这次的编程中,我们认识到前期工作很重要,所以这次的编程,我们没有同以前一样,编写一个个函数去实现一个个功能。而是,先对将要完成的功能进行细化,进行提前规划。这样编写程序的思路清晰,不会出现大量重复修改过大增加工作量的情况。
制作人:伍蔚帆 刘冕- 软件工程之二 俄罗斯方块
- 软件工程第二次二人协作项目 3D俄罗斯方块
- 软件工程笔记之二
- 软件工程之二系统分析
- 软件工程之二系统分析
- 俄罗斯方块之二——Game类
- 多库俄罗斯方块之二(VB.net)
- 俄罗斯方块之二授课计划总体规划
- 软件工程作业二——结对编程(用HTML5搭建3D俄罗斯方块)
- 软件工程习题200题之二
- 软件工程习题200题之二
- 我的软件工程之路(二)
- 软件工程之二——软件计划
- 俄罗斯方块游戏设计——不拘一格编程序之二
- 二. 软件工程
- MFC实现俄罗斯方块二
- 自己动手写俄罗斯方块(二)
- shell写俄罗斯方块二
- 如何完善职业生涯?
- Hello World
- java经验之谈
- EHCache 在WEB项目的用法
- 使用JsonCpp读写Json数据
- 软件工程之二 俄罗斯方块
- 前台防止表单重复提交的方法。Jquery、js
- OC-消息通知
- javascript String 转 Date备注
- linux configure: error: xml2-config not found. Please check your libxml2 installation
- android的窗口机制分析------UI管理系统
- 给 Xen 虚拟机添加一个网络接口
- 在ListView中添加item为WebView
- asp.net web api帮助生成插件