www.pudn.com > Paper_Rock_Scissors.rar > main.c


/************************************************************************/ 
/* main function                                                        */ 
/************************************************************************/ 
 
#include "p_r_s.h" 
int main(void) 
{ 
    int win_cnt = 0; 
    int lose_cnt = 0; 
    int tie_cnt = 0; 
    p_r_s player_choice; 
    p_r_s machine_choice; 
    outcome result; 
 
    srand(time(NULL)); // seed the random number generator 
    prf_instruction(); 
    while ((player_choice = selection_by_player()) != quit) 
        switch(player_choice) 
        { 
        case paper: 
        case rock: 
        case scissors: 
            machine_choice = selection_by_machine(); 
            result = compare(player_choice,machine_choice); 
 
            printf("\n%s%s\n%s%s\n\n", 
                   "The Player choice  :",prf_string_choice(player_choice), 
                   "The Machine choice :",prf_string_choice(machine_choice)); 
 
            report_and_rabulate(result,&win_cnt,&lose_cnt,&tie_cnt); 
            break; 
        case game: 
             prf_game_status(win_cnt,lose_cnt,tie_cnt); 
            break; 
        case help: 
            prf_help(); 
            break; 
        case instruction: 
            prf_instruction(); 
            break; 
        case quit: 
            printf("\nYou have quited this game!\n"); 
            exit(1); 
            break;     
        default: 
            printf("\nPROGRAMMER ERROR: Cannot get here!\n\n"); 
            //exit(1); 
            break; 
 
        }       
    prf_game_status(win_cnt,lose_cnt,tie_cnt); 
    prf_final_status(win_cnt,lose_cnt); 
    return 0; 
}