selection.c

来自「一个使用VC环境 C语言开发的石头 剪刀 布的游戏」· C语言 代码 · 共 52 行

C
52
字号

/*Select paper rock and scissors*/

#include "p_r_s.h"
/* selection by machine (paper rock and scissors)*/
p_r_s selection_by_machine(void)
{
    return ((p_r_s)(rand() % 3));
}

/* selection by player (paper rock and scissors)*/
p_r_s selection_by_player(void)
{
    char c = 'h';
    p_r_s player_choice;

    printf("Please Input p,r,or s:");
//    c = getchar();
    while (isspace( c = getchar()))
    {
        //skip enter key and space
    }
    switch(c)
    {
    case 'p':
        player_choice = paper;
    	break;
    case 'r':
        player_choice = rock;
    	break;
    case 's':
        player_choice = scissors;
        break;
    case 'g':
        player_choice = game;
        break;
    case 'h':
        player_choice = help;
        break;
    case 'i':
        player_choice = instruction;
        break;
    case 'q':
        player_choice = quit;
        break;
    default:
        printf("You have inputted the forbidden character!\n\n");
        break;
   }
   return player_choice;
        
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?