26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

j = i + 1;<br />

while(j < 16) {<br />

if(numbers[i] == numbers[j])<br />

match = numbers[i];<br />

j++;<br />

}<br />

}<br />

if(match != -1) {<br />

printf("The dealer matched <strong>the</strong> number %d!\n", match);<br />

printf("You lose %d credits.\n", wager);<br />

player.credits -= wager;<br />

} else {<br />

printf("There were no matches! You win %d credits!\n", wager);<br />

player.credits += wager;<br />

}<br />

return 0;<br />

// This is <strong>the</strong> Find <strong>the</strong> Ace game.<br />

// It returns -1 if <strong>the</strong> player has 0 credits.<br />

int find_<strong>the</strong>_ace() {<br />

int i, ace, total_wager;<br />

int invalid_choice, pick = -1, wager_one = -1, wager_two = -1;<br />

char choice_two, cards[3] = {'X', 'X', 'X'};<br />

ace = rand()%3; // Place <strong>the</strong> ace randomly.<br />

printf("******* Find <strong>the</strong> Ace *******\n");<br />

printf("In this game, you can wager up to all <strong>of</strong> your credits.\n");<br />

printf("Three cards will be dealt out, two queens and one ace.\n");<br />

printf("If you find <strong>the</strong> ace, you will win your wager.\n");<br />

printf("After choosing a card, one <strong>of</strong> <strong>the</strong> queens will be revealed.\n");<br />

printf("At this point, you may ei<strong>the</strong>r select a different card or\n");<br />

printf("increase your wager.\n\n");<br />

if(player.credits == 0) {<br />

printf("You don't have any credits to wager!\n\n");<br />

return -1;<br />

}<br />

while(wager_one == -1) // Loop until valid wager is made.<br />

wager_one = take_wager(player.credits, 0);<br />

print_cards("Dealing cards", cards, -1);<br />

pick = -1;<br />

while((pick < 1) || (pick > 3)) { // Loop until valid pick is made.<br />

printf("Select a card: 1, 2, or 3 ");<br />

scanf("%d", &pick);<br />

}<br />

pick--; // Adjust <strong>the</strong> pick since card numbering st<strong>art</strong>s at 0.<br />

i=0;<br />

while(i == ace || i == pick) // Keep looping until<br />

i++;<br />

// we find a valid queen to reveal.<br />

cards[i] = 'Q';<br />

print_cards("Revealing a queen", cards, pick);<br />

Programming 109

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!