




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、荊楚理工學(xué)院<<c#編程>>結(jié)課設(shè)計(jì)說明書學(xué)生姓名:姚元美 梁貴波 楊爽學(xué) 號:10en404010261 2008404010248 2008404010238專 業(yè):計(jì)算機(jī)科學(xué)與技術(shù)班 級:計(jì)算機(jī)08-2任課教師:游明坤241. 游戲編程1.1. 概述1.1.1. 完成任務(wù)(1) 程序運(yùn)行界面如圖1.1所示:圖1.1 計(jì)算機(jī)信息查看器主界面1.2. 分析1.2.1. 功能分析新局:單擊左側(cè)會(huì)出現(xiàn)連連看游戲運(yùn)行界面,進(jìn)入游戲。提示:用戶可以在找不到一樣的圖案的時(shí)候點(diǎn)擊提示,會(huì)出現(xiàn)兩個(gè)可以撤銷的類似圖案。重排:左邊圖案會(huì)重新編排一次。配置:用戶可以對游戲的相關(guān)選項(xiàng)進(jìn)行設(shè)
2、置。退出:退出游戲。1.2.2. 界面分析運(yùn)行界面如下:如圖1.1所示,程序主體界面可分為三部分:第一部分是以執(zhí)行游戲的部分,第二部分是以游戲設(shè)置以及幫助的部分,第三部分就是游戲在運(yùn)行時(shí)所剩時(shí)間提示。第一部分含1個(gè)控件:11個(gè)列表視圖(list view)。第二部分含8個(gè)控件:6個(gè)按鈕(button)2個(gè)標(biāo)簽(label)。在2個(gè)label中,2個(gè)用于顯示提示,1個(gè)復(fù)選項(xiàng),分別用于顯示相應(yīng)的“詳細(xì)信息”。第三部分含3個(gè)控件:1個(gè)label,1個(gè)顯示提示,還有一個(gè)。界面的詳細(xì)布局如圖1.1所示。1.2.3. 程序分析本程序的核心是游戲執(zhí)行部分,所有的操作都圍繞著該數(shù)據(jù)進(jìn)行的。游戲分為三關(guān):簡單、
3、一般和難。為了用戶在規(guī)定時(shí)間完成一關(guān),設(shè)計(jì)了提示和重排。其中新局是開始游戲的意思,退出也就意味著結(jié)束游戲。1.3. 實(shí)現(xiàn)步驟1.3.1. 建立工程建立c# windows窗體應(yīng)用程序game項(xiàng)目。1.3.2. 界面設(shè)計(jì)根據(jù)圖1.1的樣式,設(shè)計(jì)出查看器的窗體布局。1.3.3. 主程序功能實(shí)現(xiàn) (1)定義主程序類對象gamemain。 (2)加載數(shù)據(jù)。使用computermanager的load方法從文件中加載信息,如果存在文件,則將文件中的計(jì)算機(jī)對象填充到listview。 如果不存在,則創(chuàng)建不同類型的計(jì)算機(jī),并添加到泛型集合中,填充到listview中。 (3)窗體設(shè)計(jì)器生成的代碼中的數(shù)據(jù)到d
4、ispose:private void endgame(),private void wingame()。時(shí)間觸發(fā)private void timeouttimer_tick(object sender, eventargs e)。(4)初始化集合泛型數(shù)據(jù):private void initgame()。如果從本地文件加載泛型集合數(shù)據(jù)失敗,則由程序初始化數(shù)據(jù),填充到泛型集合。(5)給下壓式按鈕添加事件處理。1.4. 核心代碼using system;using system.collections;using system.componentmodel;using system.drawing
5、;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
6、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 screendr
7、aw 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 screencu
8、rsor 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 spb
9、g;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,w
10、inpublic 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 窗體設(shè)計(jì)器生成的代碼private void initializecomponent()ponents = new container()
11、;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
12、= 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
13、();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.bt
14、ninfo.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 =
15、 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 = "自動(dòng)清除"this.linetimer.interval = 200;this.linetimer.tick += new eventhandler(this.linetimer_tick
16、);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);t
17、his.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;th
18、is.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 = &q
19、uot;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
20、size(60, 17);this.label3.tabindex = 8;this.label3.text = "提示次數(shù):"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 = "退出"th
21、is.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
22、.location = new point(8, 404);this.lbtimeout.name = "lbtimeout"this.lbtimeout.size = new size(97, 17);this.lbtimeout.tabindex = 12;this.lbtimeout.text = "剩余時(shí)間(60秒):" this.timeouttimer.interval = 1000;this.timeouttimer.tick += new eventhandler(this.timeouttimer_tick);this.pictureb
23、ox1.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.forecolo
24、r = 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
25、);this.autoreset.name = "autoreset"this.autoreset.size = new size(80, 24);this.autoreset.tabindex = 15;this.autoreset.text = "自動(dòng)重排"this.autoreset.visible = false;this.btnabout.forecolor = color.fromargb(byte) (192), (byte) (255), (byte) (255);this.btnabout.location = new point(67
26、2, 344);this.btnabout.name = "btnabout"this.btnabout.tabindex = 16;this.btnabout.text = "關(guān)于"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)
27、;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)
28、;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.
29、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);thi
30、s.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_l
31、oad);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/ <summary>/ 應(yīng)用程序的主入口點(diǎn)。/ </summary>stathreadprivate static void m
32、ain()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("正在初始化地圖.
33、");omap = new map3;gl.updateloadinginfo("初始化地圖.完成,正在初始化連線管理.");lm = new linemanager3;gl.updateloadinginfo("初始化連線管理.完成,正在初始化光標(biāo)和配置檔案.");cursor = new screencursor();gameoption go = new gameoption(this.spl);options = go.readoption();go.dispose();gl.updateloadinginfo("初始化光標(biāo)和
34、配置檔案.完成,正在初始化素材數(shù)據(jù).");so = new screenobject();gl.updateloadinginfo("初始化素材數(shù)據(jù).完成,正在分配元素.");omap0 = new map(so, 39, 0, 0);omap1 = new map(so, 34, 0, 0);omap2 = new map(so, 28, 0, 0);gl.updateloadinginfo("分配元素.完成,正在計(jì)算路徑.");lm0 = new linemanager(omap0);lm1 = new linemanager(omap1)
35、;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&
36、quot;);catchmessagebox.show("缺少資源目錄!", "請到安裝目錄內(nèi)運(yùn)行!", messageboxbuttons.ok, messageboxicon.information);this.close();gl.updateloadinginfo("計(jì)算路徑.完成,正在初始化聲音檔案.");/spl.add(".soundsbg-01.mid");/spl.add(".soundsbg-02.mid");/spl.add(".soundsbg-03.mid&q
37、uot;);/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
38、(apppath + "soundsearse.wav", "earse");gl.updateloadinginfo("初始化連線音效完成.");sprefresh = new soundplayer(apppath + "soundsrefresh.wav", "refresh");gl.updateloadinginfo("初始化刷新音效完成.");spselect = new soundplayer(apppath + "soundsselect.wav&q
39、uot;, "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 =
40、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 < omap.length; i+)omapi.level = loptions.level - 1, i;if (gs = gamestate.end)foreach (map m in omap)m.resetm
41、ap();m.randomrefresh();updateframe();gs = gamestate.play;this.timeouttimer.enabled = true;if (options.playmusic)if (!spbg.isplaying)spbg.filename = spl.currentmusic();spbg.playsound();elsespbg.stopsound();if (gl != null)gl.close();gl.dispose();gl = null;private void endgame()gs = gamestate.end;this.
42、timeouttimer.enabled = false;sd.fill(color.black);sd.flip(0, 0);pbar.maximum = gametimesec;pbar.minimum = 0;pbar.value = pbar.maximum;picturebox1.show();lbcaption.show();spbg.stopsound();private void wingame()gs = gamestate.win;endgame();private void gamemain_mouseup(object sender, mouseeventargs e)
43、if (gs != gamestate.play) return;maptile omaptile = new maptile3;for (int i = omap.length - 1; 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 | om
44、aptilei.yindex = map.tilecolcount - 1 | omaptilei.id = 0)return;elseif (omapomap.length - 1.getcount() > 0)if (i < omap.length - 1) break;graphics g = this.creategraphics();g.drawrectangle(new pen(color.red), omaptilei.x, omaptilei.y, omaptilei.width, omaptilei.height);lmi.add(omaptilei.xindex
45、, omaptilei.yindex, omaptilei.id);cursor.drawcursor(g);if (this.options.playsound)spselect.playsound();issearch = false;if (lmi.canstartlink()updateframe();break;private void gamemain_paint(object sender, painteventargs e)if (gs = gamestate.play) updateframe();private int showlineandclear()arraylist
46、 findpathpoints = null;int truncount = 0;bp1.setempty();bp2.setempty();for (int i = omap.length - 1; i >= 0; i-)if (lmi.testlink(out findpathpoints, out truncount)omapi.drawpathpoints(sd.surface(), findpathpoints);/*繪制爆炸效果*/bp1.currentmap = omapi;bp2.currentmap = omapi;bp1.currentpoint = new poin
47、t(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 omap
48、tile2 = 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.cur
49、rentmap.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.f
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高考語文一輪復(fù)習(xí)專題六文言文閱讀附錄1
- 2025年教案分享:三角形分類的實(shí)踐教學(xué)法
- 歡迎高一新生演講稿
- 公司人事行政助理年終工作總結(jié)范文
- 2024年工廠工作實(shí)習(xí)報(bào)告(29篇)
- 護(hù)理進(jìn)修學(xué)習(xí)總結(jié)
- 2025年教師節(jié)特別報(bào)道:課件與混合式教學(xué)
- 2025年小學(xué)書法公開課課件制作:技術(shù)與藝術(shù)的結(jié)合
- 《高中團(tuán)課教案》課件
- 模板-數(shù)據(jù)展示設(shè)計(jì)
- 電焊工培訓(xùn)課件
- 考研考博-英語-天津職業(yè)技術(shù)師范大學(xué)考試押題三合一+答案詳解4
- 原型范疇理論(精選)課件
- 網(wǎng)絡(luò)賬號信息登記表
- 鋼樓梯計(jì)算(自動(dòng)版)
- 部編版八年級歷史(下)全冊教案
- 水土保持各種分級標(biāo)準(zhǔn)表與指標(biāo)
- (完整版)學(xué)生課堂學(xué)習(xí)自我評價(jià)表
- Unit 1 How tall are you B Read and write(課堂PPT)
- 最新部編版九年級語文下冊 12《詞四首》課后習(xí)題參考答案
- 部編版四年級語文下冊27《巨人的花園》PPT課件(共2課時(shí))
評論
0/150
提交評論