2 * Copyright (C) 2007 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
18 /*---------------------------------------------------------------------------*/
20 static int score_time_comp(const struct score *S, int i, int j)
22 if (S->timer[i] < S->timer[j])
25 if (S->timer[i] == S->timer[j] && S->coins[i] > S->coins[j])
31 static int score_coin_comp(const struct score *S, int i, int j)
33 if (S->coins[i] > S->coins[j])
36 if (S->coins[i] == S->coins[j] && S->timer[i] < S->timer[j])
42 static void score_swap(struct score *S, int i, int j)
47 strncpy(player, S->player[i], MAXNAM);
48 strncpy(S->player[i], S->player[j], MAXNAM);
49 strncpy(S->player[j], player, MAXNAM);
52 S->timer[i] = S->timer[j];
56 S->coins[i] = S->coins[j];
60 /*---------------------------------------------------------------------------*/
62 void score_init_hs(struct score *s, int timer, int coins)
66 strcpy(s->player[0], "Hard");
67 strcpy(s->player[1], "Medium");
68 strcpy(s->player[2], "Easy");
69 strcpy(s->player[3], "");
71 for (i = 0; i < NSCORE + 1; i++)
78 int score_time_insert(struct score *s, const char *player, int timer, int coins)
82 strncpy(s->player[3], player, MAXNAM);
86 for (i = 2; i >= 0 && score_time_comp(s, i + 1, i); i--)
87 score_swap(s, i + 1, i);
92 int score_coin_insert(struct score *s, const char *player, int timer, int coins)
96 strncpy(s->player[3], player, MAXNAM);
100 for (i = 2; i >= 0 && score_coin_comp(s, i + 1, i); i--)
101 score_swap(s, i + 1, i);
106 /*---------------------------------------------------------------------------*/