C++俄罗斯方块程序设计详细说明.doc
文本预览下载声明
该实验制作的是小游戏----俄罗斯方块
1.可实现以下基本功能:
用户可自定义添加或删除方块样式及颜色;
用户可自定义修改游戏背景颜色及按键设置。
2.另增加了几个功能:
按键设置改变后点击保存,会弹出对话框提示“保存成功” ;
点击“开始”运行游戏,背景音乐自动播放,点击暂停后,背景音乐也随之停止;
每消除一行,会有特效声音提示消除成功;
根据消行多少会自动加分并显示。
游戏界面效果图如下:
配置窗体效果图如下:
砖块样式配置效果图如下:
游戏设计分为如下九个部分:
新建窗体“配置窗体”(TrmConfig)
添加TabControl控件
砖块样式配置
I.abel控件(lblMode)
点击“事件”,选择“Paint”
Graphics gp=e.Graphics;
gp.Clear(Color.Black);
Pen p=new Pen(Color.White);
for (int i=31;i155;i=i+31)
gp.DrawLine(p,1,i,155,i);
for (int i=31;i155;i=i+31)
gp.DrawLine(p,i,1,i,155);
SolidBrush s=new SolidBrush(blockColor);
for (int x=0;x5;x++)
{
for(int y=0;y5;y++)
{
if(struArr[x,y])
{
gp.FillRectangle(s,31*x+1,31*y+1,30,30);
}
}
}
点击“事件”,选择“MouseClick”
private bool[,] struArr=new bool[5,5];
private Color blockColor=Color.Red;
--------------------------------------------------------
if (e.Button!=MouseButtons.Left)
return;
int xPos,yPos;
xPos=e.X/31;
yPos=e.Y/31;
struArr[xPos,yPos]=!struArr[xPos,yPos];
bool b=struArr[xPos,yPos];
Graphics gp=lblMode.CreateGraphics();
SolidBrush s=new SolidBrush(b ? blockColor:Color.Black);
gp.FillRectangle(s,31*xPos+1,31*yPos+1,30,30);
gp.Dispose();
II.添加ColorDialog控件
添加label(lblColor)控件
点击“事件”,选择“click”
colorDialog1.ShowDialog();
blockColor=colorDialog1.Color;
lblColor.BackColor=colorDialog1.Color;
lblMode.Invalidate();
III.添加listView控件(lsvBlockSet)
点击“事件”,选择“ItemSelectionChanged”
if (e.IsSelected)
{
blockColor=Color.FromArgb(int.Parse(e.Item.SubItems[1].Text));
lblColor.BackColor=blockColor;
string s=e.Item.SubItems[0].Text;
for(int i=0;is.Length;i++)
{
struArr[i/5,i%5]=(s[i]==1)?true:false;
}
lblMode.Invalidate();
}
IV.“添加”按钮(btnAdd)bool isEmpty=false;
foreach (bool i in struArr)
{
if(i)
{
isEmpty=true;
break;
}
}
if (!isEmpty)
{
MessageBox.Show(图案为空,请先用鼠标点击左边窗口绘制图案!,提示窗口,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
StringBuilder sb=new StringBuilder(25);
foreach (bool i in struArr)
{
sb.Append(i?1:0);
}
string blockString=sb.ToString();
foreach(ListViewItem item in lsvBlockSet.Items)
{
if (item.SubItems
显示全部