diff --git a/csts.cmi b/csts.cmi index 8af9521..81ee728 100644 Binary files a/csts.cmi and b/csts.cmi differ diff --git a/csts.cmx b/csts.cmx index cae2103..c8386c8 100644 Binary files a/csts.cmx and b/csts.cmx differ diff --git a/csts.ml b/csts.ml index 7a53619..2e15574 100644 --- a/csts.ml +++ b/csts.ml @@ -28,6 +28,10 @@ let sleep_d = 0.01 ;; let difficulty = ref 1 ;; let calc_length = ref 3 ;; let time_to_ans = ref 10 ;; +let n_inf = ref 1 ;; +let n_sup = ref 10 ;; + +let time_to_ans_f = ref 10.0 ;; let score = ref 0 and combo = ref 0 diff --git a/csts.o b/csts.o index 1eafff9..4a2e8a0 100644 Binary files a/csts.o and b/csts.o differ diff --git a/drawing.cmi b/drawing.cmi index bb2d2ae..686d574 100644 Binary files a/drawing.cmi and b/drawing.cmi differ diff --git a/drawing.cmx b/drawing.cmx index 9a0c149..27b633c 100644 Binary files a/drawing.cmx and b/drawing.cmx differ diff --git a/drawing.ml b/drawing.ml index cdf2851..5b90251 100644 --- a/drawing.ml +++ b/drawing.ml @@ -76,6 +76,48 @@ let draw_integer_alignedleft ?retval:(rv=fodder) x0 y n0 len = done ; rv := (x0 + (size+1)*(len*11/7)) ;; +let draw_integer_alignedright ?retval:(rv=fodder) x0 y n0 len = + (* 7-seg display 2 *) + set_line_width (max 1 (len/4)); + let n = ref n0 in + let size = Math.ln_b 10 n0 in + + let cur_x = ref (x0 - len*11/7) in + + if !n < 0 then begin + n := !n * (-1); + draw_poly_line [|(x0, y); (x0-(size+1)*len, y)|]; + cur_x := !cur_x + (len*11/7) + end; + + for i = 0 to size do + let x = !cur_x in + if Array.mem (!n mod 10) [|0; 4; 5; 6; 7; 8; 9|] then + draw_poly_line [|(x + !(Csts.camx), y+len + !(Csts.camy)); (x + !(Csts.camx), y + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|0; 2; 3; 5; 6; 7; 8; 9|] then + draw_poly_line [|(x + !(Csts.camx), y+len + !(Csts.camy)); (x+len + !(Csts.camx), y+len + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|0; 1; 2; 3; 4; 7; 8; 9|] then + draw_poly_line [|(x+len + !(Csts.camx), y+len + !(Csts.camy)); (x+len + !(Csts.camx), y + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|2; 3; 4; 5; 6; 8; 9|] then + draw_poly_line [|(x + !(Csts.camx), y + !(Csts.camy)); (x+len + !(Csts.camx), y + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|0; 1; 3; 4; 5; 6; 7; 8; 9|] then + draw_poly_line [|(x+len + !(Csts.camx), y-len + !(Csts.camy)); (x+len + !(Csts.camx), y + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|0; 2; 3; 5; 6; 8; 9|] then + draw_poly_line [|(x + !(Csts.camx), y-len + !(Csts.camy)); (x+len + !(Csts.camx), y-len + !(Csts.camy))|]; + + if Array.mem (!n mod 10) [|0; 2; 6; 8|] then + draw_poly_line [|(x + !(Csts.camx), y-len + !(Csts.camy)); (x + !(Csts.camx), y + !(Csts.camy))|]; + + n := !n/10; + cur_x := !cur_x - (len*11/7); + done ; + rv := (x0 + (len*11/7)) ;; + let decode_letter x y len arr = set_line_width 3; if arr.(0) = 1 then diff --git a/drawing.o b/drawing.o index 5e5219c..d973d3b 100644 Binary files a/drawing.o and b/drawing.o differ diff --git a/dynamic.cmx b/dynamic.cmx index 70495ec..9e5b0d8 100644 Binary files a/dynamic.cmx and b/dynamic.cmx differ diff --git a/dynamic.o b/dynamic.o index 7a3f91d..0bf5156 100644 Binary files a/dynamic.o and b/dynamic.o differ diff --git a/maeth.cmi b/maeth.cmi index a4c9a50..36384f4 100644 Binary files a/maeth.cmi and b/maeth.cmi differ diff --git a/maeth.cmx b/maeth.cmx index 1476a5f..7bcbcaa 100644 Binary files a/maeth.cmx and b/maeth.cmx differ diff --git a/maeth.ml b/maeth.ml index 7d159c5..b3d511f 100644 --- a/maeth.ml +++ b/maeth.ml @@ -117,4 +117,19 @@ let print_calc (f : operation) (x0 : int) (y0 : int) (size : int) = aux g ; if require_bracket g then draw_bracket_close !x y0 size ~retval:x ; in - aux f ;; \ No newline at end of file + aux f ;; + +let maeth_main () = + let start = Unix.gettimeofday () in + let found = ref false in + while not !found && (Unix.gettimeofday() -. start <= !Csts.time_to_ans_f) do + () + done ; + if !found then begin + incr Csts.combo ; + true + end + else begin + Csts.combo := 0 ; + false + end ;; \ No newline at end of file diff --git a/maeth.o b/maeth.o index 2b2da2f..fc5c70c 100644 Binary files a/maeth.o and b/maeth.o differ diff --git a/main.cmi b/main.cmi index 7eb4cdc..744e235 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmx b/main.cmx index dc512ff..1cc2ecd 100644 Binary files a/main.cmx and b/main.cmx differ diff --git a/main.ml b/main.ml index 9d1006f..87a7d00 100644 --- a/main.ml +++ b/main.ml @@ -16,6 +16,7 @@ let mainloop () = () with | Menus.MenuStart -> + Csts.time_to_ans_f := float_of_int (!Csts.time_to_ans) ; clear_graph () ; Maeth.print_calc (Maeth.generate_random_calc 8 1 20) (10) (Csts.__height__/2) 20 ; while true do diff --git a/main.o b/main.o index 0d688fc..46ad304 100644 Binary files a/main.o and b/main.o differ diff --git a/math b/math index b2ac13c..2e9b48d 100755 Binary files a/math and b/math differ diff --git a/math.cmx b/math.cmx index 210928b..739422b 100644 Binary files a/math.cmx and b/math.cmx differ diff --git a/math.o b/math.o index b25fa5e..8fa32ed 100644 Binary files a/math.o and b/math.o differ diff --git a/menus.cmi b/menus.cmi index 6f9a376..5218deb 100644 Binary files a/menus.cmi and b/menus.cmi differ diff --git a/menus.cmx b/menus.cmx index 22d9be9..adbefec 100644 Binary files a/menus.cmx and b/menus.cmx differ diff --git a/menus.ml b/menus.ml index 0acd1c2..822483d 100644 --- a/menus.ml +++ b/menus.ml @@ -10,6 +10,8 @@ type 'a value_changer = { min : 'a ; max : 'a ; pad : 'a ; + min_update : ('a ref) list ; (* after this value changes, these values will be set to min(their_value, this_value-1) *) + max_update : ('a ref) list ; (* after this value changes, these values will be set to max(their_value, this_value+1) *) } ;; type action = Nothing | Tweak of int value_changer | Warp of int @@ -120,11 +122,13 @@ let build_interface (title : string) (red : int) (green : int) (blue : int) (but Dynamic.dyn_add arr_interfaces res ; incr current_interface_index ;; -let build_tweak (ptr : int ref) (m : int) (mx : int) (st : int) = { +let build_tweak (ptr : int ref) (m : int) (mx : int) (st : int) (mi : (int ref) list) (sp : (int ref) list) = { ptr = ptr ; min = m; max = mx ; pad = st ; + min_update = mi ; + max_update = sp ; } ;; (* --------------------------------------------------------------------------------------------------------------------------------------------- *) @@ -162,7 +166,11 @@ let print_button (b : button) = fill_rect b.pos.x b.pos.y b.pos.w b.pos.h ; draw_closest b.red b.green b.blue ; set_line_width 2 ; - Drawing.draw_string (b.pos.x+3) (b.pos.y + b.pos.h/2) b.text (min (3*b.pos.h/4-2) ((7*(b.pos.w*3/4-4)/(max 1 (String.length b.text)))/10)) ;; + Drawing.draw_string (b.pos.x+3) (b.pos.y + b.pos.h/2) b.text (min (3*b.pos.h/4-2) ((7*((b.pos.w*3)/4-50)/(max 1 (String.length b.text)))/10)) ; + match b.actn with + | Tweak v -> + Drawing.draw_integer_alignedright (b.pos.x + b.pos.w) (b.pos.y + b.pos.h/2) !(v.ptr) 15 + | _ -> () ;; let print_interface (it : interface) = List.iter print_button it.bts ; @@ -176,7 +184,7 @@ let print_current_interface () = Drawing.draw_string 20 (Csts.__height__ - 40) interf.title 30 ;; (* --------------------------------------------------------------------------------------------------------------------------------------------- *) -(* actions *) +(* actions 1/2 *) let get1char () = if key_pressed () then @@ -184,13 +192,116 @@ let get1char () = else '@' ;; +let change_other (reference : int) (mins : (int ref) list) (maxs : (int ref) list) = + let rec aux = function + | ([], []) -> + () + | (hmin::tmin, []) -> + hmin := min (!hmin) (reference -1) ; + aux (tmin, []) + | ([], hmax::tmax) -> + hmax := max (!hmax) (reference +1) ; + aux ([], tmax) + | (hmin::tmin, hmax::tmax) -> + hmin := min (!hmin) (reference -1) ; + hmax := max (!hmax) (reference +1) ; + aux (tmin, tmax) + in aux (mins, maxs) ;; + +let offset_pm = 40 ;; +let size_pm = (Csts.__width__ - 2*offset_pm) /11 ;; + +let draw_rect_pm (x : int) (y : int) (w: int) (h : int) (red : int) (green : int) (blue : int) = + let (mx, my) = mouse_pos () in + if is_within {x = x; y = y; w = w; h = h} mx my then begin + set_color (rgb 0 255 0) ; + fill_rect x y w h ; + set_color (rgb red green blue) ; + fill_rect (x+6) (y+6) (w-12) (h-12) + end + else begin + set_color (rgb red green blue) ; + fill_rect x y w h + end ;; + +let draw_incrdecr () = + draw_rect_pm (offset_pm) (offset_pm) size_pm size_pm 255 0 0; + draw_rect_pm (Csts.__width__/11 + offset_pm) (offset_pm) size_pm size_pm 255 0 0; + draw_rect_pm (2*Csts.__width__/11 + offset_pm) (offset_pm) size_pm size_pm 255 0 0; + draw_rect_pm (3*Csts.__width__/11 + offset_pm) (offset_pm) size_pm size_pm 255 0 0; + draw_rect_pm (4*Csts.__width__/11 + offset_pm) (offset_pm) size_pm size_pm 255 0 0; + draw_rect_pm (10*Csts.__width__/11 - offset_pm) (offset_pm) size_pm size_pm 0 0 255; + draw_rect_pm (9*Csts.__width__/11 - offset_pm) (offset_pm) size_pm size_pm 0 0 255; + draw_rect_pm (8*Csts.__width__/11 - offset_pm) (offset_pm) size_pm size_pm 0 0 255; + draw_rect_pm (7*Csts.__width__/11 - offset_pm) (offset_pm) size_pm size_pm 0 0 255; + draw_rect_pm (6*Csts.__width__/11 - offset_pm) (offset_pm) size_pm size_pm 0 0 255;; + +let draw_digits_incrdecr () = + set_color white ; + Drawing.draw_string_centered (offset_pm + size_pm/2) (offset_pm + size_pm/2) "min" (size_pm/6) ; + Drawing.draw_integer (offset_pm + Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 1 (size_pm/3) ; + Drawing.draw_integer (offset_pm + 2*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 10 (size_pm/3) ; + Drawing.draw_integer (offset_pm + 3*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 100 (size_pm/3) ; + Drawing.draw_integer (offset_pm + 4*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 500 (size_pm/3) ; + + Drawing.draw_string_centered (-offset_pm + 10*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) "max" (size_pm/6) ; + Drawing.draw_integer (-offset_pm + 9*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 1 (size_pm/3) ; + Drawing.draw_integer (-offset_pm + 8*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 10 (size_pm/3) ; + Drawing.draw_integer (-offset_pm + 7*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 100 (size_pm/3) ; + Drawing.draw_integer (-offset_pm + 6*Csts.__width__/11 + size_pm/2) (offset_pm + size_pm/2) 500 (size_pm/3) ;; + +(* --------------------------------------------------------------------------------------------------------------------------------------------- *) +(* actions 2/2 *) + +let stall_pm = ref false ;; +let use_incrdecr (val_ptr : int value_changer) = + if button_down () then begin + if !stall_pm then + () + else begin + stall_pm := true ; + let (mox, moy) = mouse_pos () in + if moy >= offset_pm && moy <= offset_pm + size_pm then begin + match mox with + | x when x >= offset_pm && x <= offset_pm + size_pm -> + val_ptr.ptr := val_ptr.min + | x when x >= offset_pm + Csts.__width__/11 && x <= offset_pm + Csts.__width__/11 + size_pm -> + val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - 1) + | x when x >= offset_pm + 2*Csts.__width__/11 && x <= offset_pm + 2*Csts.__width__/11 + size_pm -> + val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - 10) + | x when x >= offset_pm + 3*Csts.__width__/11 && x <= offset_pm + 3*Csts.__width__/11 + size_pm -> + val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - 100) + | x when x >= offset_pm + 4*Csts.__width__/11 && x <= offset_pm + 4*Csts.__width__/11 + size_pm -> + val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - 500) + + | x when x >= 6*Csts.__width__/11 - offset_pm && x <= 6*Csts.__width__/11 - offset_pm + size_pm -> + val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + 500) + | x when x >= 7*Csts.__width__/11 - offset_pm && x <= 7*Csts.__width__/11 - offset_pm + size_pm -> + val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + 100) + | x when x >= 8*Csts.__width__/11 - offset_pm && x <= 8*Csts.__width__/11 - offset_pm + size_pm -> + val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + 10) + | x when x >= 9*Csts.__width__/11 - offset_pm && x <= 9*Csts.__width__/11 - offset_pm + size_pm -> + val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + 1) + | x when x >= 10*Csts.__width__/11 - offset_pm && x <= 10*Csts.__width__/11 - offset_pm + size_pm -> + val_ptr.ptr := val_ptr.max + | _ -> () + end + end + end + else + stall_pm := false ;; + let move_interface (b : button) = match b.actn with | Nothing -> () | Tweak val_ptr -> begin let halted = ref false in + set_color black ; + Drawing.draw_string_centered (Csts.__width__/2) (Csts.__height__ - 50) "press space to confirm" 15 ; set_line_width 3 ; while not !halted do auto_synchronize false ; + draw_incrdecr () ; + draw_digits_incrdecr () ; set_color black ; fill_rect (3*Csts.__width__/10) (3*Csts.__height__/10) (2*Csts.__width__/5) (2*Csts.__height__/5) ; set_color white ; @@ -201,13 +312,15 @@ let move_interface (b : button) = match b.actn with Drawing.draw_string (7*Csts.__width__/10-5-3*20*10/7) (11*Csts.__height__/20) "Max" 20 ; Drawing.draw_integer_alignedleft (7*Csts.__width__/10-5-3*20*10/7) (Csts.__height__/2) val_ptr.max 18 ; auto_synchronize true ; + use_incrdecr val_ptr ; Unix.sleepf Csts.sleep_d ; match get1char () with | '+' -> val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + val_ptr.pad) | '-' -> val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - val_ptr.pad) | '\n' | ' ' -> halted := true | _ -> () - done + done ; + change_other !(val_ptr.ptr) val_ptr.min_update val_ptr.max_update end | Warp ne -> if ne = -1 then @@ -255,10 +368,13 @@ build_empty_interface "Options " 32 32 32 ;; build_button "Start" {x = Csts.__width__/2 - 150; y = 270; w = 300; h = 100} 32 255 32 (Warp (-2)) ;; build_button "Options" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 255 32 255 (Warp 1) ;; build_button "Exit" {x = Csts.__width__/2 - 150; y = 50; w = 300; h = 100} 1 1 1 (Warp (-1)) ;; -build_button "Length" {x = Csts.__width__/2 - 150; y = 380; w = 300; h = 100} 255 32 32 (Tweak (build_tweak Csts.calc_length 2 20 1)) ;; -build_button "Time" {x = Csts.__width__/2 - 150; y = 270; w = 300; h = 100} 32 255 32 (Tweak (build_tweak Csts.time_to_ans 3 30 1)) ;; -build_button "Difficulty" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 32 32 255 (Tweak (build_tweak Csts.difficulty 1 10 1)) ;; -build_button "Back" {x = Csts.__width__/2 - 150; y = 50; w = 300; h = 100} 32 32 32 (Warp 0) ;; + +build_button "Minimum" {x = Csts.__width__/2 - 200; y = 600; w = 400; h = 100} 255 128 32 (Tweak (build_tweak Csts.n_inf 1 1000 1 [] [Csts.n_sup])) ;; +build_button "Maximum" {x = Csts.__width__/2 - 200; y = 490; w = 400; h = 100} 128 255 32 (Tweak (build_tweak Csts.n_sup 1 1000 1 [Csts.n_inf] [])) ;; +build_button "Length" {x = Csts.__width__/2 - 200; y = 380; w = 400; h = 100} 255 32 32 (Tweak (build_tweak Csts.calc_length 2 20 1 [] [])) ;; +build_button "Time" {x = Csts.__width__/2 - 200; y = 270; w = 400; h = 100} 32 255 32 (Tweak (build_tweak Csts.time_to_ans 3 30 1 [] [])) ;; +build_button "Difficulty" {x = Csts.__width__/2 - 200; y = 160; w = 400; h = 100} 32 32 255 (Tweak (build_tweak Csts.difficulty 1 10 1 [] [])) ;; +build_button "Back" {x = Csts.__width__/2 - 200; y = 50; w = 400; h = 100} 32 32 32 (Warp 0) ;; (*Printf.printf "(B : %d ; I : %d)\n" arr_buttons.len arr_interfaces.len ;;*) add_button_to_interface 0 0 ; @@ -267,4 +383,6 @@ add_button_to_interface 0 2 ; add_button_to_interface 1 3 ; add_button_to_interface 1 4 ; add_button_to_interface 1 5 ; -add_button_to_interface 1 6 ; \ No newline at end of file +add_button_to_interface 1 6 ; +add_button_to_interface 1 7 ; +add_button_to_interface 1 8 ; \ No newline at end of file diff --git a/menus.o b/menus.o index 9943652..1973d72 100644 Binary files a/menus.o and b/menus.o differ