C#编程设计说明.docx
《C#编程设计说明.docx》由会员分享,可在线阅读,更多相关《C#编程设计说明.docx(34页珍藏版)》请在冰点文库上搜索。
C#编程设计说明
荆楚理工学院
<>结课设计说明书
学生姓名:
姚元美梁贵波杨爽
学号:
10EN40401026120084040102482008404010238
专业:
计算机科学与技术
班级:
计算机08-2
任课教师:
游明坤
1.游戏编程
1.1.概述
1.1.1.完成任务
(1)程序运行界面如图1.1所示:
图1.1计算机信息查看器主界面
1.2.分析
1.2.1.功能分析
新局:
单击左侧会出现连连看游戏运行界面,进入游戏。
提示:
用户可以在找不到一样的图案的时候点击提示,会出现两个可以撤销的类似图案。
重排:
左边图案会重新编排一次。
配置:
用户可以对游戏的相关选项进行设置。
退出:
退出游戏。
1.2.2.界面分析
运行界面如下:
如图1.1所示,程序主体界面可分为三部分:
第一部分是以执行游戏的部分,第二部分是以游戏设置以及帮助的部分,第三部分就是游戏在运行时所剩时间提示。
第一部分含1个控件:
11个列表视图(listview)。
第二部分含8个控件:
6个按钮(button)2个标签(label)。
在2个label中,2个用于显示提示,1个复选项,分别用于显示相应的“详细信息”。
第三部分含3个控件:
1个label,1个显示提示,还有一个。
界面的详细布局如图1.1所示。
1.2.3.程序分析
本程序的核心是游戏执行部分,所有的操作都围绕着该数据进行的。
游戏分为三关:
简单、一般和难。
为了用户在规定时间完成一关,设计了提示和重排。
其中新局是开始游戏的意思,退出也就意味着结束游戏。
1.3.实现步骤
1.3.1.建立工程
建立C#Windows窗体应用程序Game项目。
1.3.2.界面设计
根据图1.1的样式,设计出查看器的窗体布局。
1.3.3.主程序功能实现
(1)定义主程序类对象GameMain。
(2)加载数据。
使用ComputerManager的Load方法从文件中加载信息,如果存在文件,则将文件中的计算机对象填充到ListView。
如果不存在,则创建不同类型的计算机,并添加到泛型集合中,填充到ListView中。
(3)窗体设计器生成的代码中的数据到Dispose:
privatevoidEndGame(),privatevoidWinGame()。
时间触发privatevoidtimeOutTimer_Tick(objectsender,EventArgse)。
(4)初始化集合泛型数据:
privatevoidInitGame()。
如果从本地文件加载泛型集合数据失败,则由程序初始化数据,填充到泛型集合。
(5)给下压式按钮添加事件处理。
1.4.核心代码
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Drawing;
usingSystem.IO;
usingSystem.Windows.Forms;
usingLLK.ACTION;
usingLLK.UI;
namespaceLLK
{
publicclassGameMain:
Form
{
privateIContainercomponents;
privateCheckBoxAutoClear;
privateTimerlineTimer;
privateButtonbtnReset;
privateButtonbtnInfo;
privateButtonbtnRePlay;
privateLabellbP;
privateLabellbInfoCount;
privateLabellabel3;
privateButtonbtnExit;
privateProgressBarpBar;
privateTimertimeOutTimer;
privateLabellbTimeOut;
privatePictureBoxpictureBox1;
privateLabellabel1;
privateLabellbCaption;
privateCheckBoxAutoReset;
privateButtonbtnAbout;
privateButtonbtnConfig;
privateScreenDrawSD=null;
privateLinesearch_p1=null;
privateLinesearch_p2=null;
privateboolisSearch=false;
privateintPointCount=0;
privateintInfoCount=5;
privateconstintGameTimeSec=60;
privateGameStategs=GameState.Start;
privateMap[]oMap=null;
privateLineManager[]LM=null;
privateScreenCursorcursor=null;
privateGameOption.Optionsoptions=newGameOption.Options();
privateScreenObjectSO=null;
privateBombPointbp1=newBombPoint();
privateBombPointbp2=newBombPoint();
privateSoundPlayListspl=newSoundPlayList();
privatestringappPath="";
privateSoundPlayerspBg;
privateSoundPlayerspBomb;
privateSoundPlayerspEarse;
privateSoundPlayerspRefresh;
privateSoundPlayerspSelect;
privateSoundPlayerspHint;
privateint[,]L=newint[3,3]{{28,22,16},{34,28,22},{39,34,28}};
privateTimerSplashTimer;
privateGameLoadingGL=null;
privateenumGameState
{
Start,
Play,
End,
Win
}
publicGameMain(GameLoadinggameLoading)
{
InitializeComponent();
this.GL=gameLoading;
}
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!
=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindows窗体设计器生成的代码
privatevoidInitializeComponent()
{
ponents=newContainer();
this.btnReset=newButton();
this.btnInfo=newButton();
this.AutoClear=newCheckBox();
this.lineTimer=newTimer(ponents);
this.btnRePlay=newButton();
this.label1=newLabel();
this.lbP=newLabel();
this.lbInfoCount=newLabel();
this.label3=newLabel();
this.btnExit=newButton();
this.pBar=newProgressBar();
this.lbTimeOut=newLabel();
this.timeOutTimer=newTimer(ponents);
this.pictureBox1=newPictureBox();
this.lbCaption=newLabel();
this.AutoReset=newCheckBox();
this.btnAbout=newButton();
this.btnConfig=newButton();
this.SplashTimer=newTimer(ponents);
this.SuspendLayout();
this.btnReset.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnReset.Location=newPoint(672,100);
this.btnReset.Name="btnReset";
this.btnReset.TabIndex=1;
this.btnReset.Text="重排";
this.btnReset.Click+=newEventHandler(this.btnReset_Click);
this.btnInfo.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnInfo.Location=newPoint(672,68);
this.btnInfo.Name="btnInfo";
this.btnInfo.TabIndex=2;
this.btnInfo.Text="提示";
this.btnInfo.Click+=newEventHandler(this.btnInfo_Click);
this.AutoClear.ForeColor=Color.Goldenrod;
this.AutoClear.Location=newPoint(672,136);
this.AutoClear.Name="AutoClear";
this.AutoClear.Size=newSize(80,24);
this.AutoClear.TabIndex=0;
this.AutoClear.Text="自动清除";
this.lineTimer.Interval=200;
this.lineTimer.Tick+=newEventHandler(this.lineTimer_Tick);
this.btnRePlay.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnRePlay.Location=newPoint(672,36);
this.btnRePlay.Name="btnRePlay";
this.btnRePlay.TabIndex=3;
this.btnRePlay.Text="新局";
this.btnRePlay.Click+=newEventHandler(this.btnRePlay_Click);
this.label1.AutoSize=true;
this.label1.ForeColor=Color.Goldenrod;
this.label1.Location=newPoint(672,204);
this.label1.Name="label1";
this.label1.Size=newSize(35,17);
this.label1.TabIndex=6;
this.label1.Text="得分:
";
this.lbP.AutoSize=true;
this.lbP.ForeColor=Color.Red;
this.lbP.Location=newPoint(672,228);
this.lbP.Name="lbP";
this.lbP.Size=newSize(11,17);
this.lbP.TabIndex=7;
this.lbP.Text="0";
this.lbInfoCount.AutoSize=true;
this.lbInfoCount.ForeColor=Color.Red;
this.lbInfoCount.Location=newPoint(672,280);
this.lbInfoCount.Name="lbInfoCount";
this.lbInfoCount.Size=newSize(11,17);
this.lbInfoCount.TabIndex=9;
this.lbInfoCount.Text="0";
this.label3.AutoSize=true;
this.label3.ForeColor=Color.Goldenrod;
this.label3.Location=newPoint(672,256);
this.label3.Name="label3";
this.label3.Size=newSize(60,17);
this.label3.TabIndex=8;
this.label3.Text="提示次数:
";
this.btnExit.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnExit.Location=newPoint(672,376);
this.btnExit.Name="btnExit";
this.btnExit.TabIndex=10;
this.btnExit.Text="退出";
this.btnExit.Click+=newEventHandler(this.btnExit_Click);
this.pBar.Location=newPoint(112,400);
this.pBar.Name="pBar";
this.pBar.Size=newSize(416,23);
this.pBar.TabIndex=11;
this.pBar.Value=100;
this.lbTimeOut.AutoSize=true;
this.lbTimeOut.ForeColor=Color.Goldenrod;
this.lbTimeOut.Location=newPoint(8,404);
this.lbTimeOut.Name="lbTimeOut";
this.lbTimeOut.Size=newSize(97,17);
this.lbTimeOut.TabIndex=12;
this.lbTimeOut.Text="剩余时间(60秒):
";
this.timeOutTimer.Interval=1000;
this.timeOutTimer.Tick+=newEventHandler(this.timeOutTimer_Tick);
this.pictureBox1.Location=newPoint(8,40);
this.pictureBox1.Name="pictureBox1";
this.pictureBox1.Size=newSize(630,330);
this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex=13;
this.pictureBox1.TabStop=false;
this.lbCaption.AutoSize=true;
this.lbCaption.ForeColor=Color.Lime;
this.lbCaption.Location=newPoint(8,8);
this.lbCaption.Name="lbCaption";
this.lbCaption.Size=newSize(116,17);
this.lbCaption.TabIndex=14;
this.lbCaption.Text="连连看赶快开始吧.";
this.AutoReset.ForeColor=Color.Goldenrod;
this.AutoReset.Location=newPoint(672,168);
this.AutoReset.Name="AutoReset";
this.AutoReset.Size=newSize(80,24);
this.AutoReset.TabIndex=15;
this.AutoReset.Text="自动重排";
this.AutoReset.Visible=false;
this.btnAbout.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnAbout.Location=newPoint(672,344);
this.btnAbout.Name="btnAbout";
this.btnAbout.TabIndex=16;
this.btnAbout.Text="关于";
this.btnAbout.Click+=newEventHandler(this.btnAbout_Click);
this.btnConfig.ForeColor=Color.FromArgb(((Byte)(192)),((Byte)(255)),((Byte)(255)));
this.btnConfig.Location=newPoint(672,312);
this.btnConfig.Name="btnConfig";
this.btnConfig.TabIndex=17;
this.btnConfig.Text="配置";
this.btnConfig.Click+=newEventHandler(this.btnConfig_Click);
this.SplashTimer.Enabled=true;
this.SplashTimer.Interval=500;
this.SplashTimer.Tick+=newEventHandler(this.SplashTimer_Tick);
this.AutoScaleBaseSize=newSize(6,14);
this.BackColor=Color.Black;
this.ClientSize=newSize(758,431);
this.Controls.Add(this.btnConfig);
this.Controls.Add(this.btnAbout);
this.Controls.Add(this.AutoReset);
this.Controls.Add(this.lbCaption);
this.Controls.Add(this.lbTimeOut);
this.Controls.Add(this.lbInfoCount);
this.Controls.Add(this.label3);
this.Controls.Add(this.lbP);
this.Controls.Add(this.label1);
this.Controls.Add(this.pBar);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnRePlay);
this.Controls.Add(this.AutoClear);
this.Controls.Add(this.btnInfo);
this.Controls.Add(this.btnReset);
this.Controls.Add(this.pictureBox1);
this.Cursor=Cursors.Default;
this.FormBorderStyle=FormBorderStyle.FixedDialog;
this.MaximizeBox=false;
this.Name="GameMain";
this.StartPosition=FormStartPosition.Ce