void play(FILE* inputFile){ if(inputFile == NULL){ printf("IN HERE\n"); inputFile = fopen("src/animals.tree", "w+"); fputs("Aelephant", inputFile); rewind(inputFile); } binary_tree* tree = binary_tree_create_f(inputFile); if(inputFile != NULL){ printf("Welcome to the Animals game!\n"); //starts the game printf("\n"); printf("Shall we play a game? "); //asks to play char c; scanf(" %c", &c); //scans for either a 'y' or 'n' char while(c == 'y'){ char* val; tree = playRound(inputFile, tree); //plays the game printf("\n"); printf("Shall we play a game? "); //asks to play scanf(" %c", &c); //scans for either a 'y' or 'n' char } printf("Bye!\n"); //quits the game freopen("src/animals.tree", "w", inputFile); //makes a blank file to be written to binary_tree_write(tree, inputFile); //writes the new information to the file rewind(inputFile); //rewinds to the beginning of the file fclose(inputFile); //closes the file binary_tree_destroy(tree); //free's the malloc'ed memory return; } else{ printf("File is null or not in the correct format\n"); } }
int main(void){ double balance = 0, wager = 0; int choice = 0; printGameRules(); balance = getBankBalance(); //Display game menu and allow user to continually choose options until they quit while(choice != 4){ displayGameMenu(); choice = getChoice(); switch (choice){ case 1: printf("Current bank balance: $%.2lf\n", balance); break; case 2: balance = addMoney(balance); printf("You now have $%.2lf in the bank\n", balance); break; case 3: balance = playRound(balance); break; case 4: break; default: printf("\nMenu choice is invalid, Please choose a number between 1 and 4\n"); //Validates menu choice break; } } return 0; }
int main(int argc, char *argv[]) { int i; printf("\nRock! Paper! Scissors! Lizard! Spock!\n"); for( i = 0 ; i < 5 ; i++ ) playRound(); return 0; }
int main(int argc, char *argv[]) { int i; printf("\nRock! Paper! Scissors! Lizard! Spock!\n"); /* Play 5 rounds in a row (best out of 5?)*/ for( i = 0 ; i < 5 ; i++ ) playRound(); return 0; }
//play Craps game, calling all appropriate functions //Parameter: none //Return Type: none void playCraps(void) { int wallet; int bet; wallet = getWallet(); do { bet = makeBet(wallet); if (playRound()) //this just means if it's true { printf("You win!\n"); wallet += bet; } else //if playRound is false { printf("You lose!\n"); wallet -= bet; } } while (wallet >= MIN_BET&&doAgain()); goodbye(wallet); }
/** @return true for success. */ bool play() { m_table->clear(); for (GamePlayerBase* currentPlayer = firstHand();; currentPlayer = nextHand(*currentPlayer)) { prePlayRound(*currentPlayer); int roundResult = playRound(*currentPlayer); if (roundResult > 0) { } else if (roundResult == 0) { break; } else { return false; } } return true; }