added end screen + score v1.1
This commit is contained in:
parent
a9a449bb32
commit
6311c15d25
3
csts.ml
3
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
|
||||
|
|
BIN
drawing.cmi
BIN
drawing.cmi
Binary file not shown.
BIN
drawing.cmx
BIN
drawing.cmx
Binary file not shown.
BIN
dynamic.cmx
BIN
dynamic.cmx
Binary file not shown.
82
maeth.ml
82
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 ;;
|
||||
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 -> () ;;
|
8
main.ml
8
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 ;;
|
||||
|
|
12
menus.ml
12
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 ;
|
||||
add_button_to_interface 1 9 ;
|
||||
add_button_to_interface 2 10 ;
|
||||
add_button_to_interface 2 11 ;
|
Loading…
Reference in New Issue