diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-21 02:03:13 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-21 02:03:35 -0700 |
commit | 7797f45a97681ca513cb75a7e6a322be3ec5003a (patch) | |
tree | b8b3e4e8a6482064aab345f82469ebcafeba0d9f /web/web_prompt.c | |
parent | dc7c6379f0ef9db382a5445954a4be37e2ec5640 (diff) | |
download | dartboat-7797f45a97681ca513cb75a7e6a322be3ec5003a.tar.gz dartboat-7797f45a97681ca513cb75a7e6a322be3ec5003a.tar.xz |
web: remove hard-coded match modes
Diffstat (limited to 'web/web_prompt.c')
-rw-r--r-- | web/web_prompt.c | 70 |
1 files changed, 33 insertions, 37 deletions
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); |