C#编程结课设计说明书

上传人:仙*** 文档编号:33886960 上传时间:2021-10-19 格式:DOC 页数:24 大小:436KB
返回 下载 相关 举报
C#编程结课设计说明书_第1页
第1页 / 共24页
C#编程结课设计说明书_第2页
第2页 / 共24页
C#编程结课设计说明书_第3页
第3页 / 共24页
点击查看更多>>
资源描述
荆楚理工学院结课设计说明书学生姓名:姚元美 梁贵波 杨爽学 号:10EN404010261 2008404010248 2008404010238专 业:计算机科学与技术班 级:计算机08-2任课教师:游明坤241. 游戏编程1.1. 概述1.1.1. 完成任务(1) 程序运行界面如图1.1所示:图1.1 计算机信息查看器主界面1.2. 分析1.2.1. 功能分析新局:单击左侧会出现连连看游戏运行界面,进入游戏。提示:用户可以在找不到一样的图案的时候点击提示,会出现两个可以撤销的类似图案。重排:左边图案会重新编排一次。配置:用户可以对游戏的相关选项进行设置。退出:退出游戏。1.2.2. 界面分析运行界面如下:如图1.1所示,程序主体界面可分为三部分:第一部分是以执行游戏的部分,第二部分是以游戏设置以及帮助的部分,第三部分就是游戏在运行时所剩时间提示。第一部分含1个控件:11个列表视图(list view)。第二部分含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:private void EndGame(),private void WinGame()。时间触发private void timeOutTimer_Tick(object sender, EventArgs e)。(4)初始化集合泛型数据:private void InitGame()。如果从本地文件加载泛型集合数据失败,则由程序初始化数据,填充到泛型集合。(5)给下压式按钮添加事件处理。1.4. 核心代码using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.IO;using System.Windows.Forms;using LLK.ACTION;using LLK.UI;namespace LLKpublic class GameMain : Formprivate IContainer components;private CheckBox AutoClear;private Timer lineTimer;private Button btnReset;private Button btnInfo;private Button btnRePlay;private Label lbP;private Label lbInfoCount;private Label label3;private Button btnExit;private ProgressBar pBar;private Timer timeOutTimer;private Label lbTimeOut;private PictureBox pictureBox1;private Label label1;private Label lbCaption;private CheckBox AutoReset;private Button btnAbout;private Button btnConfig;private ScreenDraw SD = null;private Line search_p1 = null;private Line search_p2 = null;private bool isSearch = false;private int PointCount = 0;private int InfoCount = 5;private const int GameTimeSec = 60;private GameState gs = GameState.Start;private Map oMap = null;private LineManager LM = null;private ScreenCursor cursor = null;private GameOption.Options options = new GameOption.Options();private ScreenObject SO = null;private BombPoint bp1 = new BombPoint();private BombPoint bp2 = new BombPoint();private SoundPlayList spl = new SoundPlayList();private string appPath = ;private SoundPlayer spBg;private SoundPlayer spBomb;private SoundPlayer spEarse;private SoundPlayer spRefresh;private SoundPlayer spSelect;private SoundPlayer spHint;private int, L = new int3,3 28, 22, 16, 34, 28, 22, 39, 34, 28;private Timer SplashTimer;private GameLoading GL = null;private enum GameStateStart,Play,End,Winpublic GameMain(GameLoading gameLoading)InitializeComponent();this.GL = gameLoading;protected override void Dispose(bool disposing)if (disposing)if (components != null)components.Dispose();base.Dispose(disposing);#region Windows 窗体设计器生成的代码private void InitializeComponent()ponents = new Container();this.btnReset = new Button();this.btnInfo = new Button();this.AutoClear = new CheckBox();this.lineTimer = new Timer(ponents);this.btnRePlay = new Button();this.label1 = new Label();this.lbP = new Label();this.lbInfoCount = new Label();this.label3 = new Label();this.btnExit = new Button();this.pBar = new ProgressBar();this.lbTimeOut = new Label();this.timeOutTimer = new Timer(ponents);this.pictureBox1 = new PictureBox();this.lbCaption = new Label();this.AutoReset = new CheckBox();this.btnAbout = new Button();this.btnConfig = new Button();this.SplashTimer = new Timer(ponents);this.SuspendLayout();this.btnReset.ForeColor = Color.FromArgb(Byte) (192), (Byte) (255), (Byte) (255);this.btnReset.Location = new Point(672, 100);this.btnReset.Name = btnReset;this.btnReset.TabIndex = 1;this.btnReset.Text = 重排;this.btnReset.Click += new EventHandler(this.btnReset_Click);this.btnInfo.ForeColor = Color.FromArgb(Byte) (192), (Byte) (255), (Byte) (255);this.btnInfo.Location = new Point(672, 68);this.btnInfo.Name = btnInfo;this.btnInfo.TabIndex = 2;this.btnInfo.Text = 提示;this.btnInfo.Click += new EventHandler(this.btnInfo_Click);this.AutoClear.ForeColor = Color.Goldenrod;this.AutoClear.Location = new Point(672, 136);this.AutoClear.Name = AutoClear;this.AutoClear.Size = new Size(80, 24);this.AutoClear.TabIndex = 0;this.AutoClear.Text = 自动清除;this.lineTimer.Interval = 200;this.lineTimer.Tick += new EventHandler(this.lineTimer_Tick);this.btnRePlay.ForeColor = Color.FromArgb(Byte) (192), (Byte) (255), (Byte) (255);this.btnRePlay.Location = new Point(672, 36);this.btnRePlay.Name = btnRePlay;this.btnRePlay.TabIndex = 3;this.btnRePlay.Text = 新局;this.btnRePlay.Click += new EventHandler(this.btnRePlay_Click);this.label1.AutoSize = true;this.label1.ForeColor = Color.Goldenrod;this.label1.Location = new Point(672, 204);this.label1.Name = label1;this.label1.Size = new Size(35, 17);this.label1.TabIndex = 6;this.label1.Text = 得分:;this.lbP.AutoSize = true;this.lbP.ForeColor = Color.Red;this.lbP.Location = new Point(672, 228);this.lbP.Name = lbP;this.lbP.Size = new Size(11, 17);this.lbP.TabIndex = 7;this.lbP.Text = 0; this.lbInfoCount.AutoSize = true;this.lbInfoCount.ForeColor = Color.Red;this.lbInfoCount.Location = new Point(672, 280);this.lbInfoCount.Name = lbInfoCount;this.lbInfoCount.Size = new Size(11, 17);this.lbInfoCount.TabIndex = 9;this.lbInfoCount.Text = 0;this.label3.AutoSize = true;this.label3.ForeColor = Color.Goldenrod;this.label3.Location = new Point(672, 256);this.label3.Name = label3;this.label3.Size = new Size(60, 17);this.label3.TabIndex = 8;this.label3.Text = 提示次数:;this.btnExit.ForeColor = Color.FromArgb(Byte) (192), (Byte) (255), (Byte) (255);this.btnExit.Location = new Point(672, 376);this.btnExit.Name = btnExit;this.btnExit.TabIndex = 10;this.btnExit.Text = 退出;this.btnExit.Click += new EventHandler(this.btnExit_Click);this.pBar.Location = new Point(112, 400);this.pBar.Name = pBar;this.pBar.Size = new Size(416, 23);this.pBar.TabIndex = 11;this.pBar.Value = 100;this.lbTimeOut.AutoSize = true;this.lbTimeOut.ForeColor = Color.Goldenrod;this.lbTimeOut.Location = new Point(8, 404);this.lbTimeOut.Name = lbTimeOut;this.lbTimeOut.Size = new Size(97, 17);this.lbTimeOut.TabIndex = 12;this.lbTimeOut.Text = 剩余时间(60秒):; this.timeOutTimer.Interval = 1000;this.timeOutTimer.Tick += new EventHandler(this.timeOutTimer_Tick);this.pictureBox1.Location = new Point(8, 40);this.pictureBox1.Name = pictureBox1;this.pictureBox1.Size = new Size(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 = new Point(8, 8);this.lbCaption.Name = lbCaption;this.lbCaption.Size = new Size(116, 17);this.lbCaption.TabIndex = 14;this.lbCaption.Text = 连连看 赶快开始吧.;this.AutoReset.ForeColor = Color.Goldenrod;this.AutoReset.Location = new Point(672, 168);this.AutoReset.Name = AutoReset;this.AutoReset.Size = new Size(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 = new Point(672, 344);this.btnAbout.Name = btnAbout;this.btnAbout.TabIndex = 16;this.btnAbout.Text = 关于;this.btnAbout.Click += new EventHandler(this.btnAbout_Click);this.btnConfig.ForeColor = Color.FromArgb(Byte) (192), (Byte) (255), (Byte) (255);this.btnConfig.Location = new Point(672, 312);this.btnConfig.Name = btnConfig;this.btnConfig.TabIndex = 17;this.btnConfig.Text = 配置;this.btnConfig.Click += new EventHandler(this.btnConfig_Click);this.SplashTimer.Enabled = true;this.SplashTimer.Interval = 500;this.SplashTimer.Tick += new EventHandler(this.SplashTimer_Tick);this.AutoScaleBaseSize = new Size(6, 14);this.BackColor = Color.Black;this.ClientSize = new Size(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.CenterScreen;this.Text = GameMain;this.Load += new EventHandler(this.GameMain_Load);this.MouseUp += new MouseEventHandler(this.GameMain_MouseUp);this.Paint += new PaintEventHandler(this.GameMain_Paint);this.MouseMove += new MouseEventHandler(this.GameMain_MouseMove);this.ResumeLayout(false);#endregion/ / 应用程序的主入口点。/ STAThreadprivate static void Main()GameLoading GL = new GameLoading();GL.Show();Application.Run(new GameMain(GL);private void GameMain_Load(object sender, EventArgs e)appPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf();this.Hide();GL.Refresh();GL.UpdateLoadingInfo(正在初始化地图.);oMap = new Map3;GL.UpdateLoadingInfo(初始化地图.完成,正在初始化连线管理.);LM = new LineManager3;GL.UpdateLoadingInfo(初始化连线管理.完成,正在初始化光标和配置档案.);cursor = new ScreenCursor();GameOption go = new GameOption(this.spl);options = go.ReadOption();go.Dispose();GL.UpdateLoadingInfo(初始化光标和配置档案.完成,正在初始化素材数据.);SO = new ScreenObject();GL.UpdateLoadingInfo(初始化素材数据.完成,正在分配元素.);oMap0 = new Map(SO, 39, 0, 0);oMap1 = new Map(SO, 34, 0, 0);oMap2 = new Map(SO, 28, 0, 0);GL.UpdateLoadingInfo(分配元素.完成,正在计算路径.);LM0 = new LineManager(oMap0);LM1 = new LineManager(oMap1);LM2 = new LineManager(oMap2);SD = new ScreenDraw(this.CreateGraphics(), Map.TileRowCount*Map.TileWidth, Map.TileColCount*Map.TileHeight);search_p1 = new Line();search_p2 = new Line();this.Text = 连连看 第一版 by S.F.;trythis.pictureBox1.Image = Image.FromFile(appPath + ImagesWelCome.jpg);catchMessageBox.Show(缺少资源目录!, 请到安装目录内运行!, MessageBoxButtons.OK, MessageBoxIcon.Information);this.Close();GL.UpdateLoadingInfo(计算路径.完成,正在初始化声音档案.);/spl.Add(.Soundsbg-01.mid);/spl.Add(.Soundsbg-02.mid);/spl.Add(.Soundsbg-03.mid);/spl.Add(.Soundsbg-04.mp3);spBg = new SoundPlayer(spl.CurrentMusic(), bg);GL.UpdateLoadingInfo(初始化背景音乐完成.);spBomb = new SoundPlayer(appPath + Soundsbomb.wav, bomb);GL.UpdateLoadingInfo(初始化爆炸音效完成.);spEarse = new SoundPlayer(appPath + SoundsEarse.wav, earse);GL.UpdateLoadingInfo(初始化连线音效完成.);spRefresh = new SoundPlayer(appPath + Soundsrefresh.wav, refresh);GL.UpdateLoadingInfo(初始化刷新音效完成.);spSelect = new SoundPlayer(appPath + Soundsselect.wav, select);GL.UpdateLoadingInfo(初始化选择音效完成.);spHint = new SoundPlayer(appPath + Soundshint.wav, hint);GL.UpdateLoadingInfo(游戏初始化完毕!);/GL.Close();/GL.Dispose();/GL =null;private void InitGame()/3分钟pBar.Maximum = GameTimeSec;pBar.Minimum = 0;pBar.Value = pBar.Maximum;this.InfoCount = 5;this.PointCount = 0;if (File.Exists(appPath + chinasf)this.InfoCount = 5000;pictureBox1.Hide();lbCaption.Hide();for (int i = 0; i = 0; i-)if (oMapi.GetCount() 0)oMapTilei = oMapi.TranPointToMapTile(e.X, e.Y);if (oMapTilei != null)if (oMapTilei.XIndex = 0 | oMapTilei.YIndex = 0 | oMapTilei.XIndex = Map.TileRowCount - 1 | oMapTilei.YIndex = Map.TileColCount - 1 | oMapTilei.ID = 0)return;elseif (oMapoMap.Length - 1.GetCount() 0)if (i = 0; i-)if (LMi.TestLink(out findPathPoints, out trunCount)oMapi.DrawPathPoints(SD.Surface(), findPathPoints);/*绘制爆炸效果*/bp1.CurrentMap = oMapi;bp2.CurrentMap = oMapi;bp1.CurrentPoint = new Point(LMi.Items(LMi.Count - 1).X, LMi.Items(LMi.Count - 1).Y);bp2.CurrentPoint = new Point(LMi.Items(LMi.Count - 2).X, LMi.Items(LMi.Count - 2).Y);bp1.CurrentSurface = SD.Image();bp2.CurrentSurface = SD.Image();MapTile oMapTile1 = bp1.CurrentMap.MapViewbp1.CurrentPoint.X, bp1.CurrentPoint.Y;MapTile oMapTile2 = bp2.CurrentMap.MapViewbp2.CurrentPoint.X, bp2.CurrentPoint.Y;if (oMapTile1 != null)Bitmap b1 = bp1.CurrentMap.DrawBombEff(bp1.CurrentSurface, 5, oMapTile1);SD.Surface().DrawImage(Image) b1, bp1.TransOffsetX(oMapTile1.X), bp1.TransOffsetY(oMapTile1.Y);if (oMapTile2 != null)Bitmap b2 = bp2.CurrentMap.DrawBombEff(bp2.CurrentSurface, 5, oMapTile2);SD.Surface().DrawImage(Image) b2, bp2.TransOffsetX(oMapTile2.X), bp2.TransOffsetY(oMapTile2.Y);bp1.SetEmpty();bp2.SetEmpty();/*爆炸效果完毕*/oMapi.DestroyObject(LMi.Items(LMi.Count - 1).X, LMi.Items(LMi.Count - 1).Y);oMapi.DestroyObject(LMi.Items(LMi.Count - 2).X, LMi.Items(LMi.Count - 2).Y);lineTimer.Enabled = true;LMi.Clear();return trunCount + 1;return 0;private void UpdateFrame()UpdateFrame(true);private void UpdateFrame(bool IsFlip)if (gs = GameState.Play)if (!this.Visible) return;SD.Fill(Color.Black);for (int i = 0; i oMap.Length; i+)if (oMapi.GetCount() != 0)if (i 2)if (oMapi + 1.GetCount() != 0)if (i = 0)oMapi.Draw(SD.Surface(), true, 1);elseoMapi.Draw(SD.Surface(), true, 2);elseoMapi.Draw(SD.Surface(), false, 1);elseoMapi.Draw(SD.Surface(), false, 1);if (LMi.CanStartLink()if (isSearch)/只是提示MapTile MT1 = oMapi.GetMapTile(search_p1.X, search_p1.Y);MapTile MT2 = oMapi.GetMapTile(search_p2.X, search_p2.Y);SD.Surface().DrawRectangle(new Pen(Color.Red, 2F), MT1.X, MT1.Y, MT1.Width - 1, MT1.Height - 1);SD.Surface().DrawRectangle(new Pen(Color.Red, 2F), MT2.X, MT2.Y, MT2.Width - 1, MT2.Height - 1);cursor.DrawCursor(SD.Surface(), new Point(MT1.X + 15, MT1.Y + 15);cursor.DrawCursor(SD.Surface(), new Point(MT2.X + 15, MT2.Y + 15);if (AutoClear.Checked & isSearch)int t = ShowLineAndClear();if (isSearch)if (t != 0)PointCount -= t*100;if (this.options.PlaySound)spBomb.PlaySound();elseif (t != 0)PointCount += t*100;if (this.options.PlaySound)spBomb.PlaySound();isSearch = false;else if (!isSearch)int t = ShowLineAndClear();if (t != 0)PointCount += t*100;pBar.Value = pBar.Value + Math.Min(pBar.Maximum - pBar.Value, 6);if (this.options.PlaySound)spEarse.PlaySound();lbP.Text = PointCount.ToString();if (IsFlip)SD.Flip(0, 0);lbInfoCount.Text = InfoCount.ToString();int totalObjectCount = 0;foreach (Map m in oMap)totalObjectCount += m.GetCount();if (totalObjectCount = 0)EndGame();MessageBox.Show(恭喜,已过关!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Information);if (options.PlayMusic & gs = GameState.Play)if (!spBg.IsPlaying)spBg.FileName = spl.CurrentMusic();spBg.PlaySound();elsespB
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!