TP01, TP02 & TP03EX01

This commit is contained in:
2024-02-26 19:17:32 +01:00
commit 2cfb5211c3
28 changed files with 1147 additions and 0 deletions

26
TP03/EX01/cookie.html Normal file
View File

@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Cookie clicker</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="container">
<h1>Cookie clicker</h1>
<figure>
<img id="cookie"src="img/cookie.png" alt="cookie">
<span id="score">0</span>
</figure>
<button id="btnStart">start</button>
<p id="meme" class="hidden">
<img src="img/memee.png" alt="memee" width="64" height="64">
<span id="temps"></span>
</p>
</div>
<script type="text/javascript" src="./js/game.js"></script>
</body>
</html>

BIN
TP03/EX01/css/img/bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

63
TP03/EX01/css/style.css Normal file
View File

@@ -0,0 +1,63 @@
@import url(https://fonts.googleapis.com/css?family=Kavoon);
body {
background-image: url("img/bg.jpg");
background-repeat: repeat;
font-family: Kavoon;
font-size: 24px;
text-align: center;
color: white;
}
.container {
max-width: 320px;
margin: auto;
}
h1 {
font-size: 28px;
background-color: rgba(0, 0, 0, 0.25);
padding: 10px 40px 10px 40px;
border-radius: 10px;
}
figure {
position: relative;
margin: 0;
}
figure > span {
position: absolute;
top: 25px;
right: 50px;
border-radius: 21px;
height: 42px;
width: 56px;
background-color: #f4d03f;
box-shadow: 4px 4px 4px black;
padding-top: 9px;
}
button {
display: block;
width: 100%;
font-family: Kavoon;
font-size: 24px;
background-color: white;
padding: 9px;
border-radius: 10px;
border-width: 0;
}
p {
text-align: left;
}
img[alt="GrandMa"] {
float: left;
}
.hidden {
display: none;
}

BIN
TP03/EX01/img/bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
TP03/EX01/img/cookie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
TP03/EX01/img/memee.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

48
TP03/EX01/js/game.js Normal file
View File

@@ -0,0 +1,48 @@
var btnStart = document.getElementById("btnStart");
var scoreView = document.getElementById("score");
var tempsView = document.getElementById("temps");
var meme = document.getElementById("meme");
var cookie = document.getElementById("cookie");
var score;
var temps;
var isPlayed=false;
var texte = " seconds left!";
var tailleCookieInitiale = cookie.naturalWidth;
btnStart.addEventListener('click', start);
cookie.addEventListener('click', clicCookie);
tempsView.style.color = "red";
function start(event){
if (!isPlayed){
meme.style.display="block";
cookie.style.width = tailleCookieInitiale+"px";
temps = 15;
score = 0;
scoreView.textContent = score;
isPlayed = true;
tempsView.textContent = temps+texte;
setTimeout(second,1000);
}
}
function clicCookie(event){
if (isPlayed){
score ++;
cookie.style.width = (tailleCookieInitiale+score)+"px";
scoreView.textContent = score;
}
}
function second(){
temps --;
tempsView.textContent = temps+texte;
if (temps <= 0){
isPlayed = false;
meme.style.display="none";
}
else{
setTimeout(second,1000);
}
}