diff --git a/csts.cmi b/csts.cmi index eb77b58..dc64b35 100644 Binary files a/csts.cmi and b/csts.cmi differ diff --git a/csts.cmx b/csts.cmx index 5d9cdd5..da572c7 100644 Binary files a/csts.cmx and b/csts.cmx differ diff --git a/csts.ml b/csts.ml index 9f3a913..638d836 100644 --- a/csts.ml +++ b/csts.ml @@ -39,7 +39,8 @@ let start_0 = ref 0. ;; let score = ref 0 and combo = ref 0 -and max_combo = ref 0 ;; +and max_combo = ref 0 +and misses = ref 0 ;; let plus_ch = ref 10 and minus_ch = ref 8 diff --git a/csts.o b/csts.o index da981fd..62159ae 100644 Binary files a/csts.o and b/csts.o differ diff --git a/drawing.cmi b/drawing.cmi index 804bc81..e1b9607 100644 Binary files a/drawing.cmi and b/drawing.cmi differ diff --git a/drawing.cmx b/drawing.cmx index 2d26a75..e759dea 100644 Binary files a/drawing.cmx and b/drawing.cmx differ diff --git a/drawing.o b/drawing.o index 4980ad0..7250bf7 100644 Binary files a/drawing.o and b/drawing.o differ diff --git a/dynamic.cmx b/dynamic.cmx index 649777d..54b4b92 100644 Binary files a/dynamic.cmx and b/dynamic.cmx differ diff --git a/dynamic.o b/dynamic.o index 901cfbd..a17f750 100644 Binary files a/dynamic.o and b/dynamic.o differ diff --git a/maeth.cmi b/maeth.cmi index 4c3c423..c83cd6a 100644 Binary files a/maeth.cmi and b/maeth.cmi differ diff --git a/maeth.cmx b/maeth.cmx index d55291e..87fe4bd 100644 Binary files a/maeth.cmx and b/maeth.cmx differ diff --git a/maeth.ml b/maeth.ml index 8ef8a3d..0196a6a 100644 --- a/maeth.ml +++ b/maeth.ml @@ -1,5 +1,6 @@ open Graphics ;; Random.self_init () ;; +exception Reset ;; type operation = Val of int | @@ -74,10 +75,28 @@ let require_bracket = function | Val _ -> false | _ -> true ;; +let int_of_bool = function + | true -> 1 + | false -> 0 ;; + +let fm_length (fm : operation) (size : int) = + let rec aux = function + | Val _ -> size*11/7 + | Exp(f, k) -> size*11/7 (* not implemented*) + | Sum(f, g) + | Diff(f, g) + | Prod(f, g) -> + size*11/7 + (int_of_bool (require_bracket f) + int_of_bool (require_bracket g))*size/2 + aux f + aux g + (* sign + brackets + recursive calls *) + in aux fm ;; + let print_calc (f : operation) (x0 : int) (y0 : int) (size : int) = set_line_width 3 ; + let fmlen = fm_length f size in + let x = ref (x0 - fmlen/2) in + set_color (rgb 192 192 0) ; + fill_rect (x0 - fmlen/2 - 6) (y0 - size - 6) (fmlen+12) (2*size + 12) ; set_color black ; - let x = ref x0 in let rec aux = function | Val k -> Drawing.draw_integer_alignedleft !x y0 k size ~retval:x ; @@ -193,12 +212,12 @@ let maeth_main () = let found = ref false in let equ = generate_random_calc ~plus_w:(!Csts.plus_ch) ~minus_w:(!Csts.minus_ch) ~prod_w:(!Csts.prod_ch) !Csts.calc_length !Csts.n_inf !Csts.n_sup in let resu = calculate equ in - while not !found && (!cur -. start <= !Csts.time_to_ans_f) do + while not !found && (!cur -. start <= !Csts.time_to_ans_f) && (!cur -. !Csts.start_0) <= !Csts.total_time_f do auto_synchronize false ; clear_graph () ; set_color black ; - print_calc equ 10 (Csts.__height__/2) 15 ; + print_calc equ (Csts.__width__/2) (Csts.__height__/2) 15 ; Drawing.draw_string_centered (Csts.__width__/2) (Csts.__height__/3) "Answer" 50 ; Drawing.draw_integer (Csts.__width__/2) (Csts.__height__/3 - 100) !Csts.ans 75 ; @@ -228,13 +247,64 @@ let maeth_main () = cur := Unix.gettimeofday () ; done ; Csts.ans := 0 ; - if !found then begin + if (!cur -. !Csts.start_0) > !Csts.total_time_f then + true + else if !found then begin incr Csts.combo ; Csts.max_combo := max (!Csts.max_combo) !Csts.combo ; - Csts.score := !Csts.score + int_of_float ((float_of_int !Csts.max_score) *. (!Csts.time_to_ans_f -. (!cur -. start)) /. !Csts.time_to_ans_f) ; + Csts.score := !Csts.score + int_of_float ( + (float_of_int !Csts.max_score) + *. (!Csts.time_to_ans_f -. (!cur -. start) /. 2.) /. !Csts.time_to_ans_f + *. (1. +. Float.sqrt (float_of_int !Csts.combo)) + ) ; + (* give 50% of max pts for correct answer + up to 50% more for speed *) true end else begin Csts.combo := 0 ; + incr Csts.misses ; false - end ;; \ No newline at end of file + end ;; + +let result_screen () = + try + while true do + auto_synchronize false ; + clear_graph () ; + + set_color black ; + Drawing.draw_string_centered (Csts.__width__/2) (Csts.__height__ - 60) "Press space to return to main" 22 ; + + set_color (rgb 192 192 0) ; + Drawing.draw_string (Csts.__width__/6) (Csts.__height__/2 + 70) "Score" 20 ; + set_color (rgb 255 255 0) ; + Drawing.draw_integer_alignedleft (Csts.__width__/6+20*(5+1)*10/7) (Csts.__height__/2 + 70) !Csts.score 20 ; + + set_color (rgb 0 192 0) ; + Drawing.draw_string (Csts.__width__/6) (Csts.__height__/2) "Max Combo" 20 ; + set_color (rgb 0 255 0) ; + Drawing.draw_integer_alignedleft (Csts.__width__/6+20*(9+1)*10/7) (Csts.__height__/2) !Csts.max_combo 20 ; + + set_color (rgb 0 192 32) ; + Drawing.draw_string (Csts.__width__/6) (Csts.__height__/2 - 70) "Combo" 20 ; + set_color (rgb 0 255 32) ; + Drawing.draw_integer_alignedleft (Csts.__width__/6+20*(5+1)*10/7) (Csts.__height__/2 - 70) !Csts.combo 20 ; + + set_color (rgb 192 0 0) ; + Drawing.draw_string (Csts.__width__/6) (Csts.__height__/2 - 140) "Misses" 20 ; + set_color (rgb 255 0 0) ; + Drawing.draw_integer_alignedleft (Csts.__width__/6+20*(6+1)*10/7) (Csts.__height__/2 - 140) !Csts.misses 20 ; + + if !Csts.misses = 0 then begin + set_color (rgb 0 255 0) ; + Drawing.draw_string_centered (Csts.__width__/2) (40) "FC" 35 + end ; + + auto_synchronize true ; + Unix.sleepf Csts.sleep_d ; + if key_pressed () && (read_key ()) == ' ' then + raise Reset + done; + () + with + | Reset -> () ;; \ No newline at end of file diff --git a/maeth.o b/maeth.o index 31b8f9f..753f254 100644 Binary files a/maeth.o and b/maeth.o differ diff --git a/main.cmi b/main.cmi index 7d1a064..6f7af75 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmx b/main.cmx index 406c9f4..684831e 100644 Binary files a/main.cmx and b/main.cmx differ diff --git a/main.ml b/main.ml index 2d1036f..89015cc 100644 --- a/main.ml +++ b/main.ml @@ -1,7 +1,7 @@ open Graphics ;; Random.self_init () ;; -let mainloop () = +let rec mainloop () = open_graph Csts.open_string ; set_window_title "Maeth"; try @@ -26,9 +26,11 @@ let mainloop () = * (90 / !Csts.time_to_ans) * int_of_float (Float.sqrt (float_of_int (90 / !Csts.time_to_ans))) ; Maeth.init_odds () ; clear_graph () ; - while true do + while Unix.gettimeofday () -. !Csts.start_0 <= !Csts.total_time_f do ignore (Maeth.maeth_main ()) ; - done ;; + done ; + Maeth.result_screen () ; + mainloop () ;; (* let difficulty = ref 1 ;; diff --git a/main.o b/main.o index 7e9d3a1..6a84e68 100644 Binary files a/main.o and b/main.o differ diff --git a/math b/math index f295913..66ec3bd 100755 Binary files a/math and b/math differ diff --git a/math.cmx b/math.cmx index 1459ffb..b3e722d 100644 Binary files a/math.cmx and b/math.cmx differ diff --git a/math.o b/math.o index 5e44d3d..37803bb 100644 Binary files a/math.o and b/math.o differ diff --git a/menus.cmi b/menus.cmi index 4376146..ad11228 100644 Binary files a/menus.cmi and b/menus.cmi differ diff --git a/menus.cmx b/menus.cmx index 11f1c5a..a561a80 100644 Binary files a/menus.cmx and b/menus.cmx differ diff --git a/menus.ml b/menus.ml index 3e985ac..916ae9c 100644 --- a/menus.ml +++ b/menus.ml @@ -362,8 +362,9 @@ let action_on_interface () = (* --------------------------------------------------------------------------------------------------------------------------------------------- *) (* Define the menu there *) -build_empty_interface "Main Menu" 128 128 128 ;; -build_empty_interface "Options " 32 32 32 ;; +build_empty_interface "Main Menu" 128 128 128 ;; +build_empty_interface "Options" 32 32 32 ;; +build_empty_interface "End screen" 32 32 200 ;; 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) ;; @@ -377,6 +378,9 @@ build_button "Total time" {x = Csts.__width__/2 - 200; y = 270; w = 400; h = 10 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) ;; +build_button "Exit" {x = Csts.__width__/2 - 150; y = 50; w = 300; h = 100} 1 1 1 (Warp (-1)) ;; +build_button "Main Menu" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 128 128 128 (Warp 0) ;; + (*Printf.printf "(B : %d ; I : %d)\n" arr_buttons.len arr_interfaces.len ;;*) add_button_to_interface 0 0 ; add_button_to_interface 0 1 ; @@ -387,4 +391,6 @@ add_button_to_interface 1 5 ; add_button_to_interface 1 6 ; add_button_to_interface 1 7 ; add_button_to_interface 1 8 ; -add_button_to_interface 1 9 ; \ No newline at end of file +add_button_to_interface 1 9 ; +add_button_to_interface 2 10 ; +add_button_to_interface 2 11 ; \ No newline at end of file diff --git a/menus.o b/menus.o index c13eb5e..d1c6423 100644 Binary files a/menus.o and b/menus.o differ