語言程序設(shè)計資料:java-俄羅斯方塊-java語言.doc
《語言程序設(shè)計資料:java-俄羅斯方塊-java語言.doc》由會員分享,可在線閱讀,更多相關(guān)《語言程序設(shè)計資料:java-俄羅斯方塊-java語言.doc(25頁珍藏版)》請在匯文網(wǎng)上搜索。
1、import java.awt.*;import java.applet.Applet;public class Blocks extends Applet implements RunnableDimension d;Font largefont= new Font(Helvetica, Font.BOLD, 28);Font smallfont= new Font(Helvetica, Font.BOLD, 10);Color textcolor1=new Color(96,128,255);Color textcolor2=new Color(255,160,64);FontMetric
2、s fmsmall, fmlarge;Graphics goff;Image ii;Threadthethread;boolean ingame=false;final short xblocks=10;final short yblocks=20;final int blocksize=16;final int width=xblocks*blocksize;final int height=yblocks*blocksize;short screendata;final short maxcolors=6;Color blocks;final int barwidth=8;final Co
3、lor barcolor=new Color(128,255,64);final Color background=new Color(0,0,0);int score;short emptyline;int objectx, objecty;int objectx;short objecttype;short objectcolor;int objectrotation;int objectrotationd=0;short objectptr;short checkptr;final short itemcount=7;final short itemrotlen=8;final shor
4、t itemlen=itemrotlen*4;short count;final short maxcount=5;short curcount;boolean fast=false;final short screendelay=40;short screencount=40;boolean showtitle=true;int items=0,0, -1,0, 0,-1, -1,-1, /四方形,正常狀態(tài)0,0, -1,0, 0,1, -1,1, /被旋轉(zhuǎn)90度0,0, 1,0, 0,1, 1,1,0,0, 1,0, 0,-1, 1,-1,0,0, 0,-1, 0,-2, 0,-3,0,0
5、, -1,0, -2,0, -3,0,0,0, 0,1, 0,2, 0,3,0,0, 1,0, 2,0, 3,0,0,0, 1,0, 0,-1, -1,-1,0,0, 0,-1, -1,0, -1,1,0,0, -1,0, 0,1, 1,1,0,0, 0,1, 1,0, 1,-1,0,0, -1,0, 0,-1, 1,-1,0,0, 0,1, -1,0, -1,-1,0,0, 1,0, 0,1, -1,1,0,0, 0,-1, 1,0, 1,1,0,0, 1,0, -1,0, 0,-1,0,0, 0,1, 0,-1, -1,0,0,0, 0,1, -1,0, 1,0,0,0, 1,0, 0,-
6、1, 0,1,0,0, 0,-1, 1,-1, 0,1,0,0, -1,0, -1,-1, 1,0,0,0, -1,1, 0,1, 0,-1,0,0, -1,0, 1,0, 1,1,0,0, 0,1, 0,-1, -1,-1,0,0, 1,0, -1,0, -1,1,0,0, 0,-1, 0,1, 1,1,0,0, -1,0, 1,0, 1,-1,;int checks=-1,1, 0,1, -1,1, 0,1,-1,2, 0,2, -1,2, 0,2,0,2, 1,2, 0,2, 1,2,0,1, 1,1, 0,1, 1,1,0,1, 0,1, 0,1, 0,1,0,1, -1,1, -2,
7、1, -3,1,0,4, 0,4, 0,4, 0,4,0,1, 1,1, 2,1, 3,1,0,1, -1,0, 1,1, 0,1,0,1, -1,2, 0,1, -1,2,0,2, 1,2, -1,2, 0,2,0,2, 1,1, 0,2, 1,1,-1,1, 0,1, 1,0, 1,0,-1,1, 0,2, 0,2, -1,1,-1,2, 0,2, 1,1, 1,1,0,1, 1,2, 0,1, 1,2,-1,1, 0,1, 1,1, 1,1,-1,1, 0,2, 0,2, -1,1,-1,1, 0,2, 1,1, 1,1,0,2, 1,1, 0,2, 1,1,0,2, 1,0, 1,0,
8、 0,2,-1,1, 0,1, 1,1, 1,1,-1,2, 0,2, 0,2, -1,2,-1,1, 0,1, 1,2, 1,2,-1,0, 0,2, 0,2, -1,0,-1,2, 0,1, 1,1, 1,1,0,2, 1,2, 1,2, 0,2,-1,1, 0,1, 1,1, 1,1,;public string getAppletInfo()return(Blocks - by Ali);/初始化appletpublic void init()short i;screendata=new shortxblocksyblocks;blocks=new Colormaxcolors+1;/
9、設(shè)置背景色blocks0=background;/設(shè)置方塊顏色blocks1=new Color(255,0,0);blocks2=new Color(0,255,0);blocks3=new Color(0,0,255);blocks4=new Color(255,255,0);blocks5=new Color(255,0,255);blocks6=new Color(0,255,255);Graphics g;resize(width+2*barwidth,height+30);d=size();setBackground(background);g=getGraphics();g.se
10、tFont(smallfont);fmsmall=g.getFontMetrics();g.setFont(largefont);fmlarge=g.getFontMetrics();gameInit();/初始化游戲public boid gameInit()short i,j;for(i=0;ixblocks;i+)for(j=0;j=itemcount)objecttype=itemcount-1;objectptr=(short)(objecttype*itemlen);checkptr=(short)(Mat.random()*maxcolors+1);if (objectcolor
11、maxcolors)objectcolor=maxcolors;objectrotation=0;count=maxcount;/判斷游戲是否結(jié)束for(i=0;i=0&screendataobjectx+itemsobjectptr+i*2y!=0)ingame=false;showtitle=true;/判斷鍵盤是否被按下,并且處理事件public boolean keyDown(Event e, int key)if(ingame)if(Key=Event.LEFT)objectdx=-1;else if (Key=Event.RIGHT)objectdx=1;else if (Key=
12、Event.UP)objectrotationd=1;else if (Key=Event.DOWN)fast=true;else if (Key=Event.ESCAPE)ingame=false;elseif(Key=s|Key=S)ingame=true;gameInit();return true;/處理鍵盤抬起事件public boolean keyUp(Event e, int key)if(Key=Event.DOWN)fast=false;return true;/paint()方法public void paint(Graphics g)Graphics gg;if (gof
- 1.請仔細(xì)閱讀文檔,確保文檔完整性,對于不預(yù)覽、不比對內(nèi)容而直接下載帶來的問題本站不予受理。
- 2.下載的文檔,不會出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請點(diǎn)此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
20 積分
下載 | 加入VIP,下載共享資源 |
- 配套講稿:
如PPT文件的首頁顯示word圖標(biāo),表示該P(yáng)PT已包含配套word講稿。雙擊word圖標(biāo)可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國旗、國徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計者僅對作品中獨(dú)創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- 語言程序設(shè)計 資料 java 俄羅斯方塊 語言