鱼C论坛

 找回密码
 立即注册
查看: 1611|回复: 13

[技术交流] 自己一个一个跟着敲到代码,加油

[复制链接]
发表于 2020-4-12 09:43:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
/*
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define HUMANWIN 0
#define COMPUTERWIN 1
void welcome(void);
int get_computer();
int get_human();
void gameover(int winner);
int main(void)
{
        int human,computer;//1,2
        int result;
        int human_win = 0;
        int computer_win = 0;
        welcome();
        while (1)
        {
                human = get_human();
                computer = get_computer();
                //用户输入0表示退出游戏
                if (human == 0) {
                        break;
                }
                printf("你出");
                switch (human)
                {
                case 3: {printf("剪刀,"); break; }
                case 4:{printf("石头,"); break;}
            case 6: {printf("布"); break; }
                }
                printf("我出");
                switch (computer)
                {
                case 1: {printf("剪刀,"); break; }
                case 2:{printf("石头,"); break;}
                case 3:printf("布"); break;
                }
                result = human + computer;
                //你出剪刀,电脑出局:3+3==6k
                //你出石头,电脑出石头:6+1==7
                //你出布,电脑出石头:9+2==11
                //以为三种情况算你赢
                if (result == 6 || result==7 || result == 11)
                {
                        printf("你赢了\n\n");
                        human_win++;
                }
                //你出布,电脑出剪刀:9+1==10
                //你出剪刀,电脑出石头:3+2==5
                //你出石头,电脑出布:6+3=9
                //以为三种情况算你赢
                else if (result == 5 || result == 9 || result == 10)
                {
                        printf("我赢了\n\n");
                        computer_win++;
                }
                else {
                        printf("咱打平\n\n");
                }
                //打平也算人类赢
                if (human_win >= computer_win)
                {
                        gameover(HUMANWIN);

                }
                else {
                        gameover(COMPUTERWIN);
                }


        }
        return 0;

}
int get_human(void)
{
        int human;
        printf("请出拳(1剪刀/2石头/3布/0退出)->");
        scanf_s("%d",&human);
        while (human < 0 || human>3)
        {
                printf("出拳错误,请重新出拳(只需要输入即可)->");
                scanf_s("%d",&human);
        }
        return human*3;
}
int get_computer(void)
{
        int computer;
        srand((unsigned)time(NULL));
        computer = rand() % 3 + 1;
        return computer;
}
void welcome(void)
{
        printf("\n#####################\n");
        printf("欢迎来到猜拳小游戏!\n");
        printf("#####################\n");
}
void gameover(int winner)
{
        if (winner)
        {
                printf("\n#########################################################################\n");
                printf("#                                                                       #\n");
                printf("# ##    ##    ####    ##     ##    ##         ####     ######  ######## #\n");
                printf("#  ##  ##    ##  ##   ##     ##    ##        ##  ##   ##       ##       #\n");
                printf("#   ####    ##    ##  ##     ##    ##       ##    ##  ##       ##       #\n");
                printf("#    ##     ##    ##  ##     ##    ##       ##    ##  ######   #######  #\n");
                printf("#    ##     ##    ##  ##     ##    ##       ##    ##       ##  ##       #\n");
                printf("#    ##      ##  ##    ##   ##     ##        ##  ##        ##  ##       #\n");
                printf("#    ##       ####      #####      #######    ####    ######   ######## #\n");
                printf("#                                                                       #\n");
                printf("#########################################################################\n");
        }
        else
        {
                printf("\n##########################################################################\n");
                printf("#                                                                        #\n");
                printf("# ##    ##    ####    ##     ##    ##              ##  ######  ##     ## #\n");
                printf("#  ##  ##    ##  ##   ##     ##    ##      ##      ##    ##    ###    ## #\n");
                printf("#   ####    ##    ##  ##     ##    ##     ####     ##    ##    ## #   ## #\n");
                printf("#    ##     ##    ##  ##     ##     ##   ##  ##   ##     ##    ##  #  ## #\n");
                printf("#    ##     ##    ##  ##     ##      ## ##    ## ##      ##    ##   # ## #\n");
                printf("#    ##      ##  ##    ##   ##        ###      ###       ##    ##    ### #\n");
                printf("#    ##       ####      #####          #        #      ######  ##     ## #\n");
                printf("#                                                                        #\n");
                printf("##########################################################################\n");

        }
}
*/
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-4-12 09:46:46 | 显示全部楼层
要用代码格式发代码哦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 09:54:47 | 显示全部楼层
本帖最后由 liuzhengyuan 于 2020-4-12 10:02 编辑

不错不错

为啥是
  1. scanf_s
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 09:58:00 | 显示全部楼层
  1. /*
  2. #include<stdio.h>
  3. #include<time.h>
  4. #include<stdlib.h>
  5. #define HUMANWIN 0
  6. #define COMPUTERWIN 1
  7. void welcome(void);
  8. int get_computer();
  9. int get_human();
  10. void gameover(int winner);
  11. int main(void)
  12. {
  13.         int human,computer;//1,2
  14.         int result;
  15.         int human_win = 0;
  16.         int computer_win = 0;
  17.         welcome();
  18.         while (1)
  19.         {
  20.                 human = get_human();
  21.                 computer = get_computer();
  22.                 //用户输入0表示退出游戏
  23.                 if (human == 0) {
  24.                         break;
  25.                 }
  26.                 printf("你出");
  27.                 switch (human)
  28.                 {
  29.                 case 3: {printf("剪刀,"); break; }
  30.                 case 4:{printf("石头,"); break;}
  31.             case 6: {printf("布"); break; }
  32.                 }
  33.                 printf("我出");
  34.                 switch (computer)
  35.                 {
  36.                 case 1: {printf("剪刀,"); break; }
  37.                 case 2:{printf("石头,"); break;}
  38.                 case 3:printf("布"); break;
  39.                 }
  40.                 result = human + computer;
  41.                 //你出剪刀,电脑出局:3+3==6k
  42.                 //你出石头,电脑出石头:6+1==7
  43.                 //你出布,电脑出石头:9+2==11
  44.                 //以为三种情况算你赢
  45.                 if (result == 6 || result==7 || result == 11)
  46.                 {
  47.                         printf("你赢了\n\n");
  48.                         human_win++;
  49.                 }
  50.                 //你出布,电脑出剪刀:9+1==10
  51.                 //你出剪刀,电脑出石头:3+2==5
  52.                 //你出石头,电脑出布:6+3=9
  53.                 //以为三种情况算你赢
  54.                 else if (result == 5 || result == 9 || result == 10)
  55.                 {
  56.                         printf("我赢了\n\n");
  57.                         computer_win++;
  58.                 }
  59.                 else {
  60.                         printf("咱打平\n\n");
  61.                 }
  62.                 //打平也算人类赢
  63.                 if (human_win >= computer_win)
  64.                 {
  65.                         gameover(HUMANWIN);

  66.                 }
  67.                 else {
  68.                         gameover(COMPUTERWIN);
  69.                 }


  70.         }
  71.         return 0;

  72. }
  73. int get_human(void)
  74. {
  75.         int human;
  76.         printf("请出拳(1剪刀/2石头/3布/0退出)->");
  77.         scanf_s("%d",&human);
  78.         while (human < 0 || human>3)
  79.         {
  80.                 printf("出拳错误,请重新出拳(只需要输入即可)->");
  81.                 scanf_s("%d",&human);
  82.         }
  83.         return human*3;
  84. }
  85. int get_computer(void)
  86. {
  87.         int computer;
  88.         srand((unsigned)time(NULL));
  89.         computer = rand() % 3 + 1;
  90.         return computer;
  91. }
  92. void welcome(void)
  93. {
  94.         printf("\n#####################\n");
  95.         printf("欢迎来到猜拳小游戏!\n");
  96.         printf("#####################\n");
  97. }
  98. void gameover(int winner)
  99. {
  100.         if (winner)
  101.         {
  102.                 printf("\n#########################################################################\n");
  103.                 printf("#                                                                       #\n");
  104.                 printf("# ##    ##    ####    ##     ##    ##         ####     ######  ######## #\n");
  105.                 printf("#  ##  ##    ##  ##   ##     ##    ##        ##  ##   ##       ##       #\n");
  106.                 printf("#   ####    ##    ##  ##     ##    ##       ##    ##  ##       ##       #\n");
  107.                 printf("#    ##     ##    ##  ##     ##    ##       ##    ##  ######   #######  #\n");
  108.                 printf("#    ##     ##    ##  ##     ##    ##       ##    ##       ##  ##       #\n");
  109.                 printf("#    ##      ##  ##    ##   ##     ##        ##  ##        ##  ##       #\n");
  110.                 printf("#    ##       ####      #####      #######    ####    ######   ######## #\n");
  111.                 printf("#                                                                       #\n");
  112.                 printf("#########################################################################\n");
  113.         }
  114.         else
  115.         {
  116.                 printf("\n##########################################################################\n");
  117.                 printf("#                                                                        #\n");
  118.                 printf("# ##    ##    ####    ##     ##    ##              ##  ######  ##     ## #\n");
  119.                 printf("#  ##  ##    ##  ##   ##     ##    ##      ##      ##    ##    ###    ## #\n");
  120.                 printf("#   ####    ##    ##  ##     ##    ##     ####     ##    ##    ## #   ## #\n");
  121.                 printf("#    ##     ##    ##  ##     ##     ##   ##  ##   ##     ##    ##  #  ## #\n");
  122.                 printf("#    ##     ##    ##  ##     ##      ## ##    ## ##      ##    ##   # ## #\n");
  123.                 printf("#    ##      ##  ##    ##   ##        ###      ###       ##    ##    ### #\n");
  124.                 printf("#    ##       ####      #####          #        #      ######  ##     ## #\n");
  125.                 printf("#                                                                        #\n");
  126.                 printf("##########################################################################\n");

  127.         }
  128. }
  129. */
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-12 12:58:19 | 显示全部楼层
乘号 发表于 2020-4-12 09:46
要用代码格式发代码哦

好的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-12 13:00:23 | 显示全部楼层

我用的vs2019编译器支持新版的scanf_s函数不兼容以前版本的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 13:09:22 | 显示全部楼层
加油
这是体力活
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-13 20:22:09 | 显示全部楼层
fly3412 发表于 2020-4-12 13:09
加油
这是体力活

你开始学编程不跟着敲代码吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-13 23:03:16 | 显示全部楼层
1024-web1 发表于 2020-4-13 20:22
你开始学编程不跟着敲代码吗

现在有的机构出的课件。最开始是从填空做起来。
大架构已经写好。只管几个重要的命令输入即可。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-14 13:33:35 | 显示全部楼层
fly3412 发表于 2020-4-13 23:03
现在有的机构出的课件。最开始是从填空做起来。
大架构已经写好。只管几个重要的命令输入即可。

你报班了??我没报,等考完研再说吧,现在不慌
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-15 00:10:20 | 显示全部楼层
1024-web1 发表于 2020-4-14 13:33
你报班了??我没报,等考完研再说吧,现在不慌

给孩子报了暑秋班。老师说,大人不用报班。找书,找网站自己刷题就行了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-22 09:43:23 | 显示全部楼层
fly3412 发表于 2020-4-15 00:10
给孩子报了暑秋班。老师说,大人不用报班。找书,找网站自己刷题就行了。

真好,奥里给吧,你都要孩子了,哎,我还没谈过恋爱吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-22 12:46:16 | 显示全部楼层
1024-web1 发表于 2020-4-22 09:43
真好,奥里给吧,你都要孩子了,哎,我还没谈过恋爱吧

把电脑当做爱人,把编程当人帮孩子,会不会心情愉快些?

孩子上三年级了。已经开始学点编程了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-24 11:28:16 | 显示全部楼层
fly3412 发表于 2020-4-22 12:46
把电脑当做爱人,把编程当人帮孩子,会不会心情愉快些?

孩子上三年级了。已经开始学点编程了。 {:5_1 ...

都加油,未来还是美好的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-2 12:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表