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


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

    运行环境:vs

    编译语言:c语言

    项目分析:

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

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

    总结与心得:此次项目主要是由玩家先输入游戏人数n,然后再由玩家输入自己理想的数字,同时再由电脑随机产生n-1个数字,这样可以很好的避免保持先后的顺序从而导致的不公平。通过此次项目感觉自己的逻辑能力变得更强了,对于指针的用法也很熟悉了,以及数字的简单存储之类的,从中也锻炼了与伙伴结对合作的能力,希望下次可以再接再厉做得更好。

    代码:

    #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("**************************欢迎来到黄金点游戏直播现场**************************\n");
        printf("规则是这样的,\nN位玩家,\n每位请写出1-100间的整数,\n提交的数字最靠近G点(黄金点)的人得N分\n\n\n\n");
        printf("**************************      请输入玩家姓名:     **************************\n");
        scanf("%s",name);
         
        printf("**************************      请输入游戏人数:     **************************\n");
        scanf("%d",&N);
        if(!(N>=1))
        {
          printf("%s玩家输入错误\n",name);
          exit(1);
        }
        do
        {
        printf("请%s玩家输入你想输入的数字(1~100)\n",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("^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ 诸位客官要不要继续玩?^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ \n");
        printf("继续请扣1,反之退出游戏\n");
        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\n",i+1,p->figure);
        }
        ave=ave/N;
        G=0.618*ave;
        printf("该组数据的平均值%lf:\n",ave);
        printf("该组数据的黄金点为%lf:\n",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号玩家的得分)\n",name,x->grade);
        x=x->next;
        for(i=1;i<N;i++)
        {
          if((x->grade)!=0)
          {
              printf("第%d号玩家的得分为%d\n",i+1,x->grade);
          }
          x=x->next;
        }
        printf("其余客官得分为0分。\n");
     
        return head_g;
         
         
     
    }
    

      

  • 相关阅读:
    linux进程调度(zz)
    为什么vfork的子进程里用return,整个程序会挂掉,而且exit不会(zz)
    ubuntu安装samba
    【前端知乎系列】ArrayBuffer 和 Blob 对象
    【Web技术】442- 关于图片懒加载的几种方案
    【Web技术】441- 蚂蚁前端研发最佳实践
    【面试题】440- 10 道 Nodejs EventLoop 和事件相关面试题
    【面试题】439- 这是一道网红面试题
    【Web技术】438- 移动端体验优化经验总结与实践
    记 · 寒风依旧 · 虎跑路和人生路
  • 原文地址:https://www.cnblogs.com/xiangyujojo/p/7752131.html
Copyright © 2020-2023  润新知