コード例 #1
0
ファイル: hit.c プロジェクト: nnatsu/Blackjack
/*
void computerHit: This function determines if the computer needs another card. Keeps giving the computer another card until they have the minimum dictated by the rules.
*/
void computerHit() {
  int total = totalValue(100); //calculate the total value of the hand
  //determines when the dealer shoulds hit
    while(total < 17) {
      dealCard(100, 0);
      //compCards++;
      total = totalValue(100);
    }
  //if level is hard, dealer hits on soft 17s
  if(levels == 1 && total == 17 && numAce > 0) {
      dealCard(100, 0);
      //compCards++;
      total = totalValue(100);
  }
}
コード例 #2
0
ファイル: bill.cpp プロジェクト: 0marcos0/Pedyrum
void Bill::getTotalValue()
{
    QString sql;

    sql = "select sum(valuebill) from bill where lower(typebill) = 'entrada'";

    float total;
    if (bd.search(sql))
        total = bd.loadSimple(0).toFloat();
    else
        total = 0;

    sql = "select sum(valuebill) from bill where lower(typebill) = 'saída'";

    if (bd.search(sql))
        total -= bd.loadSimple(0).toFloat();

    emit totalValue(QString::number(total));
}
コード例 #3
0
ファイル: hit.c プロジェクト: nnatsu/Blackjack
/*
int hitDecide(): this function askes the user if they want to hit or not. Returns a 1 if they answer with a y, returns a 0 if they answer with a n.
*/
int hitDecide(int i) {
  int total = totalValue(i);
  printf("Your current total is %d\n", total);
  if(totalChange == 1) {
    printf("We adjusted the point value of your aces to keep you from busting.\n");
    totalChange = 0;
  }
  if(total > 21) {
    printf("Your total is over 21, you have busted and cannot hit anymore\n");
    return 0;
  }
  printf("Do you want a hit(another card)? (Answer y or n)\n");
  char c;
  int x = 0;
  //take in input
  scanf(" %c", &c);
  //wait for acceptable input
  while(x == 0) {
    if(c != 'y' && c != 'n') {
        if (printed == 0){
            printf("I am sorry but your input was not correct. Please try again. The game will wait until you provide correct input.\n");
            printed++;
        } else {
            scanf("%c", &c);
        }
    } else {
      x = 1;
    }
  }
  //return correct number
  if(c == 'y') {
    return 1;
  } else  {
    return 0;
  }
}