Exemplo n.º 1
0
Arquivo: yahtzee.c Projeto: GNOME/tali
int
FindWinner (void)
{
  int i;
  int winner = 0;
  int total;

  WinningScore = 0;
  FreeUndoRedoLists ();

  for (i = 0; i < NumberOfPlayers; ++i) {
    total = total_score (i);
    if (total > WinningScore) {
      WinningScore = total_score (i);
      winner = i;
    }
  }

  /* Detect a drawn game. Returning the negative of the score 
   * is a bit of a hack, but it allows us to find out who the winners
   * were without having to pass around a list. */
  for (i = 0; i < NumberOfPlayers; ++i) {
    total = total_score (i);
    if ((total == WinningScore) && (i != winner))
      return -total;
  }

  return winner;
}
Exemplo n.º 2
0
static void
roll (void)
{
  if (!players[CurrentPlayer].comp) {
    RollSelectedDice ();
    if (NumberOfRolls > 1)
        FreeUndoRedoLists ();
    UpdateRollLabel ();
    LastHumanNumberOfRolls = NumberOfRolls;
  }
}
Exemplo n.º 3
0
/* Callback on Roll! button press */
gint
roll_dice (GtkWidget * widget, GdkEvent * event, gpointer data)
{
  if (!players[CurrentPlayer].comp) {
    RollSelectedDice ();
    if (NumberOfRolls > 1)
        FreeUndoRedoLists();
    UpdateRollLabel ();
    LastHumanNumberOfRolls = NumberOfRolls;
  }
  return FALSE;
}
Exemplo n.º 4
0
Arquivo: yahtzee.c Projeto: GNOME/tali
/* Must be called after window system is initted */
void
NewGame (void)
{
  int i, j;

  if (game_type == GAME_YAHTZEE) {
    FieldLabels = FieldLabelsYahtzee;
    NUM_FIELDS = NUM_FIELDS_YAHTZEE;
    NUM_LOWER = NUM_LOWER_YAHTZEE;
  }
  else if (game_type == GAME_KISMET) {
    FieldLabels = FieldLabelsKismet;
    NUM_FIELDS = NUM_FIELDS_KISMET;
    NUM_LOWER = NUM_LOWER_KISMET;
  }

  CurrentPlayer = 0;
  NumberOfRolls = 0;
  LastHumanNumberOfRolls = 0;
  FreeUndoRedoLists ();

  NumberOfPlayers = NumberOfComputers + NumberOfHumans;

  for (i = 0; i < MAX_NUMBER_OF_PLAYERS; ++i) {
    players[i].finished = 0;
    players[i].comp = 1;

    for (j = 0; j < NUM_FIELDS; ++j) {
      players[i].score[j] = 0;
      players[i].used[j] = 0;
    }
  }

  /* Possibly 0 humans? */
  for (i = 0; i < NumberOfHumans; i++)
    players[i].comp = 0;

  SelectAllDice ();
  RollSelectedDice ();
}