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


/*printf something for this game*/ 
 
#include "p_r_s.h" 
 
/* Get the final result of this game*/ 
void prf_final_status(int win_cnt,int lose_cut) 
{ 
    if (win_cnt > lose_cut) 
    { 
        printf("CONGRAULATIONS -- You Win!\n\n"); 
    } 
    else if (win_cnt == lose_cut) 
    { 
        printf("A DRAW -- You Tie!\n\n"); 
    } 
    else 
    { 
        printf("Sorry -- You Lose!\n\n"); 
    } 
} 
 
/* Get the result of this game*/ 
void prf_game_status(int win_cnt,int lose_cnt,int tie_cnt) 
{ 
    printf("\n%s\n %s%4d\n %s%4d\n %s%4d\n %s%4d\n \n", 
           "Game Status:", 
           "    Win:    ", win_cnt, 
           "    Lose:   ", lose_cnt, 
           "    Tie:    ", tie_cnt, 
           "    Total:  ", win_cnt + lose_cnt + tie_cnt);  
     
    /*printf("\n%s%4d")*/ 
} 
/* Get the help of this game */ 
void prf_help(void) 
{ 
    printf("\n%s\n","The following characters can be used for input:\n" 
           "        p           for paper\n" 
           "        r           for rock\n" 
           "        s           for scissors\n" 
           "        g           for game status\n" 
           "        h           help,print this list\n" 
           "        i           reprint the instructions\n" 
           "        q           quit the game\n"); 
     
} 
/*Get the Instruction of this Game*/ 
void prf_instruction(void) 
{ 
    printf("/************************************************************************/\n"); 
    printf("/*                         PAPER ROCK SCISSORS                          */\n"); 
    printf("/************************************************************************/"); 
    printf("\n%s\n","PAPER ROCK SCISSORS:\n" 
           " In this game p is for \" paper,\" r is for\"rock,\" and"  
           " s is for\"scissors.\"\n" 
           " both the player and the machine\n" 
           " will choose one of p,r or s." 
           " if the two choices are the same,\n" 
           " then the game is a tie.otherwise:\n" 
           "    \"paper covers the rock\"    (a win for paper),\n" 
           "    \"rock breaks the scissors\" (a win for rock),\n" 
           "    \"scissors cut the paper\"   (a win for scissors),\n" 
           "\n" 
           "  There are other allowable inputs:\n" 
           "    g    for game status   (the number of wins so far),\n" 
           "    h    for help,\n" 
           "    i    for instructions  (reprint these instructions),\n" 
           "    q    quit this game    (to quit the game),\n" 
           "\n" 
           "  This game is played repeatedly until q is entered.\n" 
           "\n" 
           " Cood Luck and have a good time!\n"); 
} 
 
/*change the choice to string type*/ 
char *prf_string_choice(p_r_s choice) 
{ 
    char *char_choice = " "; 
    switch(choice) 
    { 
    case paper: 
        char_choice = "paper"; 
    	break; 
    case rock: 
        char_choice = "rock"; 
    	break;     
    case scissors: 
        char_choice = "scissors"; 
        break; 
    default: 
        printf("\nPROGRAMMER ERROR: Cannot get here!\n\n"); 
        break; 
    } 
    return char_choice;   
}