Sure, here is a simple implementation of the game using HTML and JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fish Game</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
#play-area {
width: 100vw;
height: 100vh;
background-color: lightblue;
position: relative;
}
.fish {
width: 20px;
height: 20px;
position: absolute;
}
#yellow-fish {
background-color: yellow;
}
.red-fish {
background-color: red;
}
</style>
</head>
<body>
<div id="play-area"></div>
<script>
const playArea = document.getElementById('play-area');
const yellowFish = document.createElement('div');
yellowFish.id = 'yellow-fish';
yellowFish.classList.add('fish');
playArea.appendChild(yellowFish);
let score = 0;
let redFishSpeed = 1;
const redFishSize = 20;
function createRedFish() {
const redFish = document.createElement('div');
redFish.classList.add('fish');
redFish.classList.add('red-fish');
redFish.style.left = Math.random() * (window.innerWidth - redFishSize) + 'px';
redFish.style.top = Math.random() * (window.innerHeight - redFishSize) + 'px';
playArea.appendChild(redFish);
redFish.addEventListener('click', () => {
score++;
redFish.remove();
createRedFish();
if (score % 5 === 0) {
redFishSpeed++;
}
});
moveRedFish(redFish);
}
function moveRedFish(redFish) {
const directionX = Math.random() > 0.5 ? 1 : -1;
const directionY = Math.random() > 0.5 ? 1 : -1;
const speedX = Math.random() * redFishSpeed;
const speedY = Math.random() * redFishSpeed;
const interval = setInterval(() => {
const rect = redFish.getBoundingClientRect();
const newX = rect.left + directionX * speedX;
const newY = rect.top + directionY * speedY;
if (newX < 0 || newX > window.innerWidth - redFishSize || newY < 0 || newY > window.innerHeight - redFishSize) {
clearInterval(interval);
redFish.remove();
createRedFish();
} else {
redFish.style.left = newX + 'px';
redFish.style.top = newY + 'px';
}
}, 100);
}
createRedFish();
playArea.addEventListener('mousemove', (e) => {
const x = e.clientX - yellowFish.offsetWidth / 2;
const y = e.clientY - yellowFish.offsetHeight / 2;
yellowFish.style.left = x + 'px';
yellowFish.style.top = y + 'px';
});
setInterval(() => {
if (yellowFish.offsetLeft < 0 || yellowFish.offsetLeft > window.innerWidth - yellowFish.offsetWidth || yellowFish.offsetTop < 0 || yellowFish.offsetTop > window.innerHeight - yellowFish.offsetHeight) {
alert('Game Over! Your score: ' + score);
location.reload();
}
}, 100);
</script>
</body>
</html>
You can copy and paste this code into an HTML file and open it in a browser to play the game.