找到了一个C语言代码,能看懂一些基础,但是具体的功能运行还是没太看明白,有可以讲解一下这个代码的吗,很需要

是个游戏代码,但不知道具体那个方法对应的是哪个功能,用的是Codeblocks运行的c语言代码

#include
#include
#include
#include<time.h>
#include
/********函数变量声明********/
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;
typedef struct Birds {
  int x, y;
  int condition;
}Birds;

Birds * Bird;

typedef struct Bg {
  int x, y;
  int l_blank;
  int reward[9];
  struct Bg * pri;
  struct Bg * next;
}Bg;
Bg * Bg1;

void Position(int x, int y) {
  COORD pos = {
    x - 1, y - 1
  };
  HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleCursorPosition(Out, pos);
}
void CreatBird() {
  Bird -> x = 41;
  Bird -> y = 10;
  Bird -> condition = 0;
}
void CreatBg() {
  Bg * Bg2 = (Bg * ) malloc(sizeof(Bg));
  Bg1 -> x = 90;
  Bg1 -> y = 8;
  Bg2 -> x = Bg1 -> x + Distance;
  Bg2 -> y = 9;
  Bg1 -> l_blank = Max_blank - Grade;
  Bg2 -> l_blank = Max_blank - Grade;
  Bg1 -> next = Bg2;
  Bg1 -> pri = Bg2;
  Bg2 -> next = Bg1;
  Bg2 -> pri = Bg1;
}
void InsertBg(Bg * p) {
  int temp;
  Bg * Bgs = (Bg * ) malloc(sizeof(Bg));
  Bgs -> x = p -> pri -> x + Distance;
  Bgs -> l_blank = Max_blank - Grade;
  srand((int) time(0));
  temp = rand();
  if (temp % 2 == 0) //++
  {
    if ((temp % 4 + p -> pri -> y + Max_blank - Grade) < 21)
      Bgs -> y = p -> pri -> y + temp % 4;
    else
      Bgs -> y = p -> pri -> y;
  } else {
    if ((p -> pri -> y - temp % 4) > 2)
      Bgs -> y = p -> pri -> y - temp % 4;
    else
      Bgs -> y = p -> pri -> y;
  }
  Bgs -> pri = p -> pri;
  Bgs -> next = p;
  p -> pri -> next = Bgs;
  p -> pri = Bgs;
}
void Check_Bg(Bg * q) {
  Bg * p = q;
  int i = 0, temp;
  while (++i <= 5) {
    if (p -> x > -4)
      p = p -> next;
    else {srand((int) time(0));
      temp = rand();
      if (temp % 2 == 0) //++
      {
        if ((temp % 4 + p -> y + Max_blank - Grade) < 21)
          p -> y = p -> y + temp % 4;
        else
          p -> y = p -> y;
        p -> x = p -> pri -> x + Distance;
        p -> l_blank = Max_blank - Grade;
      } else {
        if ((p -> y - temp % 4) > 2)
          p -> y = p -> y - temp % 4;
        else
          p -> y = p -> y;
        p -> x = p -> pri -> x + Distance;
        p -> l_blank = Max_blank - Grade;
      }
    }
  }
}
void Loop_Bg(Bg * q) {
  Bg * p = q;
  int i = 0;
  while (++i <= 5) {
    p -> x = p -> x - 1;
    p = p -> next;
    if (Bird -> x == p -> x) {
      Score += 1;
      if (Score % 4 == 0 && Grade < 4)
        Grade++;
    }
  }
}
void Prt_Bg(Bg * q) {
  Bg * p = q;
  int i = 0, k, j;
  while (++i <= 5) {
    if (p -> x > 0 && p -> x <= 78) {
      for (k = 2; k < p -> y; k++) {
        Position(p -> x + 1, k);
        PR_Box;
        PR_Box;
        PR_Blank
      }
      Position(p -> x, p -> y);
      PR_Box;
      PR_Box;
      PR_Box;
      PR_Blank;
      Position(p -> x, p -> y + p -> l_blank);
      PR_Box;
      PR_Box;
      PR_Box;
      PR_Blank;
      k = k + p -> l_blank + 1;
      for (k; k <= 22; k++) {
        Position(p -> x + 1, k);
        PR_Box;
        PR_Box;
        PR_Blank;
      }
      Position(p -> x, 23);
      for (k = 1; k < Distance / 3 - 2; k++)
        PR_Land;
    }
    p = p -> next;
    if (p -> x == 0) {
      for (j = 2; j < p -> y; j++) {
        Position(p -> x + 1, j);
        PR_Blank;
        PR_Blank;
      }
      Position(p -> x + 1, p -> y);
      PR_Blank;
      PR_Blank;
      PR_Blank;
      Position(p -> x + 1, p -> y + Max_blank - Grade);
      PR_Blank;
      PR_Blank;
      PR_Blank;
      j = j + Max_blank - Grade + 1;
      for (j; j <= 22; j++) {
        Position(p -> x + 1, j);
        PR_Blank;
        PR_Blank;
      }
    }
  }
}
void PrtBg() {
  int i;
  Position(1, 1);
  PR_Bg_TL;
  Position(79, 1);
  PR_Bg_TR;
  Position(1, 24);
  PR_Bg_DL;
  Position(79, 24);
  PR_Bg_DR;
  for (i = 3; i <= 78; i += 2) {
    Position(i, 1);
    PR_Bg_X;
    Position(i, 24);
    PR_Bg_X;
  }
}
void PrtBird() {
  Position(Bird -> x, Bird -> y - 1);
  PR_Blank;
  Position(Bird -> x, Bird -> y);
  PR_FBird;
  Position(38, 2);
  printf("Score:%d", Score);
}
int CheckYN(Bg * q) {
  Bg * p = q;
  int i = 0;
  while (++i <= 5) {
    if (Bird -> y > 23)
      return 0;
    if (Bird -> x == p -> x && Bird -> y <= p -> y)
      return 0;
    if ((Bird -> x == p -> x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y)
      return 0;
    if (Bird -> x == p -> x && Bird -> y > p -> y + p -> l_blank)
      return 0;
    if ((Bird -> x == p -> x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y +
      p -> l_blank)
      return 0;
    p = p -> next;
  }
  return 1;
}
void Prtfirst() {
  printf("══════════════════════════════════════\n");
  printf(" \n");
  printf(" \n");
  printf("  Flappy Bird\n");
  printf(" 设计\n");
  printf(" 设计日期:2023.04\n");
  printf(" 祝您游戏愉快\n");
  printf(" 游戏说明:\n");
  printf(" ■■ 1-按上箭头使鸟起飞\n");
  printf(" ■■ 2-等级越高,难度越大!\n");
  printf(" ■■ 3-不要让小鸟碰到柱子\n");
  printf("\n");
  printf(" ■■ 鸟的形态:Ю \n");
  printf("\n");
  printf(" ■■ 我们真的尽力啦,不喜勿喷\n");
  printf(" ■■\n");
  printf(" ■■\n");
  printf(" ■■ 【小鸟自由的飞翔叭】\n");
  printf(" ■■ \n");
  printf(" ■■ 进阶形态:Ф \n");
  printf(" ■■ ■■\n");
  printf(" ■■ ■■\n");
  printf(" ■■ ■■\n");
  printf(" ■■ ■■\n");
  printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
  system("pause");
  Position(1, 1);
  int i = 0;
  while (i++ < 40 * 25)
    PR_Blank;
}
void main() {

  int i = 0;
  Bird = (Birds * ) malloc(sizeof(Birds));
  Bg1 = (Bg * ) malloc(sizeof(Bg));
  Prtfirst();
  PrtBg();
  CreatBg();
  InsertBg(Bg1);
  InsertBg(Bg1);
  InsertBg(Bg1);
  CreatBird();
  while (1) {
    if (!CheckYN(Bg1))
      break;
    Check_Bg(Bg1);
    Prt_Bg(Bg1);
    PrtBird();
    Loop_Bg(Bg1);
    Bird -> y = Bird -> y + 1;
    if (GetAsyncKeyState(VK_UP)) {
      Position(Bird -> x, Bird -> y - 1);
      PR_Blank;
      Bird -> y = Bird -> y - 4;
    }
    while (i++ < 500); {
      Sleep(100);
    }
    i = 0;
  }
  Position(38, 10);
  printf("You Lost!");
  Position(1, 25);
  system("pause");
}

这是一段用C语言写的Flappy Bird游戏代码。这个游戏由小鸟上下飞,躲避出现在屏幕中央的柱子,随着游戏分数的增加,难度也会逐渐增加。
定义了Bird和Bg两个结构体,Bird代表小鸟,Bg代表屏幕中央的柱子。
使用了Windows.h库中的函数来设置输出光标的位置,从而可以在控制台中输出图形。
使用了循环和条件判断语句来实现游戏的动态效果,例如小鸟的上升和下降、柱子的移动等等。
使用了时间函数和随机数函数来控制游戏中柱子的生成位置和展开程度。
在游戏的主函数中通过调用各个功能函数,实现了游戏界面的绘制、小鸟和柱子的移动、分数计算、等级增加以及游戏结束等功能。

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/7622948
  • 这篇博客你也可以参考下:利用CodeBlocks创建C语言项目
  • 除此之外, 这篇博客: CodeBlocks下载、安装与编写C语言中的 三、使用 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    1. 打开软件,会弹出一个文件关联框,点击OK
      在这里插入图片描述

    2. 因为更改了默认安装位置,这儿就需要设置一下编译器位置,点击顶部settings–>Compiler
      在这里插入图片描述

    3. 打开的Compiler settings框里,
      右侧上边选择Toolchain executables,下边Compiler’s installation directory栏选择CodeBlocks安装位置下的MinGW文件夹,然后点击OK即可。

    在这里插入图片描述

    1. 在CodeBlocks里编写C语言,需要先建项目,点击软件界面中部的Creat a new project在这里插入图片描述
      或点击软件右上角的File,弹出列表里选择New,扩展框里选择点击Project…在这里插入图片描述

    2. 打开的New from template里选择Console application,点击右上角的Go
      在这里插入图片描述

    3. 弹出框点击Next
      在这里插入图片描述
      下个框里选择C,因为要写C语言,点击Next

    在这里插入图片描述

    1. 给项目起名,选择好存放位置后,点击Next
      在这里插入图片描述

    2. 这个框里不用管,点击Finish,就建好了项目。
      在这里插入图片描述

    3. 软件顶部的那个小齿轮就是编译按钮,点击后就进行了编译,编译后可以在底部看到,error和warning都为0,没有错误后,
      在这里插入图片描述
      点击顶部的小绿三角符号就是运行。

    在这里插入图片描述

    1. 运行时会弹出控制台显示。
      在这里插入图片描述
  • 您还可以看一下 张颜源老师的2020新版C语言程序设计零基础入门小白自学编程课程中的 Codeblocks编辑器的安装使用小节, 巩固相关知识点