From de975396fe9eccd8f54c798b082c3d690b05c524 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 18 May 2022 15:59:48 -0700 Subject: web: change winning player message --- web/web_control.c | 12 ++---------- web/web_match.c | 20 +++++++++++++++++++- web/web_match.h | 2 ++ web/web_prompt.c | 8 +++++--- 4 files changed, 28 insertions(+), 14 deletions(-) (limited to 'web') diff --git a/web/web_control.c b/web/web_control.c index 310bbcf..af5723a 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -185,21 +185,13 @@ void user_visit_to_rem(int rem) user_visit(state->legs[0]->rem - rem); } -static int num_players() -{ - if (state->mode == M_P) - return 1; - - return 2; -} - static int prev_throw_player() { if (match_is_over()) return state->active_player; if (state->active_player == 1) - return num_players(); + return match_num_players(); else return state->active_player - 1; } @@ -229,7 +221,7 @@ static void undo_active() } static bool first_user_has_thrown() { - for (int i = 0, np = num_players(); i < np; ++i) { + for (int i = 0, np = match_num_players(); i < np; ++i) { int pn = match_opts->throws_first + i; if (pn > np) pn -= np; diff --git a/web/web_match.c b/web/web_match.c index b399b85..432808d 100644 --- a/web/web_match.c +++ b/web/web_match.c @@ -24,9 +24,27 @@ void match_opts_free() match_opts = NULL; } +int match_num_players() +{ + if (state->mode == M_P) + return 1; + + return 2; +} + +int match_winning_player() +{ + for (int i = 0; i < match_num_players(); ++i) { + if (state->legs[i]->rem == 0) + return i + 1; + } + + return -1; +} + bool match_is_over() { - return state->legs[0]->rem <= 0 || state->legs[1]->rem <= 0; + return match_winning_player() != -1; } struct leg *state_active_leg() diff --git a/web/web_match.h b/web/web_match.h index 85fcdbf..8f106fb 100644 --- a/web/web_match.h +++ b/web/web_match.h @@ -32,6 +32,8 @@ extern struct match_opts *match_opts; void free_state(); void match_opts_free(); +int match_num_players(); +int match_winning_player(); bool match_is_over(); struct leg *state_active_leg(); diff --git a/web/web_prompt.c b/web/web_prompt.c index f3b523e..8e2bd74 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -168,10 +168,12 @@ void prompt_end_match() { scoreboard_set_player_active(-1); + char buf[64]; + sprintf(buf, "%s wins.", + state->legs[match_winning_player() - 1]->name); + set_prompt_mode(PM_END_MATCH); - prompt_set_msgl( - state->mode == M_PVC && state->legs[1]->rem <= 0 ? - "Computer wins. :(" : "You win! :)"); + prompt_set_msgl(buf); prompt_set_msgr(NULL); dom_set_content("#key-submit", "END MATCH"); -- cgit v1.2.3-70-g09d2