




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、課程設(shè)計說明書 no.1撲克游戲1.課程設(shè)計的目的java語言是當(dāng)今流行的網(wǎng)絡(luò)編程語言,它具有面向?qū)ο蟆⒖缙脚_、分布應(yīng)用等特點。面向?qū)ο蟮拈_發(fā)方法是當(dāng)今世界最流行的開發(fā)方法,它不僅具有更貼近自然的語義,而且有利于軟件的維護(hù)和繼承。為了進(jìn)一步鞏固課堂上所學(xué)到的知識,深刻把握java語言的重要概念及其面向?qū)ο蟮奶匦?,使我們能夠熟練的?yīng)用面向?qū)ο蟮乃枷牒驮O(shè)計方法解決實際問題的能力。通過此次課程設(shè)計,鞏固所學(xué)java語言基本知識,增進(jìn)java語言編輯基本功,掌握jdk、editplus、eclipse、jcreator等開發(fā)工具的運用,拓寬常用類庫的應(yīng)用。使學(xué)生通過該教學(xué)環(huán)節(jié)與手段,把所學(xué)課程及相關(guān)知
2、識加以融會貫通,全面掌握java語言的編程思想及面向?qū)ο蟪绦蛟O(shè)計的方法,為今后從事實際工作打下堅實的基礎(chǔ)。本設(shè)計使用java語言開發(fā)撲克游戲程序,將電腦多次分發(fā)給你的牌按照相同的花色由大至小排列起來。2.設(shè)計方案論證2.1設(shè)計思路 用java語言,編程實現(xiàn)紙牌游戲,擁有如下規(guī)則,將電腦多次分發(fā)給你的牌按照相同的花色由大至小排列起來。游戲分為三個難度,簡單,普通,困難。簡單為單一花色。困難所分發(fā)給的牌有四種花色。將大小相鄰的紙牌依次排列到一起當(dāng)每種花色的全部紙牌都按順序排列到一起,則游戲結(jié)束。2.2設(shè)計方法將程序設(shè)計成為4個類,aboutdialog類用于實現(xiàn)全部的對話。pkcard類用于實現(xiàn)游
3、戲的規(guī)則。spidermenubar類用于實現(xiàn)各個模塊的功能。spider為主界面。在spidermenubar建立主界面菜單,通過構(gòu)造函數(shù)public spidermenubar構(gòu)造函數(shù),生成jmenubar的圖形界面,對菜單中各按鈕進(jìn)行事件監(jiān)聽。在該方法中調(diào)用spider的構(gòu)造方法,在其中生成spidermenubar對象,并放置在框架之上,同時設(shè)置框架標(biāo)題 沈 陽 大 學(xué)課程設(shè)計說明書 no.2框架大小背景顏色,布局為空。public spider()settitle(陶時撲克); setdefaultcloseoperation(javax.swing.jframe.exit_on_c
4、lose);setsize(1024, 742);setjmenubar(new spidermenubar(this); pane = this.getcontentpane(); pane.setbackground(new color(14, 25, 26); pane.setlayout(null); clicklabel = new jlabel(); clicklabel.setbounds(883, 606, 121, 96); pane.add(clicklabel);在spider類中有如下方法:newgame新游戲的方法,setgrade設(shè)置等級方法,初始化等級方法。set
5、grade,randomcards隨即函數(shù)。pkcard getpreviouscard獲得card上面的那張牌的方法等。由pkcard getpreviouscard,pkcard getnextcard,getlastcardlocation方法對類pkcard調(diào)用,代碼如下:public pkcard getpreviouscard(pkcard card) point point = new point(card.getlocation(); point.y -= 5; card = (pkcard) table.get(point); if (card != null)return
6、card; point.y -= 15; card = (pkcard) table.get(point); 沈 陽 大 學(xué)課程設(shè)計說明書 no.3 return card;public pkcard getnextcard(pkcard card) point point = new point(card.getlocation(); point.y += 5;card = (pkcard) table.get(point); if (card != null)return card; point.y += 15; card = (pkcard) table.get(point); retu
7、rn card;public point getlastcardlocation(int column) point point = new point(20 + column * 101, 25); pkcard card = (pkcard) this.table.get(point); if (card = null) return null; while (card != null) point = card.getlocation(); card = this.getnextcard(card); return point;public point getgroundlabelloc
8、ation(int column) return new point(groundlabelcolumn.getlocation();public void setgroundlabelzorder() for (int i = 0; i 10; i+) 沈 陽 大 學(xué)課程設(shè)計說明書 no.4pane.setcomponentzorder(groundlabeli, 105 + i); 23功能模塊圖圖1 功能模塊圖 沈 陽 大 學(xué)課程設(shè)計說明書 no.52.4程序流程圖圖2 程序流程圖3.設(shè)計結(jié)果與分析(1)首先是對游戲中主菜單的設(shè)計,設(shè)計的菜單包括兩個大部分,選項和幫助,如圖3所示: 沈
9、陽 大 學(xué)課程設(shè)計說明書 no.6圖3 顯示菜單通過如下代碼實現(xiàn):jmenu jnewgame = new jmenu(選項); jmenu jhelp = new jmenu(幫助);(2)在選項菜單下面包含7級子菜單,如圖4所示:圖4 顯示菜單 沈 陽 大 學(xué)課程設(shè)計說明書 no.7通過如下代碼實現(xiàn):jmenuitem jitemopen = new jmenuitem(開局);jmenuitem jitemplayagain = new jmenuitem(重發(fā)牌);jradiobuttonmenuitem jrmitemeasy = new jradiobuttonmenuitem(簡
10、單);jradiobuttonmenuitem jrmitemnormal = new jradiobuttonmenuitem(較難);jradiobuttonmenuitem jrmitemhard = new jradiobuttonmenuitem(困難);jmenuitem jitemexit = new jmenuitem(退出);jmenuitem jitemvalid = new jmenuitem(顯示可執(zhí)行行操作);(3)幫助下面包含2級子菜單,分別為游戲規(guī)則和聲明,如圖5所示:圖5 顯示幫助通過如下代碼實現(xiàn):jtabbedpane jtabbedpane = new jt
11、abbedpane();private jpanel jpanel1 = new jpanel();private jpanel jpanel2 = new jpanel();(4)主窗體通過類spider實現(xiàn)。將窗體名稱設(shè)置為“陶時撲克”,框架的大小設(shè)置為1024*742,背景顏色設(shè)置為黑色,布局管理設(shè)置為空,通過如下代碼實現(xiàn):public spider()settitle(陶時撲克); 沈 陽 大 學(xué)課程設(shè)計說明書 no.8setdefaultcloseoperation(javax.swing.jframe.exit_on_close);setsize(1024, 742);setjme
12、nubar(new spidermenubar(this); pane = this.getcontentpane();pane.setbackground(new color(14, 25, 26);pane.setlayout(null);(5)進(jìn)入游戲之后,首先選擇開始新游戲,通過類spider調(diào)用它的方法newgame方法,采用隨機(jī)函數(shù)隨機(jī)初始化牌的順序(這樣做的目的是,使游戲性增加可玩性,使每次出現(xiàn)牌的順序不同),如圖6所示。圖6 進(jìn)入新游戲界面用如下代碼實現(xiàn):public void newgame() this.randomcards(); this.setcardslocatio
13、n();this.setgroundlabelzorder(); 沈 陽 大 學(xué)課程設(shè)計說明書 no.9this.deal(); public int getc() return c; public void setgrade(int grade) this.grade = grade; public void initcards() if (cards0 != null) for (int i = 0; i 104; i+) pane.remove(cardsi); int n = 0;if (this.grade = spider.easy) n = 1; else if (this.gr
14、ade = spider.natural) n = 2; else n = 4; for (int i = 1; i = 8; i+)for (int j = 1; j = 13; j+) cards(i - 1) * 13 + j - 1 = new pkcard(i % n + 1) + - + j, this); 沈 陽 大 學(xué)課程設(shè)計說明書 no.10 this.randomcards(); public void randomcards() pkcard temp = null; for (int i = 0; i 52; i+) int a = (int) (math.random
15、() * 104); int b = (int) (math.random() * 104); temp = cardsa; cardsa = cardsb; cardsb = temp; (6)在游戲界面的右下角做一張圖片,顯示撲克牌的背面,同時點擊圖片,系統(tǒng)自動發(fā)牌(當(dāng)游戲無法繼續(xù)的時候,可以點擊該圖片,在每副紙牌上發(fā)一張牌,使得進(jìn)入僵局的紙牌游戲得以繼續(xù)進(jìn)行),運行界面如圖7,圖8所示。 沈 陽 大 學(xué)課程設(shè)計說明書 no.11圖7 發(fā)牌功能界面圖8 顯示發(fā)牌 沈 陽 大 學(xué)課程設(shè)計說明書 no.12用如下代碼實現(xiàn):首先在界面上添加紙牌背面的圖片:public void turnrear
16、() this.seticon(new imageicon(images/6.gif); this.isfront = false; this.canmove = false;public pkcard getpreviouscard(pkcard card) point point = new point(card.getlocation(); point.y -= 5; card = (pkcard) table.get(point); if (card != null)return card; point.y -= 15; card = (pkcard) table.get(point)
17、;return card; public pkcard getnextcard(pkcard card) point point = new point(card.getlocation(); point.y += 5; card = (pkcard) table.get(point); if (card != null)return card; point.y += 15; card = (pkcard) table.get(point); return card; 沈 陽 大 學(xué)課程設(shè)計說明書 no.13public point getlastcardlocation(int column
18、) point point = new point(20 + column * 101, 25); pkcard card = (pkcard) this.table.get(point); if (card = null) return null; while (card != null) point = card.getlocation(); card = this.getnextcard(card); return point; public point getgroundlabellocation(int column) return new point(groundlabelcolu
19、mn.getlocation(); public void setgroundlabelzorder() for (int i = 0; i 10; i+)pane.setcomponentzorder(groundlabeli, 105 + i); (7)在游戲中每次開始游戲都由程序隨機(jī)發(fā)牌,發(fā)牌的過程是,先設(shè)置紙牌的初始位置由隨機(jī)函數(shù)產(chǎn)生,并隨機(jī)生成牌號,設(shè)置紙牌的位置,初始化待展開的紙牌,將紙牌放置到固定位置(這里調(diào)用pkcard類中的setnextcardlocation方法調(diào)用圖片文件夾里的紙牌圖片),如圖9,圖10所示。 沈 陽 大 學(xué)課程設(shè)計說明書 no.14圖9 圖片庫圖10
20、圖片被載入 沈 陽 大 學(xué)課程設(shè)計說明書 no.15使用如下代碼實現(xiàn):for (int i = 0; i 6; i+) for (int j = 0; j 5; i-) for (int j = 0; j = 104) continue;pane.add(cardsn); cardsn.turnrear(); cardsn.moveto(new point(x, y); table.put(new point(x, y), cardsn); x += 101; x = 20; y -= 5; 沈 陽 大 學(xué)課程設(shè)計說明書 no.16public void showenableoperator(
21、) int x = 0; out: while (true) point point = null; pkcard card = null; do if (point != null)n+; point = this.getlastcardlocation(n); while (point = null) point = this.getlastcardlocation(+n); if (n = 10) n = 0; x+; if (x = 10) break out; card = (pkcard) this.table.get(point); while (!card.iscardcanm
22、ove(); while (this.getpreviouscard(card)!= null& this.getpreviouscard(card).iscardcanmove()card = this.getpreviouscard(card); if (a = 10)a = 0;for (; a 10; a+) if (a != n) 沈 陽 大 學(xué)課程設(shè)計說明書 no.17point p = null; pkcard c = null; do if (p != null)a+;p = this.getlastcardlocation(a); int z = 0; while (p =
23、null) p = this.getlastcardlocation(+a); if (a = 10) a = 0; if (a = n) a+; z+; if (z = 10) break out; c = (pkcard) this.table.get(p); while (!c.iscardcanmove(); if (c.getcardvalue() = card.getcardvalue() + 1) card.flashcard(card); try thread.sleep(800); catch (interruptedexception e)e.printstacktrace
24、(); c.flashcard(c); 沈 陽 大 學(xué)課程設(shè)計說明書 no.18a+; if (a = 10)n+; break out; n+; if (n = 10)n = 0; x+; if (x = 10)break out; 通過調(diào)用如下代碼實現(xiàn)圖片的調(diào)用:public void setnextcardlocation(point point)pkcard card = main.getnextcard(this);if (card != null)if (point = null)card.setnextcardlocation(null);main.table.remove(ca
25、rd.getlocation();card.setlocation(card.initpoint);main.table.put(card.initpoint, card); 沈 陽 大 學(xué)課程設(shè)計說明書 no.19elsepoint = new point(point);point.y += 20;card.setnextcardlocation(point);point.y -= 20;main.table.remove(card.getlocation();card.setlocation(point);main.table.put(card.getlocation(), card);c
26、ard.initpoint = card.getlocation();(8)進(jìn)入游戲之后能對游戲的難度進(jìn)行選擇,難度分為三種,分別為簡單,較難,困難,簡單為單一花色的紙牌進(jìn)行游戲,而較難和困難的紙牌花色相應(yīng)的增多。在設(shè)計時首先在spidermenubar類中,將三種難度的菜單實現(xiàn),然后通過調(diào)用pkcard的方法實現(xiàn)各難度的功能,如圖11,12所示。 沈 陽 大 學(xué)課程設(shè)計說明書 no.20圖11 難度選擇圖12 選擇困難 沈 陽 大 學(xué)課程設(shè)計說明書 no.21通過如下代碼實現(xiàn):實現(xiàn)菜單分成三種難度:jradiobuttonmenuitem jrmitemeasy = new jradiobu
27、ttonmenuitem(簡單); jradiobuttonmenuitem jrmitemnormal = new jradiobuttonmenuitem(較難);jradiobuttonmenuitem jrmitemhard = new jradiobuttonmenuitem(困難);jrmitemeasy.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.easy);
28、main.initcards(); main.newgame(); 分別對菜單進(jìn)行事件監(jiān)聽,若選中相應(yīng)的難度登記則觸發(fā)spider類中的方法進(jìn)行實現(xiàn):jrmitemnormal.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.natural); main.initcards(); main.newgame(); jrmitemhard.addactionlistener(new
29、java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.hard);main.initcards(); main.newgame(); 沈 陽 大 學(xué)課程設(shè)計說明書 no.22jnewgame.addmenulistener(new javax.swing.event.menulistener() public void menuselected(javax.swing.event.menuevent e) if(main.get
30、c() 60) jitemplayagain.setenabled(true); else jitemplayagain.setenabled(false); public void menudeselected(javax.swing.event.menuevent e) public void menucanceled(javax.swing.event.menuevent e) (9)退出游戲,點擊退出即可退出游戲,在spidermenubar類中actionperformed方法實現(xiàn),如圖13所示。圖13 退出游戲 沈 陽 大 學(xué)課程設(shè)計說明書 no.23使用如下代碼實現(xiàn):jiteme
31、xit.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.dispose(); system.exit(0); 4.設(shè)計體會通過本次課程設(shè)計,我學(xué)會了很多東西,在課堂上學(xué)習(xí)的知識是理論的,平時沒有多少機(jī)會去實踐,平時覺得自己java學(xué)得還不錯但真到想用它實現(xiàn)點什么的時候卻又覺得好多地方不知道如何下手。我的這個程序設(shè)計是以蜘蛛紙牌游戲作為基礎(chǔ),對其中很多地方進(jìn)行了修改,原來游戲只由2個難度,我在原來的基礎(chǔ)上對游戲進(jìn)行修改增加了一個難度,也增加了游戲的可玩性,還有游戲中好多圖片過于死板,我利用photoshop等工具對圖片進(jìn)行修改,在
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 無石棉硅酸鈣板行業(yè)跨境出海戰(zhàn)略研究報告
- 健身舞蹈服務(wù)行業(yè)跨境出海戰(zhàn)略研究報告
- 佛教寺廟保護(hù)企業(yè)制定與實施新質(zhì)生產(chǎn)力戰(zhàn)略研究報告
- 二零二五股權(quán)轉(zhuǎn)移簡單協(xié)議書
- 二零二五版幼兒園老師雇傭合同
- 吊車司機(jī)雇傭合同
- 股權(quán)轉(zhuǎn)讓回購協(xié)議二零二五年
- 二零二五版集體土地廠房買賣合同
- 二零二五房產(chǎn)財產(chǎn)抵押擔(dān)保合同
- 個人勞務(wù)合同書模板
- 江蘇省昆山、太倉、常熟、張家港市2023-2024學(xué)年下學(xué)期七年級數(shù)學(xué)期中試題
- 生物地球化學(xué)性疾病試題
- 休閑與旅游農(nóng)業(yè)課件
- 感覺障礙護(hù)理課件
- 脊髓小腦性共濟(jì)失調(diào)學(xué)習(xí)課件
- 體育運動員參賽健康狀況證明模板
- 教師的挑戰(zhàn):寧靜的課堂革命
- 菲亞特博悅說明書
- 空調(diào)維保服務(wù)方案(技術(shù)方案)
- 高空發(fā)光字安裝應(yīng)急預(yù)案
- 量具能力準(zhǔn)則Cg-Cgk評價報告
評論
0/150
提交評論