栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

原创的C语言控制台小游戏

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

原创的C语言控制台小游戏

最开始左上色块被感染,通过切换颜色,不断感染同色色块。亮点是可以切换图案,设置方块个数和最大限制次数。整体还是比较满意,希望大神指教。

#include 
#include 
#include 
#include 
#include 
 
int DIFFICULT=44;
int count=0 ;
int TYPE_SHAPE=2 ;
int flag=7 ;
int LINE=12;
 
struct MyStruct
{
  int shape ;
  int color ;
  int infect ;
};
 
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor)
{
  HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}
 
void WelcomeScr()
{
  int i;
  printf("nnntt");
  printf("●程序初始化中〉");
  for(i=0; i<=100; i++)
  {
    SetColor(i%6+8,0);
    printf("%3d",i);
    SetColor(15,0);
    printf(" %%");
    SetColor(i%6+8,0);
    printf(" Written by Oliver!");
    Sleep(20);
    printf("bbbbbbbbbbbbbbbbbbbbbbbb");
  }
  printf("a");
  Sleep(1000);
  system("cls");
  printf("nnntt");
  SetColor(15,0);
  printf("●请输入方块行数 〉 (最好不超过21行)");
  printf("bbbbbbbbbbbbbbbbbbbb");
  scanf("%d",&LINE);
  printf("nnntt");
  printf("●请输入最大次数 〉");
  scanf("%d",&DIFFICULT);
  system("cls");
}
 
void Show()
{
  int i ;
  SetColor(15,0);
  printf("n ※ 操作次数: %-2d / %d  (共%3d个色块)n",count,DIFFICULT,LINE*LINE);
  printf("n ※ 操作方法: ");
  for(i=1; i<7; i++)
  {
    SetColor(15,0);
    printf("%d.",i);
    SetColor(i+8,0);
    printf("%c ",TYPE_SHAPE);
  }
  SetColor(15,0);
  printf("7.");
  SetColor(9,0);
  printf("重");
  SetColor(10,0);
  printf("新");
  SetColor(11,0);
  printf("生");
  SetColor(12,0);
  printf("成 ");
  SetColor(15,0);
  printf("0.");
  SetColor(14,0);
  printf("改");
  SetColor(13,0);
  printf("变");
  SetColor(12,0);
  printf("图");
  SetColor(11,0);
  printf("案 ");
  SetColor(15,0);
  printf("nn ※ 请按下 0 ~ 7 键位> ");
}
 
int Choose()
{
  int choose ;
  fflush(stdin);
  scanf("%d",&choose);
  switch(choose)
  {
  case 0 :
    TYPE_SHAPE++;
    if(TYPE_SHAPE==7)
    {
      TYPE_SHAPE=1 ;
    }
    return 0 ;
  case 1 :
    return 1 ;
  case 2 :
    return 2 ;
  case 3 :
    return 3 ;
  case 4 :
    return 4 ;
  case 5 :
    return 5 ;
  case 6 :
    return 6 ;
  case 7 :
    return 7 ;
  default :
    printf("ntta● 输入无效,请重新输入!");
    Sleep(1000);
    return 0 ;
  }
}
 
void main()
{
  int i,j ;
  int num=0 ;
  char ch ;
  int cc ;
  int jj;
  struct MyStruct array[41][41];
  system("title 感染方块 Oliver's QQ 564404096");
  srand((time(NULL)%100)*rand());
  WelcomeScr();
loop :
  for(i=0; i0; i--)
    {
      for(j=LINE-1; j>0; j--)
      {
 if(array[i][j].color==array[i-1][j].color&&array[i][j].infect==1&&array[i-1][j].color!=1)
 {
   array[i-1][j].infect=1 ;
 }
 if(array[i][j].color==array[i][j-1].color&&array[i][j].infect==1&&array[i][j-1].color!=1)
 {
   array[i][j-1].infect=1 ;
 }
      }
    }
    cc=1 ;
    for(i=0; i");
    fflush(stdin);
    if((ch=getch())=='Y'||ch=='y')
    {
      system("cls");
      flag=7 ;
      goto loop ;
    }
    else if(ch=='n'||ch=='N')
    {
      system("cls");
      printf("nttt● 谢 谢 您 的 使 用 !nnttt● 作 者: Olivernnttt● Q Q: 564404096nnttt● 代 码 原 创,版 权 所 有 ●");
      Sleep(5000);
      exit(1);
    }
    else
    {
      printf("nnttta● 输入错误重新输入 >");
      Sleep(1000);
      system("cls");
      goto loop2 ;
    }
  }
  else if(count>DIFFICULT)
  {
    system("cls");
    printf("nnnnttta● 很遗憾,您闯关失败!n");
    goto loop2 ;
  }
  else
    ;
  flag=Choose();
  if(flag!=0)
  {
    array[0][0].color=flag ;
    if(flag!=7)
    {
      count++;
    }
    for(i=0; i

演示图:

以上即是本文所述的全部内容了,希望大家能够喜欢,能够对大家学习C有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/65202.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号