/*
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define HUMANWIN 0
#define COMPUTERWIN 1
void welcome(void);
int get_computer();
int get_human();
void gameover(int winner);
int main(void)
{
int human,computer;//1,2
int result;
int human_win = 0;
int computer_win = 0;
welcome();
while (1)
{
human = get_human();
computer = get_computer();
//用户输入0表示退出游戏
if (human == 0) {
break;
}
printf("你出");
switch (human)
{
case 3: {printf("剪刀,"); break; }
case 4:{printf("石头,"); break;}
case 6: {printf("布"); break; }
}
printf("我出");
switch (computer)
{
case 1: {printf("剪刀,"); break; }
case 2:{printf("石头,"); break;}
case 3:printf("布"); break;
}
result = human + computer;
//你出剪刀,电脑出局:3+3==6k
//你出石头,电脑出石头:6+1==7
//你出布,电脑出石头:9+2==11
//以为三种情况算你赢
if (result == 6 || result==7 || result == 11)
{
printf("你赢了\n\n");
human_win++;
}
//你出布,电脑出剪刀:9+1==10
//你出剪刀,电脑出石头:3+2==5
//你出石头,电脑出布:6+3=9
//以为三种情况算你赢
else if (result == 5 || result == 9 || result == 10)
{
printf("我赢了\n\n");
computer_win++;
}
else {
printf("咱打平\n\n");
}
//打平也算人类赢
if (human_win >= computer_win)
{
gameover(HUMANWIN);
}
else {
gameover(COMPUTERWIN);
}
}
return 0;
}
int get_human(void)
{
int human;
printf("请出拳(1剪刀/2石头/3布/0退出)->");
scanf_s("%d",&human);
while (human < 0 || human>3)
{
printf("出拳错误,请重新出拳(只需要输入即可)->");
scanf_s("%d",&human);
}
return human*3;
}
int get_computer(void)
{
int computer;
srand((unsigned)time(NULL));
computer = rand() % 3 + 1;
return computer;
}
void welcome(void)
{
printf("\n#####################\n");
printf("欢迎来到猜拳小游戏!\n");
printf("#####################\n");
}
void gameover(int winner)
{
if (winner)
{
printf("\n#########################################################################\n");
printf("# #\n");
printf("# ## ## #### ## ## ## #### ###### ######## #\n");
printf("# ## ## ## ## ## ## ## ## ## ## ## #\n");
printf("# #### ## ## ## ## ## ## ## ## ## #\n");
printf("# ## ## ## ## ## ## ## ## ###### ####### #\n");
printf("# ## ## ## ## ## ## ## ## ## ## #\n");
printf("# ## ## ## ## ## ## ## ## ## ## #\n");
printf("# ## #### ##### ####### #### ###### ######## #\n");
printf("# #\n");
printf("#########################################################################\n");
}
else
{
printf("\n##########################################################################\n");
printf("# #\n");
printf("# ## ## #### ## ## ## ## ###### ## ## #\n");
printf("# ## ## ## ## ## ## ## ## ## ## ### ## #\n");
printf("# #### ## ## ## ## ## #### ## ## ## # ## #\n");
printf("# ## ## ## ## ## ## ## ## ## ## ## # ## #\n");
printf("# ## ## ## ## ## ## ## ## ## ## ## # ## #\n");
printf("# ## ## ## ## ## ### ### ## ## ### #\n");
printf("# ## #### ##### # # ###### ## ## #\n");
printf("# #\n");
printf("##########################################################################\n");
}
}
*/
|