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

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);
}