3 ms·
please add go clock to (additional time)
by styczen 2y ago
please add go clock to (additional time)
- akkartik 2y agoI'm the author, but I don't follow your comment. Could you elaborate?
- sugarkjube 2y agoGoogle byo yomi
- akkartik 2y agoOhh, you mean a clock for the game Go (wei qi, baduk) Sure thing, that should be doable.
- akkartik 2y agoWhat do you think of this design? -- run within https://akkartik.itch.io/carousel g = love.graphics rect = g.rectangle color = g.setColor floor = math.floor Limit = 13 Byo_yomi_period = 30 -- seconds Curr_color = 'black' Byo_yomi = { black=0, white=0, } Curr_time = 0 function car.update(dt) if Byo_yomi.black == Limit or Byo_yomi.white == Limit then return end Curr_time = Curr_time + dt if Curr_time > Byo_yomi_period then Byo_yomi[Curr_color] = Byo_yomi[Curr_color] + 1 Curr_time = Curr_time - Byo_yomi_period end end -- initialize space per side local side_w = floor((Safe_width-60 - 100)/2) -- initialize font size local function font_size_for_chess_clock() local font_size local min_font_size = 20 local max_font_size = Safe_height for i=1,100 do if min_font_size >= max_font_size-5 then break end font_size = floor((min_font_size+max_font_size)/2) local font = g.newFont(font_size) local w = font:getWidth('00:00:00') if w < side_w then min_font_size = font_size elseif w > side_w then max_font_size = font_size elseif w == side_w then break end end return font_size end local large_font_size = font_size_for_chess_clock() local large_font = g.newFont(large_font_size) local small_font_size = 20 local small_font = g.newFont(small_font_size) function car.draw() local top = Menu_height+20 local x = 30 local height = Safe_height-80 local gutter_width = 100 -- black side color(0.2,0.2,0.2) rect('fill', x, top, side_w, height, 5,5) color(1,1,1) local y if Byo_yomi.black < Limit - 10 then y = top + (height-large_font_size)/2 print_centered(large_font, Byo_yomi.black, y, x, side_w) if Curr_color == 'black' then y = y + large_font_size + 10 print_centered(small_font, floor(Curr_time), y, x, side_w) end elseif Byo_yomi.black < Limit-1 then y = top + (height - large_font_size*2 - 10)/2 local s = ('%d left'):format(Limit - Byo_yomi.black) print_centered(large_font, s, y, x, side_w) if Curr_color == 'black' then y = y + large_font_size + 10 print_centered(large_font, floor(Curr_time), y, x, side_w) end elseif Byo_yomi.black == Limit-1 then y = top + (height - large_font_size - 10 - small_font_size)/2 print_centered(small_font, "no time left", y, x, side_w) if Curr_color == 'black' then y = y + small_font_size + 10 print_centered(large_font, floor(Curr_time), y, x, side_w) end else -- out of time; Byo_yomi.black == Limit -- print nothing end -- white side x = x + side_w + gutter_width color(0,0,0) rect('line', x, top, side_w, height, 5,5) if Byo_yomi.white < Limit-10 then y = top + (height-large_font_size)/2 print_centered(large_font, Byo_yomi.white, y, x, side_w) if Curr_color == 'white' then y = y + large_font_size + 10 print_centered(small_font, floor(Curr_time), y, x, side_w) end elseif Byo_yomi.white < Limit-1 then y = top + (height - large_font_size*2 - 10)/2 local s = ('%d left'):format(Limit - Byo_yomi.white) print_centered(large_font, s, y, x, side_w) if Curr_color == 'white' then y = y + large_font_size + 10 print_centered(large_font, floor(Curr_time), y, x, side_w) end elseif Byo_yomi.white == Limit-1 then y = top + (height - large_font_size - 10 - small_font_size)/2 print_centered(small_font, "no time left", y, x, side_w) if Curr_color == 'white' then y = y + small_font_size + 10 print_centered(large_font, floor(Curr_time), y, x, side_w) end else -- out of time; Byo_yomi.white == Limit -- print nothing end end function print_centered(font, msg, y, left, width) local w = font:getWidth(msg) local x = left + (width-w)/2 g.setFont(font) g.print(msg, x,y) end function car.mouse_press(x,y, b) if Byo_yomi.black == Limit or Byo_yomi.white == Limit then return end if y >= Menu_height + 20 then if Curr_color == 'black' then -- it's black's move if x <= 30+side_w then Curr_color = 'white' Curr_time = 0 end else -- it's white's move if x >= 30 + side_w + 100 then Curr_color = 'black' Curr_time = 0 end end end end I'm going by the description in https://www.britgo.org/bgj/10643.html https://www.britgo.org/bgj/10643.html, but I haven't actually seen a Go clock before, so feedback appreciated.