刚刚的有点问题,现在改好了:
#include
#include
#include
#include
char name[100],way[3][10]={"石头","剪子","布"},mode_name[2][20]={"三局两胜","五局三胜"};
void new_game(int mode,int *p_win,int * p_lose,int *p_tide){
char cmd[10];
int computer,user,win=0,lose=0;
int cnt[2]={3,5};
printf("***当前模式:\t%s\n",mode_name[mode]);
for(int i=0;i
fgets(cmd,9,stdin);
user=(cmd[0]-'1')%3;
if(user<0)user+=3;
computer=rand()%3;
printf("***%-10s:%s\n",name,way[user]);
printf("***%-10s:%s","电脑",way[computer]);
if(computer==user)
{
printf("\t\t平\n");
}
else if(user-computer==-1 || user-computer==2)
{
printf("\t%s\t赢\n",name);
win++;
}
else
{
printf("\t电脑\t赢\n");
lose++;
}
if(win>lose+cnt[mode]-i-1 || lose>win+cnt[mode]-i-1)
break;
}
if(win>lose)
{
printf("恭喜!该局你赢家了!\n");
(*p_win)++;
}
else if(win
(*p_lose)++;
printf(" 可惜!,你输了本局!\n");
}
else
{
(*p_tide)++;
printf(" 此局平局!\n");
}
}
int main(){
srand(time(0));
char cmd[10];
int mode=0;
int win,lose,tide;
win=lose=tide=0;
printf("请输入玩家姓名:\t");
fgets(name,99,stdin);
name[strlen(name)-1]='\0';
while(1){
printf("/******************石头剪子布游戏 ******************\n");
printf("***玩家:\t%s\n",name);
printf("***比赛情况:\t赢:\t%d\t输:\t%d\t平:\t%d\n",win,lose,tide);
printf("***当前模式:\t%s\n",mode_name[mode]);
printf("***N -- 开始游戏;\tC -- 切换模式;\tQ -- 退出;\n");
fgets(cmd,9,stdin);
if(cmd[0]=='N' || cmd[0]=='n')
new_game(mode,&win,&lose,&tide);
else if(cmd[0]=='Q' || cmd[0]=='q')
break;
else
mode=1-mode;
}
return 0;
}
#include
# include "time.h"
int getComputerType() {
srand((unsigned)time(NULL));
return rand()%3+1;
}
void printType(int type) {
switch (type) {
case 1:
printf("石头\n");
break;
case 2:
printf("剪刀\n");
break;
case 3:
printf("布\n");
break;
}
}
int Compare(int userType, int computerType) {
if (userType == computerType) {
return 0;
}
switch (computerType) {
case 1:
if (userType == 2) {
return -1;
} else {
return 1;
}
break;
case 2:
if (userType == 1) {
return 1;
} else {
return -1;
}
break;
case 3:
if (userType == 1) {
return -1;
} else {
return 1;
}
break;
}
}
int main() {
int i;
char name[20];
int rule;
int userType;
int computerType;
int userWinNum = 0;
int computerWinNum = 0;
while (1) {
printf("输入玩家名字:");
gets(name);
printf("选择模式1. 三局两胜;2. 五局三胜:");
scanf("%d", &rule);
if (rule != 1 && rule != 2) {
printf("模式选择错误!请输入1或2进行选择。\n\n");
continue;
}
printf("1.石头;2.剪刀;3. 布");
for (i=1; i
do{
printf("第%d局,请出:");
scanf("%d", &userType);
} while(userType == 1 || userType == 2 || userType == 3);
printf("计算机:");
printType(computerType);
printf("%s:", name);
printType(userType);
switch (Compare(userType, computerType)) {
case 0:
i--;
printf("平局,此局重来\n");
break;
case 1:
userWinNum++;
printf("你赢了!\n");
break;
case -1:
computerWinNum++;
printf("你输了!\n");
break;
}
printf("当前比分:\n%s:%d\n电脑:%d\n", name, userWinNum, computerWinNum);
if (userWinNum == (rule*2+1)/2 + 1) {
printf("恭喜你,你赢了!!\n");
break;
} else if (computerWinNum == (rule*2+1)/2 + 1) {
printf("很不幸,你输了!!\n");
break;
}
}
}
}
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
char *words[3]={"石头","剪刀","布"};
//本程序用S代表石头,C代表剪刀,P代表布
//本程序假设用户所有的输入,都是遵循电脑的提示进行的正确输入,不考虑输入错误的处理
void main()
{
char name[81];//玩家姓名
int mode;//代表赛制
char input;//代表你出的东东
int you,computer;//代表你和电脑出的东东
int win,lose,deuce;
srand( (unsigned)time( NULL ) ); //初始化随机数种子
printf("欢迎参加猜挙比赛,请输入您的名字:");
gets(name);
printf("欢迎您,%s\n",name);
printf("本次猜挙比赛,您想采取哪种赛制?(1.三局两胜\t2.五局三胜):");
scanf("%d",&mode);//此处不考虑用户输入1,2以外数字或非数字字符的情况
getchar();//过滤回车
if(mode==1)
printf("您选择了三局两胜制\n");
else if(mode==2)
printf("您选择了五局三胜制\n");
printf("比赛开始!!!\n");
win=lose=deuce=0;
while(1)
{
printf("请出拳{石头:(S/s),剪刀(C/c),布(P/p)}:");
input=getchar(); //此处不考虑用户输入了其他字符的情况
getchar();//过滤回车
if(input=='S' || input=='s')
you=0;
else if(input=='C' || input=='c')
you=1;
else you=2;
computer=rand()%3;
printf("你出了%s,电脑出了%s\n",words[you],words[computer]);
if(you-computer==-1 || you-computer==2)
{
win++;
printf("你赢了\n");
}
else if(you-computer==1 || you-computer==-2)
{
lose++;
printf("你输了\n");
}
else
{
deuce++;
printf("平手\n");
}
if((mode==1 && (win==2 || lose==2)) || (mode==2 && (win==3 || lose==3)))
{
if(win>lose)
{
printf("恭喜%s获得了最终胜利!\n",name);
}
else
{
printf("唉,你输了,下次再努力吧\n");
}
break;
}
else
{
printf("目前你赢了%d局,输了%d局,平了%d次\n",win,lose,deuce);
}
}
}
#include
#include
#include
int main()
{
char name[100];
int usr_select;
int system_select;
int num;
int usrwin=0,syswin=0,nowin=0;
printf("please in put you name:\n");
scanf("%s",name);
printf("please input how many games do you want to play:\n");
scanf("%d",&num);
while (num == 0 || (num %2) == 0)
{
printf("the num must be singular,please input a right number again:\n");
scanf("%d",&num);
}
int temp = 1;
for (temp;temp<=num; temp++)
{
printf("%d: input you chocice:(0:shi tou 1:jian zi 2:bu)",temp);
scanf("%d",&usr_select);
while( usr_select <0 || usr_select >2 )
{
printf("your choice is error,please input again(0:shi tou 1: jian zi 2:bu)\n");
scanf("%d",&usr_select);
}
srand(time(0));
system_select= rand()%3;
if(usr_select - system_select == -1 || usr_select-system_select == 2)
{
usrwin++;
printf("you win!\n");
}
else if(usr_select == system_select)
{
nowin++;
printf("no one win\n");
temp--;
}
else
{
syswin++;
printf("system win\n");
}
}
if(usrwin > syswin)
printf("%s is winner!\n",name);
else
printf("system is winner!\n");
}
Please input player name:wyd
Choose (A)5/3 or (B)3/2:a
Select Jiandao(J) or Shitou(S) or Bu(B): s
Computer is Shitou(S)The same!
Select Jiandao(J) or Shitou(S) or Bu(B): b
Computer is Jiandao(J)You Lost!
Select Jiandao(J) or Shitou(S) or Bu(B): j
Computer is Jiandao(J)The same!
Select Jiandao(J) or Shitou(S) or Bu(B): s
Computer is Shitou(S)The same!
Select Jiandao(J) or Shitou(S) or Bu(B): b
Computer is Shitou(S)You Win!
5 rounds, 1 win,3 same,1 lost,The Same!
Press any key to continue
#include
#include
#include
main()
{
int i,randAI,playerGuess,score[3]={0},round;
char sel,player[20]={0},game[3][12]={"Jiandao(J)","Shitou(S)","Bu(B)"};
srand((unsigned)time(NULL));
printf("Please input player name:");
gets(player);
printf("Choose (A)5/3 or (B)3/2:");
scanf("%c",&sel);
if (sel=='A' || sel=='a')
round =5;
else if (sel=='B' || sel=='b')
round =3;
else
printf("select error!\n");
for (i=0;i
randAI= rand()%2;
printf("Select %s or %s or %s: ",game[0],game[1],game[2]);
fflush(stdin);
scanf("%c",&sel);
printf("Computer is %s",game[randAI]);
if (sel=='J' || sel =='j' )
playerGuess=0;
else if (sel =='S' || sel =='s')
playerGuess=1;
else if (sel =='B' || sel =='b')
playerGuess=2;
else
printf("Wrong Choose!\n");
if ((randAI==0 && playerGuess==1 ) ||
(randAI==1 && playerGuess==2 ) ||
(randAI==2 && playerGuess==0 ))
{
printf("You Win!\n");
score[0]++;
}else if (randAI==playerGuess)
{
printf("The same!\n");
score[1]++;
}else
{
printf("You Lost!\n");
score[2]++;
}
}
if (score[0]>score[2])
printf("%d rounds, %d win,%d same,%d lost,%s win!\n",round,score[0],score[1],score[2],player);
else if (score[0]
else
printf("%d rounds, %d win,%d same,%d lost,The Same!\n",round,score[0],score[1],score[2],player);
}
有问题请追问 满意记得采纳哦 亲 包邮哦