Add all thing to the code

something
This commit is contained in:
2026-04-12 21:42:48 +02:00
commit 408acdc23b
12 changed files with 1304 additions and 0 deletions

87
www/js/ClockFrontEnd.js Normal file
View File

@@ -0,0 +1,87 @@
let white = document.getElementById("white_button");
let black = document.getElementById("black_button");
let white_time = document.getElementById("TimeWhite")
let black_time = document.getElementById("TimeBlack")
let black_move_left = document.getElementById("MoveLeftBlack")
let white_move_left = document.getElementById("MoveLeftWhite")
let BlockType = document.getElementById("BlockType")
let BlockTime = document.getElementById("BlockTime")
let trais = true
function msToMinSec(ms) {
const totalSeconds = Math.floor(ms / 1000);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}
function toggle_trais(){
trais = !trais
if (trais){
showGlowRight()
}else{
showGlowLeft()
}
}
function change_move_left_white(number){
white_move_left.innerText = `Coup restant Blanc : ${number}`
}
function change_move_left_black(number){
black_move_left.innerText = `Coup restant Noire : ${number}`
}
function change_time_block(Time){
BlockTime.innerText = `temps restant Block : ${msToMinSec(Time)}`
}
function set_block_type(type){
// true = +
// false = -
if (type){
BlockType.innerText = "Block +"
}else{
BlockType.innerText = "Block -"
}
}
function change_time_white(Time){
white_time.innerText = msToMinSec(Time)
}
function change_time_black(Time){
black_time.innerText = msToMinSec(Time)
}
white.addEventListener("pointerdown", () => {
if (!trais) white.classList.add("click");
if (!has_start) start()
else white_touch()
});
white.addEventListener("pointerup", () => {
white.classList.remove("click");
});
black.addEventListener("pointerdown", () => {
if (trais )black.classList.add("click");
black_touch()
});
black.addEventListener("pointerup", () => {
black.classList.remove("click");
});
function showGlowLeft() {
document.body.classList.remove("glow-right");
document.body.classList.add("glow-left");
}
function showGlowRight() {
document.body.classList.remove("glow-left");
document.body.classList.add("glow-right");
}
function hideGlow() {
document.body.classList.remove("glow-left", "glow-right");
}

1
www/js/appload.js Normal file
View File

@@ -0,0 +1 @@
show_scene("Clock");

102
www/js/backend.js Normal file
View File

@@ -0,0 +1,102 @@
let White = {
moveLeft : 0,
Time : 0,
TimeStartMove : 0
}
let Black = {
moveLeft : 0,
Time : 0,
TimeStartMove : 0
}
let has_start = false
Block = {
Type : false,
Time : 0,
last_time : 0
}
config = {
StartTime : 600000,
StartMoveLeft : 8,
BlockTime : 180000,
last_block : true
}
inizalize_clock()
function inizalize_clock(){
toggle_trais()
White.Time = config.StartTime
White.moveLeft = config.StartMoveLeft
Black.Time = config.StartTime
Black.moveLeft = config.StartMoveLeft
Block.Time = config.BlockTime
Block.Type = !config.last_block
change_move_left_black(Black.moveLeft)
change_move_left_white(White.moveLeft)
change_time_black(Black.Time)
change_time_white(White.Time)
change_time_block(Block.Time)
}
function start(){
White.TimeStartMove = Date.now()
Black.TimeStartMove = Date.now()
Block.last_time = Date.now()
update()
has_start = true
}
function load_cube_scene(){
hide_scene("Clock")
hideGlow()
show_scene("Cube")
}
function white_touch(){
if (trais) return null
if (!has_start) return null
toggle_trais()
Black.TimeStartMove = Date.now()
White.moveLeft -= 1
change_move_left_white(White.moveLeft)
}
function black_touch(){
if (!trais) return null
if (!has_start) return null
toggle_trais()
White.TimeStartMove = Date.now()
Black.moveLeft -= 1
change_move_left_black(Black.moveLeft)
if (Black.moveLeft == 0){
load_cube_scene()
}
}
function update() {
if (!trais) {// trais au blanc
White.Time -= (Date.now() - White.TimeStartMove)
White.TimeStartMove = Date.now()
}else{
Black.Time -= (Date.now() - Black.TimeStartMove)
Black.TimeStartMove = Date.now()
}
Block.Time -= (Date.now() - Block.last_time)
Block.last_time = Date.now()
if (Block.Time <= 0){
load_cube_scene()
}
change_time_white(White.Time)
change_time_black(Black.Time)
change_time_block(Block.Time)
requestAnimationFrame(update);
}

13
www/js/scene.js Normal file
View File

@@ -0,0 +1,13 @@
let last_scene = ""
function show_scene(name){
scene = document.getElementById("scene" + name);
console.log(scene)
last_scene = name
scene.style.display = "block";
}
function hide_scene(name){
scene = document.getElementById("scene" + name);
scene.style.display = "none";
}