summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-18 15:59:48 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-18 15:59:48 -0700
commitde975396fe9eccd8f54c798b082c3d690b05c524 (patch)
tree75e2c55fa290bd742ecc5643b26d4af4cc0c6823
parentcbbb37271bdfd5b51824f8b5a3ee5354236beff0 (diff)
downloaddartboat-de975396fe9eccd8f54c798b082c3d690b05c524.tar.gz
dartboat-de975396fe9eccd8f54c798b082c3d690b05c524.tar.xz
web: change winning player message
-rw-r--r--web/web_control.c12
-rw-r--r--web/web_match.c20
-rw-r--r--web/web_match.h2
-rw-r--r--web/web_prompt.c8
4 files changed, 28 insertions, 14 deletions
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");