Add all thing to the code
something
This commit is contained in:
102
www/js/backend.js
Normal file
102
www/js/backend.js
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user