




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、面向?qū)ο蟪绦蛟O(shè)計ii -j2me課程設(shè)計論文題 目:俄羅斯方塊學(xué) 院:計算機與信息工程學(xué)院專 業(yè):計算機科學(xué)與技術(shù)班 級:計算機06-7班姓 名:曲春良學(xué) 號:09起止時間:2008.12.21-2008.12.31 成績: 課程設(shè)計成績評定表質(zhì)量評價指標(biāo)(在相應(yīng)欄目打)評 價 項 目評 價 質(zhì) 量優(yōu)秀良好一般及格不及格工作量和態(tài)度實驗、計算可靠性文字和圖表質(zhì)量程序完成情況總體評價評定成績評定人員簽名2008年12月31日iv課程設(shè)計任務(wù)書一、設(shè)計題目:俄羅斯方塊二、設(shè)計內(nèi)容:提起“俄羅斯方塊”,在當(dāng)今世界上,幾乎無人不知它是一個經(jīng)典的游戲。對于那些在機場等待飛機起飛或者每天需乘車上下班的人來
2、說,俄羅斯方塊游戲很容易讓他們著迷,成了他們打發(fā)時間的一種消遣。俄羅斯方塊是一款風(fēng)靡全球的電視游戲機和掌上游戲機游戲,它曾經(jīng)造成的轟動與造成的經(jīng)濟價值可以說是游戲史上的一件大事。這款游戲最初是由蘇聯(lián)的游戲制作人alex pajitnov制作的,它看似簡單但卻變化無窮,令人上癮。相信大多數(shù)用戶都還記得茶飯不思的那個俄羅斯方塊時代。三、設(shè)計要求:游戲有7種下墜物,如“田”字形,“l(fā)”字形等,每種下墜物可以左移、右移、下墜以及變形;當(dāng)游戲區(qū)域(所謂的游戲區(qū)域是,把整個屏幕分為游戲區(qū)域和非游戲區(qū)域,游戲區(qū)域16個磚塊高,12個磚塊寬,而非游戲區(qū)域用來顯示下一個下墜物、分?jǐn)?shù)以及速度)中滿行時系統(tǒng)就進行記
3、分,并且消行,上面的磚塊下移;如果方塊不能再出現(xiàn)并往下移,就表明游戲結(jié)束。l 記分機制:1、2行就10、20分,3行40分,4行50分;行數(shù)越多分?jǐn)?shù)越高;l 隨機產(chǎn)生方塊,每滿100分就提高一個等級,最低0級,最高為9級;l 不能連續(xù)按鍵;l “左”按左鍵,“右”按右鍵,“下移”按下鍵,“變”按fire鍵。l 用戶設(shè)定等級。四、工作計劃:時間完成內(nèi)容提交文檔備注第1天查找資料,確定題目,選擇方案課程設(shè)計任務(wù)書設(shè)計準(zhǔn)備階段第2天第3天題目分析,設(shè)計算法算法描述設(shè)計階段第4天功能模塊的劃分和設(shè)計結(jié)構(gòu)流程圖等第5天第6天實現(xiàn)具體數(shù)據(jù)結(jié)構(gòu)和模塊無第7天程序設(shè)計與調(diào)試無運行并驗證程序功能第8天第9天檢查
4、程序第10天整理材料,撰寫論文課程設(shè)計論文指導(dǎo)教師: 王艷濤 陳偉 高輝 教研室主任: 2008 年 12月31 日ii 本科課程設(shè)計論文摘 要游戲中,充分利用j2me的知識在手機上實現(xiàn)一個經(jīng)典的俄羅斯方塊。要求隨機產(chǎn)生方塊,可以左右移動、下移和變形,滿行時可以消行并且記分,滿100分時還要升級同時加速;同時還要求人機操作合理,讓人一看就懂。手機游戲的設(shè)計不許秉承人性化的特點,在沒有詳細的用戶說明的時候,用戶仍然可以輕易的理解游戲的意圖,并且很容易的從中得到快樂。 關(guān)鍵詞:j2me 面向?qū)ο?俄羅斯方塊iii目 錄課程設(shè)計成績評定表ii課程設(shè)計任務(wù)書iii摘 要iii目 錄iv1 設(shè)計內(nèi)容22
5、 設(shè)計過程22.1設(shè)計方案的論證22.2概要設(shè)計32.3界面設(shè)計圖32.4代碼實現(xiàn)73 設(shè)計總結(jié)8參考文獻8附錄:程序源代碼91 設(shè)計內(nèi)容游戲有7種下墜物,如“田”字形,“l(fā)”字形等,每種下墜物可以左移、右移、下墜以及變形;當(dāng)游戲區(qū)域(所謂的游戲區(qū)域是,把整個屏幕分為游戲區(qū)域和非游戲區(qū)域,游戲區(qū)域16個磚塊高,12個磚塊寬,而非游戲區(qū)域用來顯示下一個下墜物、分?jǐn)?shù)以及速度)中滿行時系統(tǒng)就進行記分,并且消行,上面的磚塊下移;如果方塊不能再出現(xiàn)并往下移,就表明游戲結(jié)束2 設(shè)計過程2.1設(shè)計方案的論證midp的游戲設(shè)計,本質(zhì)上就是用一個線程或者定時器產(chǎn)生重繪事件,用線程和用戶輸入改變游戲狀態(tài)。游戲也不
6、例外,啟動midlet后,就立即生成一個重繪線程,該線程每隔speed(程序中設(shè)置的變量,用來控制游戲的速度)ms繪制一次屏幕。當(dāng)然,重繪時有一些優(yōu)化措施,并不是屏幕上所有的像素都需要重繪,而是有所選擇,比如游戲畫布上那些已經(jīng)固定下來的下墜物(下墜物一共有7種,由4個小磚塊組成,每種下墜物顏色固定,可以上下左右旋轉(zhuǎn))就不需重繪。游戲畫布是一個commandlistener,可以接受用戶鍵盤命令,控制下墜物的左移,右移,下移,旋轉(zhuǎn)動作。整個游戲的流程控制體現(xiàn)在游戲畫布對象的paint()方法里。paint()根據(jù)當(dāng)前的游戲狀態(tài),繪制出當(dāng)時的游戲畫面。歡迎畫面和game over畫面的繪制相當(dāng)簡單
7、,就直接用背景顏色清屏,再用drawstring方法畫圖就可以了。游戲暫停畫面的繪制也相當(dāng)容易,就是設(shè)立標(biāo)志,讓paint()執(zhí)行的時候無需真正執(zhí)行重繪動作。對于游戲處于運行狀態(tài)的畫面的繪制,則需要在下墜物的當(dāng)前位置,繪制下墜物。在繪制下墜物之前,判斷下墜物是否還能下墜,如果能下墜的話,就讓它下落一格,再進行繪制,如果下墜物已無法下墜,則判斷游戲是否處于game over狀態(tài),如果是處于game over狀態(tài)的話,則設(shè)置游戲狀態(tài)為game over狀態(tài),這樣畫布在下一次重繪時就繪出game over的畫面.如果游戲不是處于game over狀態(tài),則把下墜物固定下來,同時檢查游戲畫布上下墜物當(dāng)前
8、行下面的所有行,看是否需要進行行刪除動作,如果需要行刪除,則清除游戲地圖上被刪除行的數(shù)據(jù),再把被刪除行繪制成背景色。然后初始化一個新的下墜物,繪制這個新的下墜物。2.2概要設(shè)計根據(jù)初步的分析,項目分成四個部分:russianblock、russiancanvas、russiangame和russianmap。russianblock負(fù)責(zé)畫小磚塊、畫下移磚塊、磚塊下移、磚塊左右移、磚塊變形、根據(jù)隨機數(shù)讀取當(dāng)前要下移的磚塊以及下一個磚塊。russiancanvas接受用戶的控制命令,調(diào)用russianblock里的方法。russiangame是繼承midlet的,有startapp()方法。rus
9、sianmap設(shè)置地圖數(shù)據(jù)的,在特定的坐標(biāo)取地圖數(shù)據(jù),在具體坐標(biāo)下設(shè)置地圖數(shù)據(jù);以及畫一些score,speed,control之類。russianblockrussiancanvasrussiangamerussianmap方塊下墜、設(shè)置地圖數(shù)據(jù)、讀方塊數(shù)據(jù)、畫下墜物、畫方塊接受用戶輸入、重畫線程、繪制幫助或者game over繼承了midlet類,startapp(),pauseapp(),destoryapp()設(shè)置/讀取指定地圖的數(shù)據(jù)、消行等操作、繪制得分/速度如圖所示:圖 各模塊的功能另外,游戲還分為5個狀態(tài):game_init,game_run,game_start_demo,ga
10、me_supend,game_over。游戲在game_init(游戲初始狀態(tài))狀態(tài)下,系統(tǒng)會把游戲地圖畫出來;游戲在game_run(游戲正在運行狀態(tài))狀態(tài)下,就是正常的游戲狀態(tài),接受用戶輸入、畫方塊等等;game_start_demo會打印歡迎畫面;在game_supend(游戲掛起狀態(tài))狀態(tài)下,游戲就進入了掛起狀態(tài),不重畫方塊,一直等到進入game_run狀態(tài);game_over狀態(tài)就是游戲的結(jié)束狀態(tài),這時會畫出游戲結(jié)束畫面。2.3界面設(shè)計圖游戲的操作流程非常簡單,用戶啟動midlet啟動后,即進入游戲主畫面,屏幕開始顯示為歡迎畫面。用戶選擇了【開始】按鈕后,就可以開始玩游戲了,當(dāng)用戶想
11、暫停時,再次按一下【開始】按鈕,游戲就暫停了,在暫停的情況下再按【開始】按鈕,游戲繼續(xù)運行;當(dāng)選擇【幫助】時,屏幕會跳到幫助頁面;任何時候按【退出】按鈕,游戲midlet都會終止。游戲畫面流程圖如圖所示:游戲運行畫面midlet選擇畫面開始畫面game over畫面游戲暫停畫面圖 游戲畫面流程圖 開始歡迎界面 主場景界面游戲進入界面 菜單界面游戲暫停界面 游戲結(jié)束界面2.4代碼實現(xiàn)2.russianblock 類是最主要的類,限于篇幅只給出russianblock類的代碼:package bysj;import java.util.*;import javax.microedition.lcd
12、ui.*;public class russianblock /各種磚塊,1-7為活動磚塊顏色,8為墻磚顏色 public static final int brick_colors = 0x00ff0000, 0x0000ff00, 0x00ffff00, 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00c0dcc0, 0x00808080; /* * blockpattern的編碼規(guī)則:blockpattern表示一個下墜物體的形狀,一種下墜物的顏色是固定的。 * 對于一個下墜物,用一個三維數(shù)祖表示,第一維用rot表示(旋轉(zhuǎn)值),第二維用x(也就是行),第三
13、維用y表示(也就是列)。 * 所以 blockpattern1:田字及四種旋轉(zhuǎn)形狀 * blockpattern2:反l字及四種旋轉(zhuǎn)形狀 * blockpattern3:l字及四種旋轉(zhuǎn)形狀 * blockpattern4:1字及四種旋轉(zhuǎn)形狀 * . */3 設(shè)計總結(jié)通過此次兩周的j2me的課程設(shè)計,使我學(xué)到了很多,真正達到了學(xué)與用的結(jié)合,增強了對j2me方面應(yīng)用的理解,對自己今后參與開發(fā)手機游戲積累了不少經(jīng)驗,在實驗過程中,對手機游戲設(shè)計理念及思想上有更高的認(rèn)識,懂得了不少有關(guān)j2me開發(fā)過程中的知識,在學(xué)習(xí)過程中,我也能過上網(wǎng)查了不少資料,也看了一些別人設(shè)計的俄羅斯方塊的設(shè)計報告,學(xué)以致用,
14、自我創(chuàng)新,完成了這份自己的報告,從中在學(xué)到用,從用又到學(xué),不斷修改,系統(tǒng)更新。雖然不能達到完善游戲,但也做到了盡善盡美,加強理論學(xué)習(xí)對完善系統(tǒng)會有很多幫助,不管怎么說,對這次做的課程設(shè)計自己覺得還算滿意參考文獻1 timothy budd. 三聯(lián)四方工作室譯,面向?qū)ο骿ava編程思想m. 清華大學(xué)出版社,2002.82 mary campione kathy walrath alison huml. 馬朝暉 等譯,java語言導(dǎo)學(xué)m. 機械工業(yè)出版社,2002.13 王森. java手機/pda程序設(shè)計入門m. 電子工業(yè)出版社,2004.34 張小瑋. j2me無線平臺應(yīng)用開發(fā)m. 清華大學(xué)出
15、版社, 20045 微型抓哇人. java手機程序開發(fā)m. 中國鐵道出版社, 2003.36 美roger riggs 芬 jyri huopaniemi jim van peursem et al. 肖煒 郭曉剛 譯,j2me無線設(shè)備程序設(shè)計m. 電子工業(yè)出版社,2004.67 盧軍. j2me應(yīng)用程序開發(fā)m. 中國鐵道出版社,2002.98 飛思科技產(chǎn)品研發(fā)中心. 精通jbuilder9m. 電子工業(yè)出版社,2003.89 聞怡洋. j2me midp1.0/2.0無線設(shè)備編程指南m. 北京大學(xué)出版社,2004.710 john wiley .java 2 micro edition: p
16、rofessional developer's guidem. sons,inc附錄:程序源代碼package com.crackj2ee.j2me.game.russia;import javax.microedition.lcdui.*;import javax.microedition.midlet.midlet;/* * the app main midlet.*/public final class russiamidlet extends midlet private static final string options = "new game", &
17、quot;load game", "top 10", "exit" private static russiamidlet instance = null; private display display = null; private list welcome = null; private mycanvas canvas = null; public russiamidlet() instance = this; display = display.getdisplay(this); protected void startapp() if
18、(welcome=null) welcome = new list("welcome!", list.implicit, options, null); welcome.setcommandlistener(new welcomelistener(welcome); display.setcurrent(welcome); protected void pauseapp() protected void destroyapp(boolean unconditional) public static void quitapp() if(instance!=null) inst
19、ance.destroyapp(true); instance.notifydestroyed(); " public static void setdisplay(displayable d) instance.dksplay.setcurrent(d); class welcomelistener implements commandlisôener private list list; public welcomelistener(list list) this.list = list; public"void commandaction(command c
20、, displayable d) if(s=list.select_command) switch(lit.getselectedindex() case 0: / new game russiamidlet.setdisplay(new mycanvas(false); break; case 1: / load game russiamidlet.setdisplay(new mycanvas(true); break; case 2: / top 10 break; case 3: / exit russiamidlet.quitapp(); package com.crackj2ee.
21、j2me.game.russia;import java.util.random;import javax.microedition.lcdui.*;/* * activeshape represent the current falling shape. */public final class activeshape implements storable private shape currentshape; / current shape private int nextshapeindex; / next shape private shape previousshape; / pr
22、evious shape private int colorindex; / init location: private int init_left; / the location on background: private int left; private int top; / the last location: private int pre_left; private int pre_top; / random generator: private random random = new random(); public activeshape(int init_left) th
23、is.init_left = init_left; public void init() currentshape = shape.shapes0; previousshape = currentshape; nextshapeindex = 1; colorindex = 0; public byte getrecorddata() byte data = new byte3; / current shape index: data0 = (byte)shape.indexof(currentshape); / next shape index: data1 = (byte)nextshap
24、eindex; data2 = (byte)colorindex; return data; public int setrecorddata(byte data, int offset) if(data.length-offset<3) return (-1); currentshape = shape.shapesdataoffset; previousshape = currentshape; nextshapeindex = dataoffset+1; colorindex = dataoffset+2; this.left = init_left; this.top = sha
25、pe.getinittop(shape.indexof(currentshape); return 3; /* * if false, that means game over! * * param shapeindex the index of the shape. * param color the color of the shape. * return true if can reset to top. */ public boolean reset(background bg) this.currentshape = shape.shapesnextshapeindex; this.
26、previousshape = currentshape; this.left = init_left; this.top = shape.getinittop(nextshapeindex); this.pre_left = left; this.pre_top = top; if(bg.collideswith(this) return false; / set next shape: random.setseed(system.currenttimemillis(); int rnd = random.nextint(); if(rnd<0) rnd=0-rnd; colorind
27、ex = rnd % colors.all_colors.length; nextshapeindex = rnd % shape.shapes.length; return true; public shape getcurrentshape() return this.currentshape; public int getcolorindex() return this.colorindex; public int getleft() return this.left; public int gettop() return this.top; private void lastlocat
28、ionbeforemove() pre_left = left; pre_top = top; public boolean moveleft(background bg) lastlocationbeforemove(); / move left first: left-; / detect if overflow: int data = currentshape.getdata(); for(int i=0; i<0-left; i+) / col for(int j=0; j<4; j+) / row if(datai+4*j=1) left+; return false;
29、/ detect if collides with boxes: if(bg.collideswith(this) left+; return false; return true; public boolean moveright(background bg) lastlocationbeforemove(); / move right first: left+; / detect if overflow: int width = bg.getwidth(); int data = currentshape.getdata(); for(int i=width-left; i<4; i
30、+) / col for(int j=0; j<4; j+) / row if(datai+4*j=1) left-; return false; / detect if collides with boxes: if(bg.collideswith(this) left-; return false; return true; public boolean movedown(background bg) lastlocationbeforemove(); / move down first: top+; / detect if fall on bottom: int height =
31、bg.getheight(); int data = currentshape.getdata(); for(int i=height-top; i<4; i+) / row for(int j=0; j<4; j+) / col if(data4*i+j=1) top-; return false; / detect if collides with boxes: if(bg.collideswith(this) top-; return false; return true; public void falldown(background bg) while(movedown(
32、bg); public boolean change(background bg) shape backup = currentshape; currentshape = currentshape.next(); / test if overflow: int width = bg.getwidth(); int data = currentshape.getdata(); for(int i=width-left; i<4; i+) / col for(int j=0; j<4; j+) / row if(datai+4*j=1) this.currentshape = back
33、up; return false; for(int i=0; i<0-left; i+) / col for(int j=0; j<4; j+) / row if(datai+4*j=1) this.currentshape = backup; return false; / test if collides with: if(bg.collideswith(this) this.currentshape = backup; return false; previousshape = backup; return true; public void paint(graphics g
34、, int box_size) if(previousshape=currentshape) / just move, not change: g.translate(pre_left*box_size, pre_top*box_size); currentshape.erase(g, box_size); g.translate(left-pre_left)*box_size, (top-pre_top)*box_size); currentshape.paint(g, box_size, colors.all_colorscolorindex); else / just changed:
35、g.translate(left*box_size, top*box_size); previousshape.erase(g, box_size); / draw new position: currentshape.paint(g, box_size, colors.all_colorscolorindex); / make prev=current until next change: previousshape=currentshape; public shape getnextshape() return shape.shapesnextshapeindex; /*package c
36、om.crackj2ee.j2me.game.russia;import javax.microedition.lcdui.*;/* * to represent the container of all boxes.*/public final class background implements storable public static final int empty = 99; / holds width & height: private int width; private int height; / holds boxes, empty or color_index:
37、 private int boxes; / holds the rows that can be removed. private boolean removingrows; / make sure cannot instanciate from outside: public background(int width, int height) this.width = width; this.height = height; this.removingrows = new booleanheight; this.boxes = new intwidthheight; public int g
38、etwidth() return this.width; public int getheight() return this.height; /* * clean all boxes and can start a new game. */ public void init() for(int i=0; i<width; i+) for(int j=0; j<height; j+) boxesij = empty; for(int i=0; i<height; i+) removingrowsi = false; public byte getrecorddata() by
39、te data = new bytewidth*height; int offset = 0; for(int r=0; r<height; r+) for(int c=0; c<width; c+) dataoffset = (byte)boxescr; offset+; return data; public int setrecorddata(byte data, int offset) if(data.length-offset)<width*height) return (-1); for(int r=0; r<height; r+) for(int c=0;
40、 c<width; c+) boxescr = dataoffset; offset+; return width*height; /* * detect if there is a collition between two 4x4 area. * param active the activeshape object. * return true if there is a collition. */ public boolean collideswith(activeshape active) int data = active.getcurrentshape().getdata(
41、); int left = active.getleft(); int top = active.gettop(); for(int i1=top, i2=0; i1<top+4; i1+, i2+) for(int j1=left, j2=0; j1<left+4; j1+, j2+) if(i1>=0 && i1<height && j1>=0 && j1<width) if(data4*i2+j2=1 && boxesj1i1!=empty) return true; return fal
42、se; public int getboxes() return boxes; /* * merge the activeshape to the background. * param active the activeshape object. */ public void merge(activeshape active) int left = active.getleft(); int top = active.gettop(); int box; for(int i=0; i<4; i+) for(int j=0; j<4; j+) box = active.getcur
43、rentshape().getdata()i*4+j; if(box=1) this.boxesleft+jtop+i = active.getcolorindex(); /* * mark all rows that can be removed. */ public boolean markremovingrows() / mark all rows if it can be removed: for(int i=0; i<height; i+) removingrowsi = true; for(int j=0; j<width; j+) if(boxesji=empty) removingrowsi = false; break; return removingrows; public int doremove() int r = height - 1; int i = height - 1; for(i=height-1; i>=0; i-) while(r>=0 && removingrowsr) r-; if(r=(-1) break; copyrow(r, i); r-; for(int j=i; j>=0; j-) for(int n=0; n<w
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣播電視節(jié)目制作中的編劇策略考核試卷
- 信托公司財務(wù)風(fēng)險分析與控制考核試卷
- 疫情網(wǎng)課班會課件小學(xué)生
- 塑料薄膜在戶外運動裝備的應(yīng)用考核試卷
- 智能清潔電器的遠程監(jiān)控技術(shù)考核試卷
- 機器人傳感器數(shù)據(jù)融合與應(yīng)用考核試卷
- 蘇州恒溫配送合同范本
- 土建及市政合同范本
- 拍攝視頻制作合同范本
- 毛坯公寓酒店合同范本
- 蘇教版科學(xué)五年級下15《升旗的方法》教案
- 現(xiàn)代工業(yè)發(fā)酵調(diào)控緒論
- 超高性能混凝土項目立項申請(參考模板)
- 電纜橋架招標(biāo)文件范本(含技術(shù)規(guī)范書)
- 試車場各種道路施工方案設(shè)計
- 部編版四年級語文下冊第二單元《習(xí)作:我的奇思妙想》課件PPT
- PS零基礎(chǔ)入門學(xué)習(xí)教程(適合純小白)PPT課件
- XX輸變電工程公司作業(yè)風(fēng)險評估數(shù)據(jù)庫(精品模板)
- 涂裝行業(yè)常用日語單詞集
- 頭頸部影像學(xué)表現(xiàn)(詳細、全面)
- 《國際商務(wù)》PPT課件.ppt
評論
0/150
提交評論