From 7797f45a97681ca513cb75a7e6a322be3ec5003a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 21 May 2022 02:03:13 -0700 Subject: web: remove hard-coded match modes --- web/web_prompt.c | 70 ++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'web/web_prompt.c') diff --git a/web/web_prompt.c b/web/web_prompt.c index 1e2e1a1..dc21d62 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -163,9 +163,7 @@ void menu_display_match_opts() sprintf(buf, "Starting points: %d", match_opts->start_pts); add_list_opt(buf); sprintf(buf, "Throws first: %s", - match_opts->throws_first == 1 ? - match_opts->p1_name : - match_opts->p2_name); + match_opts->players[match_opts->throws_first - 1].name); add_list_opt(buf); list_back = true; @@ -187,9 +185,8 @@ void menu_display_throws_first() { prompt_set_msgl("Throws first:"); - add_list_opt(match_opts->p1_name); - if (match_opts->p2_name) - add_list_opt(match_opts->p2_name); + for (int i = 0; i < match_opts->num_players; ++i) + add_list_opt(match_opts->players[i].name); list_back = true; } @@ -237,41 +234,40 @@ static void menu_push(enum menu m) menu_display(); } -void menu_submit_main(int mode) +void menu_submit_main(int val) { - if (mode < M_FIRST || mode > M_LAST) { - oi(); - return; - } - - if (match_opts) match_opts_free(); - match_opts = calloc(1, sizeof(*match_opts)); - match_opts->mode = mode; + match_opts_new(); match_opts->start_pts = 501; match_opts->throws_first = 1; + // names need to be freed if we stop using string literals - if (mode == M_PVC) { - match_opts->p1_name = "User"; - match_opts->p2_name = "Computer"; - match_opts->p2_type = PT_COMP; - } else if (mode == M_P) { - match_opts->p1_name = "Player 1"; - match_opts->p2_name = NULL; - } else if (mode == M_PVP) { - match_opts->p1_name = "Player 1"; - match_opts->p2_name = "Player 2"; - } else if (mode == M_CVC) { - match_opts->p1_name = "Computer 1"; - match_opts->p1_type = PT_COMP; - match_opts->p2_name = "Computer 2"; - match_opts->p2_type = PT_COMP; - } else if (mode == M_PVPVP) { - match_opts->p1_name = "Player 1"; - match_opts->p2_name = "Player 2"; - } else if (mode == M_PVCVCVC) { - match_opts->p1_name = "User"; - match_opts->p2_type = PT_COMP; - match_opts->p2_name = "Computer 1"; + switch(val) { + case 1: + match_opts_add_player(PT_USER, "User"); + match_opts_add_player(PT_COMP, "Computer"); + break; + case 2: + match_opts_add_player(PT_USER, "Player 1"); + break; + case 3: + match_opts_add_player(PT_USER, "Player 1"); + match_opts_add_player(PT_USER, "Player 2"); + break; + case 4: + match_opts_add_player(PT_COMP, "Computer 1"); + match_opts_add_player(PT_COMP, "Computer 2"); + break; + case 5: + match_opts_add_player(PT_USER, "Player 1"); + match_opts_add_player(PT_USER, "Player 2"); + match_opts_add_player(PT_USER, "Player 3"); + break; + case 6: + match_opts_add_player(PT_USER, "Player 1"); + match_opts_add_player(PT_COMP, "Computer 1"); + match_opts_add_player(PT_COMP, "Computer 2"); + match_opts_add_player(PT_COMP, "Computer 3"); + break; } menu_push(MENU_MATCH_OPTS); -- cgit v1.2.3-70-g09d2