• C语言小程序(七)、石头剪刀布


    本来挺简单的一个程序,但突然想把《Friends》给糅合进去,就多花了一些心思,这是我写过最有趣的程序了。

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int getrand()
    {
    	srand(time(NULL));
    	return rand()%3;
    }
    
    int win_lose(int choice)
    {
    	int rand = 0;
    	char *p[3] = {"SCISSORS", "STONE", "CLOTH"};
    	rand = getrand();
    	printf("
    The system give the %s.
    ",p[rand]);
    	rand++;
    
    	if(choice == rand)							//even
    	{
    		printf("
    Joey:	Hei, How you doing? We call it even, all right?
    ");
    		printf("	And if you are Chandler M. Bing, of course you will say ok.
    ");
    		return 0;
    	}
    	else if(rand==choice-1 || rand==choice+2)	//win
    	{
    		printf("
    Monica:	Of course the winner is Me. I knew it, you such a loser,
    ");
    		printf("	you can't win me ever!
    ");
    		printf("Ross:	It can't be, I am Profess Geller and I am a doctor.
    ");
    		printf("	I can't lose, you must cheat me last time. 
    ");
    		return 1;
    	}
    	else										//lose
    	{
    		printf("
    Rachel:	Oh my god! Oh my god! I can't believe this. Phoebe,
    ");
    		printf("	you are my best friend, can we forget this?
    ");
    		printf("Phoebe:	Ok, But it is when you say that you don't love Ross any more.
    ");
    		return -1;
    	}
    }
    
    int main()
    {
    	int choice = 0;
    	int flag = 0;
    	int rot = 0;
    	char ch;
    	system("clear");
    	printf("***********************************************");
    	printf("
    	Lets play a game about <Friends>.
    ");
    	printf("***********************************************");
    	printf("
    Janice:	You don't want to see me any more, right? 
    	So just chose a number quickly:
    ");
    	printf("
    1.SCISSORS
    2.STONE
    3.CLOTH
    ");
    	do
    	{
    		printf("
    Input your choice:");
    		scanf("%d",&choice);
    		if(choice>0 && choice<4) 
    		{
    			flag = win_lose(choice);
    			while((ch=getchar())!='
    ' && ch!=EOF);
    			printf("
    Gunther:I want to see Rachel");
    			if(flag == -1)
    				printf(" again");
    			printf(", so please replay it.(y/n)");
    		}
    		else
    		{
    			while((ch=getchar())!='
    ' && ch!=EOF);
    			printf("
    Monica:	What's the matter with you! What you need is just chose
    ");
    			printf("	a number from 1 to 3. So are you ready?(y/n)");
    		}
    
    		ch = getchar();
    	}
    	while(ch=='y' || ch=='Y' || ch=='
    ');
    
    	printf("
    Goodbye!
    ");
    
    	return 0;
    }
    

    谨以此程序纪念下《Friends》,Monica、Ross、Joey、Rachel、Chandler、Phoebe。

    还请诸位大侠自动忽略那蹩脚的英语。

  • 相关阅读:
    什么是Code Review
    支撑5亿用户、1.5亿活跃用户的Twitter最新架构详解及相关实现
    shell的数组操作
    CDN(内容分发网络)技术原理
    云计算服务模型,第 3 部分: 软件即服务(PaaS)
    Mongodb
    360的开源项目
    用linux mail命令发送邮件[Linux]
    BZOJ2761:[JLOI2011]不重复数字(map)
    BZOJ1821:[JSOI2010]部落划分(并查集,二分)
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218664.html
Copyright © 2020-2023  润新知