马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
运用此方法积分不能正常增加,同时在经过几次管道后异常判定游戏失败。<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
#bodyss {
float: left;
}
body {
background-color: antiquewhite;
}
a {
text-decoration: none;
color: black;
float: left;
}
#head {
margin-top: 5px;
}
.biaoti {
border-bottom: 5px solid black;
text-align: center;
font-size: 30px;
}
.anniua {
background-color: cadetblue;
font-size: 18px;
font-weight: 700;
}
.clear {
clear: both;
}
#changjing {
width: 800px;
height: 600px;
margin-top: 50px;
background-color: skyblue;
}
.guangdao {
width: 40px;
height: 100px;
background-color: cadetblue;
position: absolute;
animation: guanleft 3s linear infinite;
}
#downguan {
top: 595px;
}
#niao {
width: 40px;
height: 40px;
background-color: burlywood;
position: absolute;
left: 100px;
top: 350px;
}
#jifen {
margin-left: 380px;
position: absolute;
font-size:30px;
font-weight:bolder;
}
@keyframes guanleft {
from {
left: 700px
}
to {
left: 0px;
}
}
</style>
</head>
<body id="bodybox">
<div id="box">
<h3 class="biaoti" id="title"><a href="小工具.html">首页</a>管道鸟</h3>
<div id="niao"></div>
<div id="changjing">
<div id="jifen">0</div>
<div class="guangdao" id="upguan"></div>
<div class="guangdao" id="downguan"></div>
</div>
</div>
<script>
const niao = document.querySelector("#niao");
const changjing = document.querySelector("#changjing");
const uguan = document.querySelector("#upguan")
const dguan = document.querySelector("#downguan")
//初始化
returnall();
function returnall() {
niao.style.top = `350px`
}
//鸟的落体运动
let bridheight = 350
function birddown() {
bridheight = (niao.style.top).slice(0, -2)
niao.style.top = `${+bridheight + 2}px`
panding()
if (bridheight > 655) {
clearInterval(jishi1)
// alert("lost")
}
}
let jishi1 = setInterval(birddown, 10)
//点击使鸟能够上升
window.onclick = function () {
let bridheight = (niao.style.top).slice(0, -2)
niao.style.top = `${+bridheight - 60}px`
panding()
if (bridheight < 140) {
clearInterval(jishi1)
//alert("lost")
}
}
//管道
let uplenth = 100, downlenth = 100;//上下管子长度
let alllenth = 200;//管子总长度
//管道的长度随机以及位置处理
function lenth() {
uplenth = getInt(0, alllenth)
downlenth = alllenth - uplenth
if (downlenth < 0) {
downlenth = 0
}
if (uplenth > alllenth) {
uplenth = alllenth
}
uguan.style.height = `${uplenth}px`
dguan.style.height = `${downlenth}px`
dguan.style.top = `${695 - downlenth}px`
alllenth = alllenth + 5
}
setInterval(lenth, 3000)
//经过管道判定
const jifen = document.querySelector("#jifen");
let ji = 0
let uleft = uguan.offsetLeft
function panding() {
uleft = uguan.offsetLeft
if (uleft <= 140) {
if ((bridheight > 140 + uplenth) && (bridheight < 655 - downlenth)) {
if (uleft == 140) {
jifen.innerHTML = ji++;
}
}
else {
alert('lost')
}
}
}
//等待函数
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
//获取随机整数
function getInt(min = 0, max = 10) {
let mid
if (min > max) {
mid = min
min = max
max = mid
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
</body>
</html>
|