Jquery是一个适配性很强的程序,相比于andriod系统语言,更容易上手,而且通过java形式完全可以转化成apk文件,实现软件安装,这种网络教程很多,感兴趣的朋友可以自行搜索。
本文是一个通过Jquery实现的贪吃蛇小游戏,并且已成功在安卓手机上安装,具体界面如下:
实现代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equip="Content_Type" content="text/html;charset=utf-8"/>
<title>贪吃蛇</title>
<meta name="viewport" content="width=device-width,shrink-to-fit=no">
<link rel="stylesheet" href="index.css"/>
</head>
<body>
<div class="background">
<p class="score">您的成绩:<span>0</span></p>
<div class="snake start"></div>
</div>
<div class="begin">
<ul>
<li><input type="button" id="btn_begin" value="开始"/></li>
<li><input type="button" id="btn_exit" value="退出"/></li>
</ul>
</div>
<div class="GameOver">
<h1>GAME OVER</h1>
</div>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
*{
margin: 0px;
padding: 0px;
list-style: none;
}
body{
position: relative;
}
.background{
position: relative;
top: 50px;
z-index: -1;
margin: 20px auto;
width: 1000px;
height: 600px;
border: solid 2px ;
background-color: bisque;
}
.snake{
display: inline-block;
border: solid 1px;
width: 20px;
height: 20px;
background-color: saddlebrown;
border-radius: 40%;
position: absolute;
z-index: 10px;
}
.start{
top:300px;
left: 100px;
}
.snake_boby{
display: inline-block;
border: solid 1px;
width: 20px;
height: 20px;
background-color: yellowgreen;
position: absolute;
border-radius: 40%;
z-index: 10px;
}
.food{
display: inline-block;
border: solid 0.5px;
width: 20px;
height: 20px;
background-color:red;
border-radius:50%;
position: absolute;
z-index: 10px;
}
.score{
position: absolute;
font-size: 20px;
top: -30px;
left: 0px;
}
.begin {
position: absolute;
top: 300px;
left:650px;
transform: translateX(-50%);
border: solid 1px;
background-size: 300px ;
width: 150px;
height: 100px;
}
.begin ul li input{
width: 150px;
height: 50px;
line-height: 30px;
border: none;
background-color: #7dbb32;
cursor: pointer;
border-radius: .3em;
box-shadow: 0 1px white inset;
text-align: center;
text-shadow: 0 1px 1px black;
color:white;
font-weight: bold;
outline: none;
}
.GameOver{
display: none;
}
.GameOver h1{
text-align: center;
margin-top: -380px;
margin-left: 380px;
color:red;
font-size: 38px;
font-weight: bold;
text-shadow: 2px 2px 0 white;
position: absolute;
}
如果各位对源代码感兴趣,可以到我的主页下载,文件里也有apk文件,无广告,无病毒,也可以自己安装试试。