码迷,mamicode.com
首页 > 其他好文 > 详细

编了个21点游戏 结果错误好多的样子T T求指点

时间:2015-02-02 12:23:45      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

#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.");

}

编了个21点游戏 结果错误好多的样子T T求指点

标签:

原文地址:http://www.cnblogs.com/g564ds46g/p/4267249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!