结对项目——黄金分割点游戏(陈香宇&蔡春燕)

结对项目名称:黄金分割点游戏(单机)

运行环境:vs

编译语言:c语言

项目分析:

实现的功能:用户可以选择继续游戏并且可以保存之前获得的分数,但是为了游戏的公平性,游戏的参数人数一开始用户确定以后就不能够改变。

Github地址:http://github.com/Yu0Ci/Project/blob/master/结对项目(陈香宇&蔡春燕).txt

总结与心得:本次项目的设计能够学习到另一个结对项目者的想法,能够让自己的思维能够开阔一些,在设计项目的过程中总是不断完善能够让自己的思维更加严密,同时也可以学习到另一个结对项目者的代码编写方法,能够让自己对于同一个代码编写能够有不同的写法。

代码:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
struct Grade
{
   int grade;
   struct Grade * next;
};
struct Figure
{
  int figure;
  struct Figure * next;
};
struct Grade * point(int N,int n,char name[50],int count,struct Grade *head);
void main()
{  
	//count 统计玩家游戏的次数
    int c, N,n,count;
    struct Grade *head_g,*x,*y;
	char name[50];
	count=0;
	int i;
    head_g=NULL;
	x=NULL;
    printf("**************************欢迎来到黄金点游戏直播现场**************************
");
    printf("规则是这样的,
N位玩家,
每位请写出1-100间的整数,
提交的数字最靠近G点(黄金点)的人得N分



");
	printf("**************************      请输入玩家姓名:     **************************
");
	scanf("%s",name);
	
    printf("**************************      请输入游戏人数:     **************************
");
	scanf("%d",&N);
    if(!(N>=1))
	{
	  printf("%s玩家输入错误
",name);
      exit(1);
	}
	do
	{
	printf("请%s玩家输入你想输入的数字(1~100)
",name);
    scanf("%d",&n);
	if((n>=1)&&(n<=100))
	{   
		if(count==0)
		{   
			for(i=0;i<N;i++)
			{
	    	y=(struct Grade*)malloc(sizeof(struct Grade));
        	y->grade=0;
		    y->next=NULL;
			if(head_g==NULL)
            {head_g=y; x=y;}
			else
			{x->next=y;x=y;}
			}
		
		}
		count=count+1;
		head_g=point(N,n,name,count,head_g);
	}
	else 
	exit(1);
    printf("^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ 诸位客官要不要继续玩?^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ 
");
	printf("继续请扣1,反之退出游戏
");
	scanf("%d",&c);
	}while(c==1);
	      
}
struct Grade * point(int N,int n,char name[50],int count,struct Grade *head_g)
{   
	struct Figure *head_p,*q,*p;
	struct Grade *x;
	double G,ave,amax,amin;
	srand(unsigned(time(NULL)));
	int i;
	ave=n;
	head_p=NULL;
	p=NULL;
    q=(struct Figure*)malloc(sizeof(struct Figure));
	q->figure=n;
	q->next=NULL;
	head_p=q;
	p=q;
    for(i=1;i<N;i++)
    {    
	    
	    q=(struct Figure*)malloc(sizeof(struct Figure));
		q->figure=rand()%101;
        q->next=NULL;
		if((p->figure)==0)
		{
			p->figure=1;
		}
        if(head_p==NULL)
		{
		  q->figure=n;
		  head_p=q;
		  p=q;
		}
		
		  p->next=q;
		  p=q;
		
		ave=ave+(p->figure);
        printf("第%d号玩家的数字是%d
",i+1,p->figure);
	}
	ave=ave/N;
	G=0.618*ave;
	printf("该组数据的平均值%lf:
",ave);
	printf("该组数据的黄金点为%lf:
",G);
	p=head_p;
    amin=fabs((p->figure)-G);
	amax=fabs((p->figure)-G);
	p=p->next;
	while(p!=NULL)//找到amax amin
	{
		if(fabs((p->figure)-G)<amax)
		{
			amax=fabs((p->figure)-G);
		}
		if(fabs((p->figure)-G)>amin)
		{	
			amin=fabs((p->figure)-G);
		}
			p=p->next;
	}
	p=head_p;
	x=head_g;
	while(p!=NULL)//打分
	{       
			if(amax==fabs((p->figure)-G))
			{   
			    	x->grade=(x->grade)+2;
			}
			if(amin==fabs((p->figure)-G))
			{   
				x->grade=(x->grade)-1;
			}
			p=p->next;
			x=x->next;
		 
	}
	x=head_g;
	printf("%s玩家的得分为%d(即第1号玩家的得分)
",name,x->grade);
	x=x->next;
	for(i=1;i<N;i++)
	{
      if((x->grade)!=0)
	  {
		  printf("第%d号玩家的得分为%d
",i+1,x->grade);
	  }
	  x=x->next;
	}
	printf("其余客官得分为0分。
");

	return head_g;
	
	

}

  

原文地址:https://www.cnblogs.com/Ci0Yu/p/7676464.html