| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 563 人关注过本帖
标题:对于现在的C语言很迷茫,求助。
只看楼主 加入收藏
qq312154421
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:124
专家分:120
注 册:2010-6-7
结帖率:86.36%
收藏
已结贴  问题点数:20 回复次数:7 
对于现在的C语言很迷茫,求助。
我以前学了一点C语言,现在不知道从何学起,如果我从新学又觉得前面的太简单的看不下去,学后面又不知道从哪章开始学,现在很迷茫希望有人能指点我一下。非常感谢。另求一个师傅带我。
搜索更多相关主题的帖子: C语言 师傅 
2011-07-26 00:47
正电子
Rank: 3Rank: 3
来 自:江苏常州
等 级:论坛游侠
帖 子:30
专家分:112
注 册:2011-7-26
收藏
得分:3 
那就把书上的代码敲一边
2011-07-26 01:31
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
收藏
得分:3 
学这东西,我看还真得有不厌其烦的毅力,LZ还是静下心来.加油学吧!
2011-07-26 08:27
李不了
Rank: 1
等 级:新手上路
帖 子:8
专家分:4
注 册:2011-7-25
收藏
得分:3 
用c语言编写21点游戏(编游戏可以最大限度的激发兴趣,兴趣有了,自然不迷茫了!)
/*21点
计算电脑是否要牌100*(21-n)/21 + rand()%50 >=50 ? 要牌 :不要
*/
#include <stdio.h>
#include <time.h>
#include <string.h>
typedef enum point {ace=1,two,three,four,five,six,seven,eight,nine,ten,jack,queen,king}point;
point puker[52];
typedef struct player{
        char name[16];
        point pk[11];
        int num;
        int flag;
        int sign;
}player;
player computer,people;
int cnt = 0;

void initial(player *com, player *peo)           //初始化玩家
{
        int i;
        int j = 0;
        for(i=0; i<52; i++)
        {
                j++;
                if(j>13) j = 1;
                puker[i] = j;
        }
        for(i=0; i<11; i++)
        {
                com->pk[i] = 0;
                peo->pk[i] = 0;
        }
        strcpy(com->name,"computer");
        com->flag = 0;
        com->sign = 0;
        peo->flag = 0;
        peo->sign = 0;
}

/* 洗牌,随机抽取两张牌,交换位置,执行1000次 */
void shuffle()              //洗牌
{
        srand(time(NULL));
        int i,j,k;
        point temp;
        for(i=0;i<1000;i++)
        {
                j=rand()%52;
                k=rand()%52;
                temp=puker[j];
                puker[j]=puker[k];
                puker[k]=temp;
        }
}

void distribute(player *a)          //发牌
{
        int m;
        for(m=0;m<11;m++)
        {
                if(a->pk[m]==0)
                {
                        a->pk[m]=puker[cnt];
                        if(strcmp(a->name,"computer")!=0)
                        {
                                switch(a->pk[m])
                                {
                                        case 11:printf("%s拿到%c\n",a->name,'J');break;
                                        case 12:printf("%s拿到%c\n",a->name,'Q');break;
                                        case 13:printf("%s拿到%c\n",a->name,'K');break;
                                        default:printf("%s拿到%d\n",a->name,a->pk[m]);break;
                                }
                        }
                        break;
                }
        }
        cnt++;  //发一张牌后,指向后面的一张牌
}

void complay(player *p)            //电脑玩牌
{        
        if(p->flag==0)      //电脑目前还未决定是否继续要牌
        {
                p->num=0;
                int i;
                for(i=0; i<11; i++)     //任何一方拿到的最多的牌数未11张
                {
                        p->num+=p->pk[i];
                }
                if(p->num>21)           //电脑点数大于21,函数返回
                {
                        p->sign=1;
                        return;
                }
                int k;
                k=(100*(21-p->num)/21+rand()%50);       //产生随机数,计算是否要牌
                if(k>=50)
                {
                        printf("computer要牌\n");
                        distribute(p);
                }
                else if(k<50)
                {
                        printf("computer不要牌\n");
                        p->flag=1;
                }
        }
        else            //已经确定电脑不要牌了
        {
                printf("computer不要牌\n");
        }
}

void peoplay(player *p)           //玩家玩牌
{
        if (p->flag == 0)
        {
                int i;
                p->num=0;               //计算玩家点数
                for(i=0; i<11; i++)
                {
                        p->num += p->pk[i];
                }
                printf("%s现在有    %d点\n",p->name,p->num);
                if(p->num>21)           //玩家点数大于21点,函数返回
                {
                        p->sign=1;
                        return;
                }
                char a;
                printf("******是否继续要牌? y/n \n====================");
                scanf("%c",&a);
                scanf("%*[^\n]");scanf("%*c");  //清空输入缓冲区
                if(a=='y')        //玩家要牌
                {
                        distribute(p);
                }
                else if(a!='y')
                {
                        printf("不要牌\n");
                        p->flag=1;
                }
        }
        else if(p->flag==1)   //玩家不要牌
        {
                printf("%s不要牌\n",p->name);
        }
}

int main()
{
        printf("请输入玩家的姓名:");
        scanf("%s",people.name);
        scanf("%*[^\n]");scanf("%*c");  //清空输入缓冲区
        initial(&computer, &people);
        shuffle();
        distribute(&people);           //第一次给玩家发牌
        distribute(&computer);          //第一次给电脑发牌
        printf("给computer发牌\n");
        do
        {
                peoplay(&people);                 //电脑玩牌
                if (people.sign == 1) break;
                complay(&computer);               //电脑玩牌
                if (computer.sign == 1) break;
        }while(computer.flag==0 || people.flag==0); //循环终止条件是电脑爆了或电脑、玩家有都不要牌了
        if(people.sign==1)              //玩家爆了
        {
                printf("%s现在有%d点,%s现在有%d点\n",computer.name,computer.num,people.name,people.num);
                printf("%s爆了\n",people.name);
        }
        else if(computer.sign==1)              //电脑爆了
        {
                printf("%s现在有%d点,%s现在有%d点\n",computer.name,computer.num,people.name,people.num);
                printf("computer爆了\n");
        }
        else if(computer.num==people.num)    //都没爆而且点数相同
        {
                printf("%s现在有%d点,%s现在有%d点\n",computer.name,computer.num,people.name,people.num);
                printf("平局!\n");
        }
        else                   //都没爆,谁点数大谁赢
        {
                printf("%s现在有%d点,%s现在有%d点\n",computer.name,computer.num,people.name,people.num);
                printf("%s胜利了\n",(computer.num>people.num ? computer.name : people.name));
        }

        return 0;
}
2011-07-26 08:58
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:3 
还是得根据自己的具体情况量身定制 学习方法
2011-07-26 09:35
edgar_wang
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:64
专家分:178
注 册:2011-7-24
收藏
得分:3 
多敲代码,多跟踪调试程序,这是学编程的不二法门!
2011-07-26 10:53
我叫小杜
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:54
专家分:105
注 册:2011-6-11
收藏
得分:3 
顶四楼,谁都有过迷茫时候,殊不知迷茫过后是新晴。
寻寻觅觅疑无路,踏踏实实又一村。

坚持到底,不,轻言,放弃!
2011-07-26 11:25
ryyleader
Rank: 1
等 级:新手上路
帖 子:9
专家分:2
注 册:2012-9-29
收藏
得分:0 
找C语言高手QQ396806883,有大量视频和实例,能网络在线指导。诚心专业服务
2012-11-13 16:07
快速回复:对于现在的C语言很迷茫,求助。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018723 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved