热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

短代码的java打地鼠_使用JavaScript实现网页版Pongo设计思路及源代码分享

varifingame0;varmaxgrade0,grade0;vargrade1,grade2;varnickname;vargamespeed1.4;小球速度varlines

var ifingame=0;

var maxgrade=0,grade=0;

var grade1,grade2;

var nickname;

var gamespeed=1.4;//小球速度

var linespeed=Math.PI/95; //跟踪线速度

var crashdistancefaild=-7;//碰撞检测参数

var crashdistancesucc=15

var fantanjuli=7;

var themaxgradeline=12.1;

function getCOOKIE1(nickname)

{

if (document.COOKIE.length>0)

{

c_start=document.COOKIE.indexOf(nickname + "=")

if (c_start!=-1)

{

c_start=c_start + nickname.length+1;

c_end=document.COOKIE.indexOf(",",c_start);

if (c_end==-1)

c_end=document.COOKIE.length;

return unescape(document.COOKIE.substring(c_start,c_end));

}

}

return ""

}

function getCOOKIE2(mymaxgrade)

{

if (document.COOKIE.length>0)

{

c_start=document.COOKIE.indexOf(mymaxgrade + "=")

if (c_start!=-1)

{

c_start=c_start + mymaxgrade.length+1;

c_end=document.COOKIE.indexOf(";",c_start);

if (c_end==-1)

c_end=document.COOKIE.length;

return unescape(document.COOKIE.substring(c_start,c_end));

}

}

return ""

}

function setCOOKIE(nickname,value,mymaxgrade,maxgrade,expiredays)

{

var exdate=new Date()

exdate.setDate(exdate.getDate()+expiredays)

document.COOKIE=nickname+ "=" +escape(value)+"," + mymaxgrade + "=" + escape(maxgrade) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString());

}

function checkCOOKIE()

{

nickname=getCOOKIE1('nickname');

maxgrade=parseInt(getCOOKIE2('mymaxgrade'));

if(isNaN(maxgrade)==true)

{

maxgrade=0;

}

if (nickname!=null && nickname!="")

{

alert('欢迎'+nickname+'回来!'+'\n'+"如果喜欢请分享一下哈~");

}

else

{

nickname=prompt('请输入你的昵称:(名字太长上榜可是会显示不完整的哦)',"")

if (nickname!=null && nickname!="")

{

var maxgradestring=maxgrade.toString();

setCOOKIE('nickname',nickname,'mymaxgrade',maxgradestring,365);

}

}

}

var objpane=document.getElementById("pane");

var ctxpane=objpane.getContext("2d");

ctxpane.translate(150,150);//必备 画布中心点平移

function sendmail()

{

if(grade2>themaxgradeline)

var max_grade=grade2;

window.location.href='index.php?max_grade='+max_grade+'&nick_name='+nickname;

/*    {

$grade=$_GET['max_grade'];

$nickname=$_GET['nick_name'];

$mail = new SaeMail();

$ret = $mail->quickSend( 'reasonpongo@163.com' , $grade , $nickname ,'reasonpongo@163.com' , 'mypongo' );

$mail->clean();

?>

}*/

alert(nickname+"你的成绩为:"+grade2+"提交成功~");

}

var gamedirection={

shang : 1,

xia  : 5,

zuo  : 7,

you  : 3,

zuoshang: 8,

zuoxia : 6,

youshang: 2,

youxia : 4,

clock : 0,

anticlock: 9,

};//方向

var canvas={

width : 300,

height: 300,

};//画布

var bigcircle = {//大圆参数

x : 0,    //圆心的x轴坐标值

y : 0,    //圆心的y轴坐标值

r : 150,  //圆的半径

c : 'rgb(255,255,255)',

};//大圆

var smallcircle = {//小圆参数

x : 0,    //圆心的x轴坐标值

y : 0,    //圆心的y轴坐标值

r : 12,  //圆的半径

c : 'rgb(204,105,106)',

direction :  gamedirection.xia,

};//小圆

var line = {//挡板线的参数

x : 0,    //圆心的x轴坐标值

y : 0,    //圆心的y轴坐标值

r : 150 ,  //圆弧的半径

start:(Math.PI/2-Math.PI/16),

end : (Math.PI/2+Math.PI/16),

c : 'rgb(55,55,55)',

direction: gamedirection.anticlock,

};//跟踪线

var dot = {//跟踪点参数

x : (bigcircle.r*Math.cos(line.start+Math.PI/16)),//以大圆为原点

y : (bigcircle.r*Math.sin(line.start+Math.PI/16)),

r : 1,

}//跟踪点

function changelinedirection()

{

if(line.direction==gamedirection.clock)

{

line.direction=gamedirection.anticlock;

}

else

{

line.direction=gamedirection.clock;

}

}

function getdistance(){

var distance=Math.sqrt((smallcircle.x)*(smallcircle.x )+(smallcircle.y )*(smallcircle.y ));

return distance;

}//返回小球与大圆中心距离平方 getdistance()

function ifgameover(){//判断是否出界

if((getdistance() - bigcircle.r)>5)

return true;

else

return false;

} //判断游戏是否结束 ifgameover()

function ifcrash(){  //碰撞检测

var dx = dot.x-smallcircle.x;

var dy = dot.y-smallcircle.y;

var dd=Math.sqrt(dx*dx+dy*dy);

if(dd

return true;

else

return false;

}//碰撞检测 ifcrash()

function randomback()

{

var x=Math.floor(Math.random()*3);

switch (smallcircle.direction){

case gamedirection.shang:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.xia;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.zuoxia;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.youxia;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.xia:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.shang;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.zuoshang;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.youshang;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.zuo:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.you;

smallcircle.x=smallcircle.x+fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.youshang;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.youxia;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.you:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.zuo;

smallcircle.x=smallcircle.x-fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.zuoxia;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.zuoshang;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.zuoshang:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.youxia;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.xia;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.you;

smallcircle.x=smallcircle.x+fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.zuoxia:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.youshang;

smallcircle.x=smallcircle.x+fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.shang;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.you;

smallcircle.x=smallcircle.x+fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.youshang:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.zuoxia;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y+fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.zuo;

smallcircle.x=smallcircle.x-fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.xia;

smallcircle.y=smallcircle.y+fantanjuli;

break;

default:

break;

} break;

}

case gamedirection.youxia:

{

switch (x)

{

case 0:

smallcircle.direction=gamedirection.zuoshang;

smallcircle.x=smallcircle.x-fantanjuli;

smallcircle.y=smallcircle.y-fantanjuli;

break;

case 1:

smallcircle.direction=gamedirection.zuo;

smallcircle.x=smallcircle.x-fantanjuli;

break;

case 2:

smallcircle.direction=gamedirection.shang;

smallcircle.y=smallcircle.y-fantanjuli;

break;

default:

break;

} break;

}

default:

{

break;

}

}

}//小球随机反向 randomback()

function smallcircledirection()

{

switch (smallcircle.direction){    //根据小球方向做移动

case gamedirection.shang:

{

smallcircle.y=smallcircle.y-gamespeed;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.xia:

{

smallcircle.y=smallcircle.y+gamespeed;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.zuo:

{

smallcircle.x=smallcircle.x-gamespeed;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.you:

{

smallcircle.x=smallcircle.x+gamespeed;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.zuoshang:

{

smallcircle.x=smallcircle.x-gamespeed*0.8;

smallcircle.y=smallcircle.y-gamespeed*0.8;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.zuoxia:

{

smallcircle.x=smallcircle.x-gamespeed*0.8;

smallcircle.y=smallcircle.y+gamespeed*0.8;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.youshang:

{

smallcircle.x=smallcircle.x+gamespeed*0.8;

smallcircle.y=smallcircle.y-gamespeed*0.8;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

case gamedirection.youxia:

{

smallcircle.x=smallcircle.x+gamespeed*0.8;

smallcircle.y=smallcircle.y+gamespeed*0.8;

grade++;

if(grade>maxgrade)

{

maxgrade=grade;

newrecoder();

}

addone();

break;

}

default:

{

break;

}

}

}//小球移动 smallcircledirection()

/*画出底部圆*/

ctxpane.beginPath(); //大圆

ctxpane.arc(bigcircle.x,bigcircle.y,bigcircle.r,0,Math.PI*2,true);

ctxpane.fillStyle = bigcircle.c;

ctxpane.fill();

ctxpane.closePath();

/*画出底部追踪线条*/

ctxpane.beginPath();

ctxpane.lineWidth=6;

ctxpane.strokeStyle = line.c;

ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);

ctxpane.stroke();

ctxpane.closePath();

function tapme()//tapme

{

ctxpane.beginPath();

ctxpane.strokeStyle="rgb(255,222,195)";

ctxpane.font = "80px Papyrus";

ctxpane.strokeText('TAP',-95,30);

ctxpane.fillStyle="rgb(255,205,105)";

ctxpane.font = "35px Papyrus";

ctxpane.fillText('me',70,30);

ctxpane.closePath();

}

function newrecoder()

{

ctxpane.beginPath();

ctxpane.fillStyle="rgb(255,0,0)";

ctxpane.font = "18px Papyrus";

ctxpane.fillText("New!",58,80);

ctxpane.closePath();

}

function addone()

{

grade1=(grade/150).toFixed(1);

grade2=(maxgrade/150).toFixed(1);

var say1="now";

var say2="best"

ctxpane.beginPath();

ctxpane.strokeStyle="rgb(250,222,185)";

ctxpane.font = "60px Papyrus";

ctxpane.strokeText(grade1,-45,-60);

ctxpane.strokeText(grade2,-45,100);

ctxpane.fillStyle="rgb(255,0,100)";

ctxpane.font = "15px Papyrus";

ctxpane.fillText(say1,58,-60);

ctxpane.fillStyle="rgb(255,0,100)";

ctxpane.font = "15px Papyrus";

ctxpane.fillText(say2,58,100);

ctxpane.closePath();

}

function movetest(){

if(ifgameover())

{

ifingame=0;

if(maxgrade>parseInt(getCOOKIE2('mymaxgrade')))

{

setCOOKIE('nickname',nickname,'mymaxgrade',maxgrade.toString(),365);

}

clearInterval(timer);

tapme();

}

else

{

if(ifcrash())

{

randomback();

}

ctxpane.clearRect(-150,-150,300,300); //清屏

ctxpane.beginPath(); //大圆

ctxpane.arc(bigcircle.x,bigcircle.y,bigcircle.r,0,Math.PI*2,true);

ctxpane.fillStyle = bigcircle.c;

ctxpane.fill();

ctxpane.closePath();

if(line.direction==gamedirection.clock)   //跟踪线顺时针

{

line.start=line.start + linespeed;

line.end=line.end +linespeed;

ctxpane.beginPath();

ctxpane.lineWidth=4;

ctxpane.strokeStyle = line.c;

ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);

ctxpane.stroke();

ctxpane.closePath();

}

if(line.direction==gamedirection.anticlock)         //跟踪逆顺时针

{

line.start=line.start - linespeed;

line.end=line.end -linespeed;

ctxpane.beginPath();

ctxpane.lineWidth=4;

ctxpane.strokeStyle = line.c;

ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);

ctxpane.stroke();

ctxpane.closePath();

}

dot.x=bigcircle.r*Math.cos(line.start+Math.PI/32) //跟踪点

dot.y=bigcircle.r*Math.sin(line.start+Math.PI/32)

ctxpane.beginPath();//线上跟踪点

ctxpane.arc(dot.x,dot.y,dot.r,0,Math.PI*2,true);

ctxpane.fillStyle = smallcircle.c;

ctxpane.fill();

ctxpane.closePath();

smallcircledirection();//小圆

ctxpane.save();

ctxpane.beginPath();

ctxpane.arc(smallcircle.x,smallcircle.y,smallcircle.r,0,Math.PI*2,true);

ctxpane.fillStyle = smallcircle.c;

ctxpane.fill();

ctxpane.closePath();

ctxpane.restore();

}

}//主函数

///

tapme();

var timer;

function startgame(){//开始游戏

if(ifingame==0)

{

ifingame=1;

grade=0;

var xx=Math.floor(Math.random()*8);

/*      switch(xx)

{

case 0:

smallcircle.direction=gamedirection.shang;

break;

case 1:

smallcircle.direction=gamedirection.xia;

break;

case 2:

smallcircle.direction=gamedirection.zuo;

break;

case 3:

smallcircle.direction=gamedirection.you;

break;

case 4:

smallcircle.direction=gamedirection.zuoshang;

break;

case 5:

smallcircle.direction=gamedirection.zuoxia;

break;

case 6:

smallcircle.direction=gamedirection.youshang;

break;

case 7:

smallcircle.direction=gamedirection.youxia;

break;

default:

break;

}*/

smallcircle.direction=gamedirection.xia;

smallcircle.x=smallcircle.y=0;

line.start=Math.PI/2-Math.PI/26;

line.end=Math.PI/2+Math.PI/26;

line.direction=gamedirection.anticlock;

clearInterval(timer);

timer=setInterval(movetest,10);

}

}//开始游戏 startgame()

function opentop()

{

window.location="http://pongotop.sinaapp.com";

}



推荐阅读
author-avatar
骨感小男人2502861673_698
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有