pull/271/merge
zhangyi-user 7 months ago committed by GitHub
commit 0918a28e1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
{
}

@ -9,7 +9,25 @@
<body> <body>
<div class="screen"> <div class="screen">
<h1>Catch The Insect</h1> <h1>Catch The Insect</h1>
<div class="speed-selector">
<label for="speed">Speed:</label>
<select id="speed">
<option value="1">1x</option>
<option value="2">2x</option>
<option value="3">3x</option>
<option value="4">4x</option>
<option value="5">5x</option>
<option value="6">6x</option>
<option value="7">7x</option>
<option value="8">8x</option>
<option value="9">9x</option>
<option value="10">10x</option>
</select>
</div>
<button class="btn" id="start-btn">Play Game</button> <button class="btn" id="start-btn">Play Game</button>
<div class="high-score-display">
<span>High Score: <span id="high-score-menu">0</span></span>
</div>
</div> </div>
<div class="screen"> <div class="screen">
@ -48,12 +66,49 @@
/> />
</button> </button>
</li> </li>
<li>
<button class="choose-insect-btn">
<p>Bee</p>
<img
src="https://cdn-icons-png.flaticon.com/512/616/616492.png"
alt="bee"
/>
</button>
</li>
<li>
<button class="choose-insect-btn">
<p>Butterfly</p>
<img
src="https://cdn-icons-png.flaticon.com/512/1866/1866304.png"
alt="butterfly"
/>
</button>
</li>
<li>
<button class="choose-insect-btn">
<p>Ant</p>
<img
src="https://cdn-icons-png.flaticon.com/512/1866/1866327.png"
alt="ant"
/>
</button>
</li>
<li>
<button class="choose-insect-btn">
<p>Ladybug</p>
<img
src="https://cdn-icons-png.flaticon.com/512/2330/2330867.png"
alt="ladybug"
/>
</button>
</li>
</ul> </ul>
</div> </div>
<div class="screen game-container" id="game-container"> <div class="screen game-container" id="game-container">
<h3 id="time" class="time">Time: 00:00</h3> <h3 id="time" class="time">Time: 00:00</h3>
<h3 id="score" class="score">Score: 0</h3> <h3 id="score" class="score">Score: 0</h3>
<h3 id="high-score" class="high-score">Best: 0</h3>
<h5 id="message" class="message"> <h5 id="message" class="message">
Are you annoyed yet? <br> Are you annoyed yet? <br>
You are playing an impossible game!! You are playing an impossible game!!

@ -5,11 +5,23 @@ const game_container = document.getElementById('game-container')
const timeEl = document.getElementById('time') const timeEl = document.getElementById('time')
const scoreEl = document.getElementById('score') const scoreEl = document.getElementById('score')
const message = document.getElementById('message') const message = document.getElementById('message')
const highScoreEl = document.getElementById('high-score')
const highScoreMenuEl = document.getElementById('high-score-menu')
const speedSelect = document.getElementById('speed')
let seconds = 0 let seconds = 0
let score = 0 let score = 0
let selected_insect = {} let selected_insect = {}
let speed = 1
let highScore = localStorage.getItem('insectGameHighScore') || 0
highScoreMenuEl.innerHTML = highScore
highScoreEl.innerHTML = `Best: ${highScore}`
start_btn.addEventListener('click', () => screens[0].classList.add('up')) start_btn.addEventListener('click', () => {
speed = parseInt(speedSelect.value)
screens[0].classList.add('up')
})
choose_insect_btns.forEach(btn => { choose_insect_btns.forEach(btn => {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
@ -23,6 +35,7 @@ choose_insect_btns.forEach(btn => {
}) })
}) })
function startGame() { function startGame() {
setInterval(increaseTime, 1000) setInterval(increaseTime, 1000)
} }
@ -65,8 +78,9 @@ function catchInsect() {
} }
function addInsects() { function addInsects() {
setTimeout(createInsect, 1000) const baseDelay = 1000 / speed
setTimeout(createInsect, 1500) setTimeout(createInsect, baseDelay)
setTimeout(createInsect, baseDelay * 1.5)
} }
function increaseScore() { function increaseScore() {
@ -75,4 +89,11 @@ function increaseScore() {
message.classList.add('visible') message.classList.add('visible')
} }
scoreEl.innerHTML = `Score: ${score}` scoreEl.innerHTML = `Score: ${score}`
if(score > highScore) {
highScore = score
localStorage.setItem('insectGameHighScore', highScore)
highScoreEl.innerHTML = `Best: ${highScore}`
highScoreMenuEl.innerHTML = highScore
}
} }

@ -39,6 +39,34 @@ h1 {
outline: 0; outline: 0;
} }
.speed-selector {
margin: 20px 0;
font-size: 14px;
}
.speed-selector label {
margin-right: 10px;
}
.speed-selector select {
padding: 10px 15px;
font-family: inherit;
font-size: 14px;
border: 2px solid #fff;
background-color: #fff;
color: #516dff;
cursor: pointer;
}
.speed-selector select:focus {
outline: 0;
}
.high-score-display {
margin-top: 20px;
font-size: 12px;
}
.screen { .screen {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -108,6 +136,13 @@ h1 {
right: 20px; right: 20px;
} }
.high-score {
position: absolute;
top: 50px;
right: 20px;
font-size: 12px;
}
.message { .message {
line-height: 1.7; line-height: 1.7;
background-color: rgba(0, 0, 0, 0.5); background-color: rgba(0, 0, 0, 0.5);

Loading…
Cancel
Save