home *** CD-ROM | disk | FTP | other *** search
- /*
- * ScoreBoard.c - ScoreBoard operations
- */
-
- # include "TransSkel.h"
-
- # include "Concentration.h"
-
-
- /*
- * Calculate rectangle for player slot. Slot -1 is for the title.
- */
-
- static void
- ScoreBoardPlayerRect (short i, Rect *rp)
- {
- SetRect (rp, 0, 0, sbWidth, sbSlotHeight - 10);
- OffsetRect (rp, sbHOffset, sbVOffset + (i + 1) * sbSlotHeight);
- }
-
-
- /*
- * Calculate rectangle for player name.
- */
-
- static void
- ScoreBoardPlayerNameRect (short i, Rect *rp)
- {
- SetRect (rp, 0, 0, sbNameWidth, sbSlotHeight - 10);
- OffsetRect (rp, sbHOffset, sbVOffset + (i + 1) * sbSlotHeight);
- }
-
-
- /*
- * Calculate rectangle for player score.
- */
-
- static void
- ScoreBoardPlayerScoreRect (short i, Rect *rp)
- {
- SetRect (rp, 0, 0, sbScoreWidth, sbSlotHeight - 10);
- OffsetRect (rp, sbHOffset + sbNameWidth, sbVOffset + (i + 1) * sbSlotHeight);
- }
-
-
- /*
- * Draw player info (player number and name). If n is current player,
- * draw a frame around name and score.
- *
- * If n >= nPlayers, erase the scoreboard slot. This allows scoreboard
- * redrawing easily, when the number of players is reduced in the Players
- * dialog.
- */
-
- void
- DrawPlayerInfo (short n)
- {
- Str255 s;
- Rect r;
- short i;
-
- if (n >= sb->nPlayers)
- {
- ScoreBoardPlayerRect (n, &r);
- EraseRect (&r);
- return;
- }
- ScoreBoardPlayerNameRect (n, &r);
- TextBox (sb->name[n] + 1, (long) sb->name[n][0], &r, teJustLeft);
- NumToString ((long) sb->score[n], s);
- ScoreBoardPlayerScoreRect (n, &r);
- TextBox (s + 1, (long) s[0], &r, teJustRight);
- ScoreBoardPlayerRect (n, &r);
- if (n != sb->player)
- PenMode (patBic);
- InsetRect (&r, -1, -1);
- FrameRect (&r);
- InsetRect (&r, -2, -2);
- FrameRect (&r);
- PenNormal ();
- }
-
-
- void
- DrawScoreBoard (void)
- {
- StringPtr str = "\pScoreboard";
- Rect r, r2;
- short i;
-
- ScoreBoardPlayerRect (-1, &r);
- ScoreBoardPlayerRect (maxPlayers - 1, &r2);
- r2.top = r.top;
- InsetRect (&r2, -8, -8);
- FrameRect (&r2);
- InsetRect (&r2, 2, 2);
- PenSize (2, 2);
- FrameRect (&r2);
- PenNormal ();
-
- TextBox (str + 1, (long) str[0], &r, teJustCenter);
-
- for (i = 0; i < maxPlayers; i++)
- DrawPlayerInfo (i);
- }
-
-
- void
- FlashPlayerFrame (short n)
- {
- Rect r;
- short i;
-
- ScoreBoardPlayerRect (n, &r);
- InsetRect (&r, -1, -1);
- for (i = 0; i < 2; i++)
- {
- SkelPause (8L);
- PenMode (patBic);
- FrameRect (&r);
- InsetRect (&r, -2, -2);
- FrameRect (&r);
- SkelPause (8L);
- PenMode (patCopy);
- FrameRect (&r);
- InsetRect (&r, 2, 2);
- FrameRect (&r);
- }
- PenNormal ();
- }
-
-
- /*
- * Initialize player scores to zero and select first player. The first
- * player rotates to the next player after the previous first player
- * unless no moves had been made in the previous game.
- */
-
- void
- ResetScoreBoard (Boolean advanceFirstPlayer)
- {
- short i;
-
- for (i = 0; i < sb->nPlayers; ++i)
- sb->score[i] = 0;
-
- if (advanceFirstPlayer)
- {
- if (++sb->firstPlayer >= sb->nPlayers)
- sb->firstPlayer = 0;
- }
- sb->player = sb->firstPlayer;
- }
-
-
- /*
- * Call this when the game is over. It determines which player has the highest
- * score (if not a tie), and makes that the current player in order to frame the
- * score.
- */
-
- /* THIS FUNCTION IS NOT ACTUALLY USED */
-
- void
- HiliteWinner (void)
- {
- short i, n, highScore, highScorePlayer;
-
- n = sb->player;
- sb->player = -1;
- DrawPlayerInfo (n); /* erase frame around current player */
- /*
- * determine high score
- */
- highScore = 0;
- for (i = 0; i < sb->nPlayers; i++)
- {
- if (highScore < sb->score[i])
- highScore = sb->score[i];
- }
- /*
- * determine how many players have the high score and the last
- * player having that score.
- */
- n = 0;
- for (i = 0; i < sb->nPlayers; i++)
- {
- if (sb->score[i] == highScore)
- {
- ++n;
- highScorePlayer = i;
- }
- }
- if (n == 1) /* frame player if only one with high score */
- {
- sb->player = highScorePlayer;
- DrawPlayerInfo (sb->player);
- FlashPlayerFrame (sb->player);
- }
- }