Esempio n. 1
0
void hangman() {
	char *toguess;
	int i;
	char correct[128];
	char guess[4];
	unsigned int len = 0;
	int right;
	int correctcount = 0;
	unsigned int wagered = 0;

	bzero(correct, 128);
	toguess = pickaword(state);
	len = cgc_strlen(toguess);
	state->hangmanguess = 0;

	wagered = getBet(state);
	if(wagered == -1)
		return;

	while(state->hangmanguess < 5)
	{
		right = 0;
		bzero(guess, 4);
		put(renderBoard(state));
		for(i=0;i<len;i++)
		{
			if(correct[i] == 0)
				put("_");
			else {
				put(&correct[i]);
				i+= cgc_strlen(&correct[i])-1;
			}
		}

		put("\n");
		put("Please enter a guess: ");
		recvUntil(0, guess, 3, '\n');
		for(i=0;i<len;i++)
		{
			if(guess[0] == toguess[i])
			{
				correct[i] = guess[0];
				right = 1;
				correctcount++;
			}
		}
		if(right == 0)
			state->hangmanguess++;
		if(cgc_strlen(correct) == cgc_strlen(toguess))
		{
			handleOutcome(state, 1, wagered);
			return;
		}
	}
	handleOutcome(state, 0, wagered);
}
Esempio n. 2
0
void Cpot::print()
{  
#ifdef DEBUG_POT_

  std::cout << "Chips=" << getChips()
            << " Stake=" << getStake()
            << " Bet=" << getBet() << endl;

  cout << "   chips ---> [";
  for (int i = 0; i < 9; i++)
  {
    cout << chips_[i] << ' ';
  }
  cout << chips_[9] << ']' << endl;

#endif
};  
Esempio n. 3
0
main() {
    int bet;
    int bank = 100;
    int i;
    int cardRank[5];
    int cardSuit[5];

    int finalRank[5];
    int finalSuit[5];
    int ranksinHand[13];
    int suitsinHand[4];
    int winnings;
    time_t t;
    char suit, rank, stillPlay;

    // This function is called outside of the do-while loop because the 
    // greeting only needs to be displayed once,
    // while everything else in main will run multiple times,
    // depending on how many times the user wants to play.

    printGreeting();

    // Loop runs each time the user plays a new hand of draw poker

    do {
        bet = getBet();
        srand(time(&t));
        getFirstHand(cardRank, cardSuit);
        printf("Your five cards: \n");
        
        for (i=0; i<5; i++) {
            suit = getSuit(cardSuit[i]);
            rank = getRank(cardRank[i]);
            printf("Card #%d: %c%c\n", i+1, rank, suit);
        }

        // These two arrays are used to figure out the value of 
        // the player's hand. However, they must be zeroed out
        // in case the user plays multiple hands.

        for (i=0; i<4; i++) {
            suitsinHand[i] = 0;
        }

        for (i=0; i<13; i++) {
            ranksinHand[i] = 0;
        }

        getFinalHand(cardRank, cardSuit, finalRank, finalSuit,
                        ranksinHand, suitsinHand);

        printf("Your final five cards: \n");
        for (i = 0; i < 5; i++) {
            suit = getSuit(finalSuit[i]);
            rank = getRank(finalRank[i]);
            printf("Card #%d: %c%c\n", i+1, rank, suit);
        }

        winnings = analyzeHand(ranksinHand, suitsinHand);
        printf("You won %d!\n", bet*winnings);
        bank = bank - bet + (bet*winnings);
        printf("\nYour bank is now %d.\n", bank);
        printf("\nDo you want to play again? ");
        scanf(" %c", &stillPlay);
    } while (toupper(stillPlay) == 'Y');


    return 0;
}