版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、使用html+css+js實現(xiàn)彈球游戲用法html+css+js實現(xiàn)彈球嬉戲17969075ca2705a31a16ae54b880bb9.png代碼如下,復(fù)制即可用法:.panelposition:relative;z-index:0;top:0px;left:400px;width:300px;height:500px;.consoleposition:absolute;z-index:1;top:0;left:0;width:100%;height:40px;background-color:bbb;.messageposition:absolute;z-index:1;top:40px
2、;left:0;width:100%;height:460px;color:white;font-size:50px;text-align:center;line-height:460px;background-color:999;.start,.score,.pauseposition:absolute;z-index:2;top:0;width:100px;height:100%;font-size:large;color:white;text-align:center;line-height:40px;background:-webkit-linear-gradient(top,4ca8
3、ff,yellow);.startleft:0px;.scoreleft:100px;background-color:red;.pauseleft:200px;.start:after,.pause:beforecontent:""position:absolute;z-index:2;top:0;width:3px;height:100%;background:-webkit-linear-gradient(top,666,999);.start:afterleft:97px;.pause:beforeleft:0px;.start:hover,.pau
4、se:hovercursor:pointer;background:-webkit-linear-gradient(top,4ca8ff,red);.panelspanposition:absolute;z-index:0;top:50%;left:50%;font-size:50px;color:blue;.ball,.secondballposition:absolute;z-index:2;border-radius:50%;width:20px;height:20px;.balltop:460px;left:140px;background-color:red;.secondballt
5、op:40px;left:140px;background-color:red;.plateposition:absolute;top:480px;left:100px;z-index:2;width:100px;height:20px;background-color:e5e5e5;.promtemargin-top:20px;text-align:center;開頭0暫停提醒:鍵盤左右箭頭控制滑板(function()document.onkeydown=function(e)vare=e|window.event;if(e.keycode=37)/鍵盤向左鍵platemove(&
6、quot;left");elseif(e.keycode=39)/鍵盤向右鍵platemove("right");)();varpanel=document.getelementbyid("panel"),message=document.getelementbyid("message"),plate=document.getelementbyid("plate"),ball=document.getelementbyid(&
7、quot;ball"),start=document.getelementbyid("start"),score=document.getelementbyid("score"),pause=document.getelementbyid("pause"),secondball;varstartgame,x=x2=-1,y=y2=-1,speed=1,positionarr=,pauseactive=false,/一個標(biāo)記:表示難度是否還能增強flag=true,/球的
8、起始位置ballx,bally,secondballx,secondbally,/邊界minx=0,maxx=panel.offsetwidth-ball.offsetwidth,miny=40;maxy=panel.offsetheight-ball.offsetheight-plate.offsetheight;window.onload=function()if(window.addeventlistener)start.addeventlistener("click",startclick,false);pause.addeventlistener(
9、"click",pauseclick,false);elseif(window.attachevent)start.attachevent("onclik",startclick);pause.attachevent("onclik",pauseclick);elsestart.onclik=startclick;pause.onclik=pauseclick;functionplatemove(direction)if(direction="left"
10、;)if(plate.offsetleft>0)plate.style.left=(plate.offsetleft-30200?200:plate.offsetleft+30)+"px"functionstartclick()if(!pauseactive)resetgame();elsepauseactive=!pauseactive;startgame=setinterval(function()/console.log(ballx+"="+bally);positionarr=setposition(ball
11、x,bally,true);if(positionarr="gameover")return;ballx=positionarr0;bally=positionarr1;/設(shè)置球的位置ball.style.left=ballx+"px"ball.style.top=bally+"px"if(!flag)positionarr=setposition(secondballx,secondbally,false);secondballx=positionarr0;secondbally=po
12、sitionarr1;secondball.style.left=secondballx+"px"secondball.style.top=secondbally+"px"elseadddifficulty();,30);functionpauseclick()pauseactive=true;clearinterval(startgame);functionresetgame()clearinterval(startgame);message.innerhtml=""score.inn
13、erhtml="0"ball.style.left="140px"ball.style.top="460px"plate.style.left="100px"plate.style.top="480px"ballx=ball.offsetleft;bally=ball.offsettop;speed=1;flag=true;/其次個球設(shè)置躲藏if(secondball)secondball.style.display
14、="none"secondball.style.left="140px"secondball.style.top="40px"functionadddifficulty()if(parseint(score.innerhtml)>500&&parseint(score.innerhtml)2000&&parseint(score.innerhtml)5000)if(typeofsecondball!="
15、;undefined")secondball.style.display=""elsesecondball=document.createelement(&39;div&39;);secondball.classname=&39;secondball&39;panel.appendchild(secondball);secondballx=secondball.offsetleft;secondbally=secondball.offsettop;flag=false;functionsetposition(_x,_y,firstball)if(_x=minx|_x=maxx)/x*=-1;firstball?x*=-1:x2*=-1;if(_y=miny|_y=maxy)/y*=-1;firstball?y*=-1:y2*=-1;if(_y=m
溫馨提示
- 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)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2031年中國全硅化干粉行業(yè)投資前景及策略咨詢研究報告
- 2025至2030年中國霓虹燈沖擊變壓器數(shù)據(jù)監(jiān)測研究報告
- 2025年度公路護欄廢舊材料回收與再利用合同
- 2025年度共享智能停車服務(wù)合同
- 2025年度文化旅游產(chǎn)業(yè)合伙經(jīng)營合同(年度版)
- 2025年度國際貨運代理與跨境電商合作合同
- 2025年度房地產(chǎn)項目混凝土班組承包合同
- 2025年化妝品電商平臺廣告投放合同范本
- 2025年專賣店開設(shè)意向合同(2篇)
- 2025年度個人信用貸款合同規(guī)范
- 2024年公安機關(guān)理論考試題庫附答案【考試直接用】
- 課題申報參考:共同富裕進程中基本生活保障的內(nèi)涵及標(biāo)準(zhǔn)研究
- 2025年浙江嘉興桐鄉(xiāng)市水務(wù)集團限公司招聘10人高頻重點提升(共500題)附帶答案詳解
- 食品企業(yè)如何做好蟲鼠害防控集
- 2025中國聯(lián)通北京市分公司春季校園招聘高頻重點提升(共500題)附帶答案詳解
- 康復(fù)醫(yī)學(xué)科患者隱私保護制度
- 環(huán)保工程信息化施工方案
- 狂犬病暴露后預(yù)防處置
- 紅色中國風(fēng)2025蛇年介紹
- 2024年安徽省高考地理試卷真題(含答案逐題解析)
- 高等數(shù)學(xué)中符號的讀法及功能(挺全的)
評論
0/150
提交評論