cmd可以写小游戏吗?
# include & ltstdio.h & gt
# include & lttime.h & gt
# include & ltstdlib.h & gt
# include & ltstring.h & gt
Charname [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计算机,用户,win=0,lose = 0;
int cnt[2]={3,5 };
Printf("***当前模式:\t%s\n ",mode _ name[mode]);
for(int I = 0;我& ltCNT[mode];i++){
printf(" * * 1-stone;\ T2-剪刀\ T3-布\ n ");
fgets(cmd,9,stdin);
user =(cmd[0]--1 ')% 3;
如果(用户& lt0)用户+= 3;
computer = rand()% 3;
printf(" * * * * * %-10s:% s \ n ",name,way[user]);
printf(" * *-10s:% s ","计算机",way[计算机]);
if(计算机= =用户)
{
printf(" \ t \ t ping \ n ");
}
else if(用户计算机==-1 ||用户计算机==2)
{
Printf ("\ t% s \ tWin \n ",name);
win++;
}
其他
{
printf(" \ t computer \ tWin \ n ");
输++了;
}
if(win & gt;lose+CNT[mode]-I-1 | | lose & gt;win+CNT[模式]-i-1)
打破;
}
if(win & gt;输)
{
Printf("恭喜!你赢了这场比赛!\ n ");
(* p _ win)++;
}
else if(win & lt;输)
{
(* p _ lose)++;
Printf("真可惜!,你输了局!\ n ");
}
其他
{
(* p _ tide)++;
Printf("这场比赛是平局!\ n ");
}
}
int main(){
srand(time(0));
char cmd[10];
int mode = 0;
int赢,输,潮;
赢=输=潮= 0;
Printf("请输入玩家姓名:\ t ");
fgets(name,99,stdin);
name[strlen(name)-1]= ' \ 0 ';
while(1){
printf("/* * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf("*** Player: \t%s\n ",name);
printf(" * * * Competition:\ tWin:\ t % d \ t Lose:\ t % d \ t ping:\ 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 ')
新游戏(模式,和;赢了。失去& amp潮);
else if(cmd[0]=='Q' || cmd[0]=='q ')
打破;
其他
mode = 1-mode;
}
返回0;
}