javascript中蛇游戏的不完整代码 [英] incomplete code of snake game in javascript

查看:78
本文介绍了javascript中蛇游戏的不完整代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以通过javascript提供蛇游戏的代码来帮助我。

我想要非常基本的代码



我试过一些代码



#main {

身高:500px;

宽度:500px;

border:black;

background-color:#CCC;





}

#food {

宽度:10px;

身高:10px;

背景颜色:黑色;

位置:绝对;

}

.snake {

宽度:10px;

身高: 10px;

背景颜色:黑色;

位置:继承;



}



< / style>





< / head>



< script>



函数init(){



函数move(其他,x,y){







var a = document.getElementById (食物);

//警告(x =+ a.st yle.left +,y =+ a.style.top);

a.style.left = x +px;

a.style.top = y + px;







}

fucnction createElement(){

document.createElement(





函数随机(a,b){

var ran_x = parseInt(Math.random()*(ba)+ a);

var ran_y = parseInt(Math.random()*(ba)+ a);

move(food,ran_x,ran_y);



}

setInterval(function(){Random(1,500) }},1500);



}



< / script>

<bodyönload=init()>

Can someone help me by providing the code of snake game in javascript.
I want the very basic code

I have tried some code

#main{
height:500px;
width:500px;
border:black;
background-color:#CCC;


}
#food{
width:10px;
height:10px;
background-color:black;
position:absolute;
}
.snake{
width:10px;
height:10px;
background-color:black;
position:inherit;

}

</style>


</head>

<script>

function init(){

function move(other,x,y){



var a= document.getElementById("food");
//alert("x= "+a.style.left+", y= "+a.style.top);
a.style.left= x+"px";
a.style.top= y+"px";



}
fucnction createElement(){
document.createElement(
}

function Random(a,b){
var ran_x = parseInt(Math.random()*(b-a)+a);
var ran_y = parseInt(Math.random()*(b-a)+a);
move("food",ran_x,ran_y);

}
setInterval(function(){ Random(1,500)},1500);

}

</script>
<body önload="init()">






















< / body> ;

< / html>



以上代码生成食物bt后我有s tuck任何人都可以引导我

(只有纯粹的JAVASCRIPT)




</body>
</html>

the above code generate the food bt after that i have stuck can anyone plz guide me
(ONLY PURE JAVASCRIPT)

推荐答案

不,这不是它的工作方式。

您尝试这样做,遇到问题,请求帮助。



我们不在此为您提供完整代码 - 这是你的功课,你应该继续下去!
No, that''s not how it works.
You try to do it, you get a problem, you ask for help.

We are not here to provide "full code" for you - that is your homework, and you should get on with it!


这篇关于javascript中蛇游戏的不完整代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆