| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 558 人关注过本帖
标题:编了个21点游戏 结果错误好多的样子T T求指点
取消只看楼主 加入收藏
贰贰
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-1-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
编了个21点游戏 结果错误好多的样子T T求指点
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n1=2,n2=2;
int main()
{
    void Game();
    char str[10];
    printf("if you want to start the game,enter start,otherwise log out\n");
    gets(str);
    if(strcmp(str,"start")==0)
        Game();
    else printf("Thank you for your playing!\n");
    return 0;
}
void Game()
{
    void poker(int x);int analyse(int y);int count(int x,int y);
    void Decide(int player,int computer);int Analyse(int y);
    int computer,player,a1,a2,b1,,b2;
    while(n1<=5&&n2<=5)
    {
        a1=rand()%52+1;a2=rand()%52+1;
        b1=rand()%52+1;b2=rand()%52+1;
        poker(a1);poker(a2);
        a1=analyse(a1);a2=analyse(a2);
        b1=Analyse(b1);b2=Analyse(b2);
        player=count(a1,a2);computer=count(b1,b2);
        Decide(player,computer);
    }
}
void poker(int x)
{
    void heart(int x);void club(int x);
    void spade(int x);void diamond(int x);
    if(x>=1&&x<=13)
        heart(x);
    else if(x>=14&&x<=26)
        club(x);
    else if(x>=27&&x<=39)
        spade(x);
    else diamond(x);
}
void heart(int x)
{char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=3;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void club(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=5;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void spade(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=6;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void diamond(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=4;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
int analyse(int x)
{int choose(int p),m;
    x=x%13;
    if(x==1||x==11||x==12||x==0)
        m=choose(x);
    return m;
}
int Analyse(int x)
{int choose(int p),m;
    x=x%13;
    if(x==11||x==12||x==0)
    m=10;
    return m;
}
int choose(int x)
{
    int t,p;
    if(x==1)
    {printf("You can choose 1 or 11 to decide your score\n");
    scanf("%d",&t);
    p=t;}
    else p=10;
    return p;
}
int count(int x,int y)
{
    int t;
    if(x+y>21)
        t=0;
    else t=x+y;
    return t;
}
void Decide(int player,int computer)
{
    int mark1(int player);int mark2(int computer);
    void compare(int x,int y);
    char string[10];
    printf("your score is:%d",x);
    printf("If you want another poker,enter yes,otherwise no.\n");
    gets(string);
    if(strcmp(string,"yes")==0)
    {    player=mark1(player);
    computer=mark2(computer);
    Decide(player,computer);
    }
    else compare(player,computer);
}
int mark1(int player)
{void poker(int x);
int analyse(int x);
int count(int x,int y);
    int p;
    p=rand()%52+1;
    poker(p);
    p=analyse(p);
    player=count(player,p);
    n1++;
    return player;
}
int mark2(int computer)
{
    int analyse(int x);
int count(int x,int y);
    int t;
    if(computer<=15)
    {t=rand()%52+1;
    t=analyse(t);
    computer=count(computer,t);
    n2++;}
    return computer;
}
void compare(int x,int y)
{
    if(x>y)
        printf("You are the winner!congratulations!\n");
    else if(x==y)
        printf("this is a draw");
    else printf("I am sorry to tell you that you lose the game.");
}
搜索更多相关主题的帖子: otherwise computer include playing return 
2015-01-30 01:15
贰贰
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-1-9
收藏
得分:0 
回复 2楼 somnus517
子函数不是只要在调用函数中声明就好了么  主函数中也要吗
2015-01-30 09:35
快速回复:编了个21点游戏 结果错误好多的样子T T求指点
数据加载中...
 
   



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

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