下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 java小游戏编程

java小游戏编程.doc

java小游戏编程

海豚湾_友人
2017-09-29 0人阅读 举报 0 0 暂无简介

简介:本文档为《java小游戏编程doc》,可适用于综合领域

java小游戏编程importjavaawt*importjavaappletAppletpublicclassBlocksextendsAppletimplementsRunnable{DimensiondFontlargefont=newFont("Helvetica",FontBOLD,)Fontsmallfont=newFont("Helvetica",FontBOLD,)Colortextcolor=newColor(,,)Colortextcolor=newColor(,,)FontMetricsfmsmall,fmlargeGraphicsgoffImageiiThreadthethreadbooleaningame=falsefinalshortxblocks=finalshortyblocks=finalintblocksize=finalintwidth=xblocks*blocksizefinalintheight=yblocks*blocksizeshortscreendatafinalshortmaxcolors=Colorblocksfinalintbarwidth=finalColorbarcolor=newColor(,,)finalColorbackground=newColor(,,)intscoreshortemptylineintobjectx,objectyintobjectdxshortobjecttypeshortobjectcolorintobjectrotationintobjectrotationd=shortobjectptrshortcheckptrfinalshortitemcount=finalshortitemrotlen=finalshortitemlen=itemrotlen*shortcountfinalshortmaxcount=shortcurcountbooleanfast=falsefinalshortscreendelay=shortscreencount=booleanshowtitle=trueintitems={,,,,,,,,ËÄÐÎ,Õý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÖÏßÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,æÔòÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,æÔòÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,LÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,LÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,,ÍÐÎÕý×Ì,,,,,,,,ÐýתÈ,,,,,,,,ÐýתÈ,,,,,,,ÐýתÈ}intchecks={,,,,,,,,checkËÄÐÎ,Õý×Ì,,,,,,,,check,ÐýתÈ,,,,,,,,check,ÐýתÈ,,,,,,,,check,ÐýתÈ,,,,,,,,,,,,,,,,,,,,,,,,ÖÏßÐÎ,,,,,,,,,,,,,,,,æÔòÐÎ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,æÔòÐÎ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,ÍÐÎ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,LÐÎ,,,,,,,LÐÎ,,,,,,,,,,,,,,,,,,,,,,,}publicStringgetAppletInfo(){return("BlocksbyAli")}õÊappletpublicvoidinit(){shortiscreendata=newshortxblocksyblocksblocks=newColormaxcolorsblocks=backgroundÉèÖÃÉblocks=newColor(,,)ÉèÖÃéÑÕÉblocks=newColor(,,)blocks=newColor(,,)blocks=newColor(,,)blocks=newColor(,,)blocks=newColor(,,)Graphicsgresize(width*barwidth,height)d=size()setBackground(background)g=getGraphics()gsetFont(smallfont)fmsmall=ggetFontMetrics()gsetFont(largefont)fmlarge=ggetFontMetrics()gameInit()}õÊÓÎÏpublicvoidgameInit(){shorti,jfor(i=i<xblocksi){for(j=j<yblocksj){screendataij=}}score=emptyline=newObject()fast=falsecurcount=maxcount}publicvoidnewObject(){shortiintyobjectx=xblocksobjectdx=objecty=objecttype=(short)(Mathrandom()*itemcount)if(objecttype>=itemcount)objecttype=itemcountobjectptr=(short)(objecttype*itemlen)checkptr=(short)(objecttype*itemlen)objectcolor=(short)(Mathrandom()*maxcolors)if(objectcolor>maxcolors)objectcolor=maxcolorsobjectrotation=count=maxcountÅÐÏÓÎÏÊÇñáÊøfor(i=i<i){y=itemsobjectptri*if(y>=screendataobjectxitemsobjectptri*y!=){ingame=falseshowtitle=true}}}ÅÐÏüÅÌÊÇñÏÂÇÒÀíÊÂþpublicbooleankeyDown(Evente,intkey){if(ingame){if(key==EventLEFT){objectdx=}elseif(key==EventRIGHT){objectdx=}elseif(key==EventUP){objectrotationd=}elseif(key==EventDOWN){fast=true}elseif(key==EventESCAPE){ingame=false}}else{if(key=='s'||key=='S'){ingame=truegameInit()}}returntrue}ÀíüÅÌÌÆðÊÂþpublicbooleankeyUp(Evente,intkey){if(key==EventDOWN){fast=false}returntrue}paint()publicvoidpaint(Graphicsg){Graphicsggif(goff==dwidth>dheight>){ii=createImage(dwidth,dheight)goff=iigetGraphics()}if(goff==||ii==)returngoffsetColor(background)ÉèÖÃÉgofffillRect(,,dwidth,dheight)if(ingame)ÈçûÓÎÏÒÑ,ªÊplayGame()µÓÃplayGame()elseñÔòÏÔÊÆäËûÐÅÏshowIntro()ÏÔÊõÊÐÅÏshowScore()ÏÔʵÃÖgdrawImage(ii,,,this)}ʵÏÖÓÎÏpublicvoidplayGame(){booleanbottomreached=falsebooleanstillscrolling=falseif(emptyline<){bottomreached=drawObject()}else{scrollDown()stillscrolling=true}drawBars()drawBlocks()if(stillscrolling||bottomreached){checkFull()}}ÏÔÊõÊÐÅÏpublicvoidshowIntro(){StringsdrawBars()drawBlocks()if(showtitle){goffsetFont(largefont)s="íÂÞËwhite)goffdrawString(s,barwidth(widthfmlargestringWidth(s)),height)}else{goffsetFont(smallfont)s="ÇëÏÂ'S'üªÊÓÎÏ"goffsetColor(textcolor)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)goffsetColor(Colorwhite)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)s="ÊÓÃ×óÓÒÏòüØÖÆÔË"goffsetColor(textcolor)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)goffsetColor(Colorwhite)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)s="ÊÓÃÏòÉϵÄÏòüʵÏÖÐýת"goffsetColor(textcolor)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)goffsetColor(Colorwhite)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)s="ÊÓÃÏòϵÄÏòüʵÏÖϵ"goffsetColor(textcolor)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)goffsetColor(Colorwhite)goffdrawString(s,barwidth(widthfmsmallstringWidth(s)),height)}screencountif(screencount<=){screencount=screendelayshowtitle=!showtitle}}publicvoiddrawBars(){goffsetColor(barcolor)gofffillRect(,,barwidth,blocksize*yblocks)gofffillRect(barwidthblocksize*xblocks,,barwidth,blocksize*yblocks)gofffillRect(,blocksize*yblocks,xblocks*blocksize*barwidth,barwidth)}publicbooleandrawObject(){shortibooleanbottomreached=falseintx,y,checkx,checkyÇåýÉÍÐÎfor(i=i<i){x=objectxitemsobjectptri*objectrotation*itemrotleny=objectyitemsobjectptri*objectrotation*itemrotlencheckx=objectxchecksobjectptri*objectrotation*itemrotlenchecky=objectychecksobjectptri*objectrotation*itemrotlenif(y>=)screendataxy=if(screendatacheckxchecky!=)bottomreached=true}if(!bottomreached){countif(count<=||fast){objectycount=curcount}checkRotation()objectdx=objectrotationd=}æÖÆÐÂÍÐÎfor(i=i<i){x=objectxitemsobjectptri*objectrotation*itemrotleny=objectyitemsobjectptri*objectrotation*itemrotlenif(y>=)screendataxy=objectcolorif(y>=(yblocks))bottomreached=true}if(bottomreached){scorenewObject()}returnbottomreached}publicvoidcheckRotation(){intdummyxintdummyrotintx,yshortibooleancando=truedummyrot=(objectrotationobjectrotationd)dummyx=objectxobjectdxÈÈÏÃÖáÊÆÁÄÐýתfor(i=i<i){x=dummyxitemsobjectptri*dummyrot*itemrotlenif(x>=xblocks)dummyx=(xxblocks)elseif(x<)dummyx=x}for(i=(i<cando)i){x=dummyxitemsobjectptri*dummyrot*itemrotleny=objectyitemsobjectptri*dummyrot*itemrotlenif(y>=)cando=cafor(y=y<yblocksy){goffsetColor(blocksscreendataxy)goffdrawRect(x*blocksizebarwidth,y*blocksize,blocksize,blocksize)gofffillRect(x*blocksizebarwidth,y*blocksize,blocksize,blocksize)}}}publicvoidcheckFull(){shortx,ybooleanfound=falsefor(y=yblocks(y>=!found)y){found=truefor(x=x<xblocksx){if(screendataxy==)found=false}if(found){score=µÓõĵÃÖºÜàÊÔöÓÓÎÏËÙÈif(score>)curcount=elseif(score>)curcount=elseif(score>)curcount=elseif(score>)curcount=for(x=x<xblocksx){screendataxy=}emptyline=y}}}publicvoidscrollDown(){shortx,yfor(y=emptyliney>y){for(x=x<xblocksx){screendataxy=screendataxy}}for(x=x<xblocksx){screendatax=}emptyline=}publicvoidshowScore(){StringsgoffsetFont(smallfont)goffsetColor(Colorwhite)s="µÃÖº"scoregoffdrawString(s,width,(yblocks)*blocksize)}publicvoidrun(){longstarttimeGraphicsgThreadcurrentThread()setPriority(ThreadMAXPRIORITY)g=getGraphics()while(true){starttime=SystemcurrentTimeMillis()try{paint(g)starttime=Threadsleep(Mathmax(,starttimeSystemcurrentTimeMillis()))}catch(InterruptedExceptione){break}}}publicvoidstart(){if(thethread==){thethread=newThread(this)thethreadstart()}}publicvoidstop(){if(thethread!=){thethreadstop()thethread=}}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/8

java小游戏编程

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利