dom
This commit is contained in:
BIN
R4.01_R4.A.10/td_tp/tp2/src/ex1/img/mole-whacked.png
Normal file
BIN
R4.01_R4.A.10/td_tp/tp2/src/ex1/img/mole-whacked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
R4.01_R4.A.10/td_tp/tp2/src/ex1/img/mole2.png
Normal file
BIN
R4.01_R4.A.10/td_tp/tp2/src/ex1/img/mole2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
37
R4.01_R4.A.10/td_tp/tp2/src/ex1/index.html
Normal file
37
R4.01_R4.A.10/td_tp/tp2/src/ex1/index.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Whack-a-Mole Game</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||
>
|
||||
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="game">
|
||||
<h1>Whack-a-Mole!</h1>
|
||||
<div class="score-board">
|
||||
<span>Score: </span><span id="score">0</span>
|
||||
</div>
|
||||
<div class="holes">
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole up"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
<div class="hole"><div class="mole"><img src="img/mole2.png"></div></div>
|
||||
</div>
|
||||
<button id="startButton">START</button>
|
||||
</div>
|
||||
</main>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
53
R4.01_R4.A.10/td_tp/tp2/src/ex1/script.js
Normal file
53
R4.01_R4.A.10/td_tp/tp2/src/ex1/script.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const holes = document.querySelectorAll('.hole');
|
||||
const moles = document.querySelectorAll('.mole');
|
||||
const scoreBoard = document.getElementById('score');
|
||||
const startButton = document.getElementById('startButton');
|
||||
|
||||
let lastHole;
|
||||
let timeUp = false;
|
||||
let score = 0;
|
||||
let duration = 30
|
||||
|
||||
function randomTime(min, max) {
|
||||
return Math.round(Math.random() * (max - min) + min);
|
||||
}
|
||||
|
||||
function randomHole(holes) {
|
||||
const idx = Math.floor(Math.random() * holes.length);
|
||||
const hole = holes[idx];
|
||||
if (hole === lastHole) {
|
||||
return randomHole(holes);
|
||||
}
|
||||
lastHole = hole;
|
||||
return hole;
|
||||
}
|
||||
|
||||
function peep() {
|
||||
const time = randomTime(1000, 1500);
|
||||
const holerandomHole(holes);
|
||||
|
||||
// TODO
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
// TODO
|
||||
//
|
||||
}}, time);
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
scoreBoard.textContent = 0;
|
||||
score = 0;
|
||||
timeUp = false;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
function bonk(e) {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
moles.forEach(mole => mole.addEventListener('click', bonk));
|
||||
startButton.addEventListener('click', startGame);
|
||||
68
R4.01_R4.A.10/td_tp/tp2/src/ex1/styles.css
Normal file
68
R4.01_R4.A.10/td_tp/tp2/src/ex1/styles.css
Normal file
@@ -0,0 +1,68 @@
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-color: #f0f0f0;
|
||||
/* font-family: Arial, sans-serif;*/
|
||||
}
|
||||
|
||||
.game {
|
||||
text-align: center;
|
||||
}
|
||||
.holes {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
flex-wrap: wrap;
|
||||
width: 400px;
|
||||
margin: 20px auto;
|
||||
}
|
||||
|
||||
.hole {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background : radial-gradient(rgb(150,250,150), #00ee00);
|
||||
|
||||
/* background-color: red;/*#8b4513;*/
|
||||
/* background-image : url('img/mole2.png');*/
|
||||
position: relative;
|
||||
border-radius: 50%;
|
||||
margin: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.mole img{
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
/* background-color: #555;*/
|
||||
position: absolute;
|
||||
bottom: -100px;
|
||||
left: 0px;
|
||||
/*border-radius: 50%;*/
|
||||
transition: bottom 0.3s;
|
||||
}
|
||||
|
||||
.mole.up img{
|
||||
/* background-image : url('img/mole2.png');
|
||||
background-size:contain;
|
||||
background-repeat: no-repeat;*/
|
||||
width:90px;
|
||||
height:90px;
|
||||
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
.mole.whacked img {
|
||||
content: url('img/mole-whacked.png');
|
||||
/* background-image : url('img/mole-whacked.png');
|
||||
background-size:contain;
|
||||
background-repeat: no-repeat;*/
|
||||
width:90px;
|
||||
height:90px;
|
||||
|
||||
bottom: -20px;
|
||||
}
|
||||
.score-board {
|
||||
font-size: 1.5em;
|
||||
margin: 20px;
|
||||
}
|
||||
Reference in New Issue
Block a user