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

2021-10-20

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

2021-10-20

C语言安卓编译器 实现emoji游戏-----坦克大战

/至少需要#include “stdio.h” #include “string” "#include "conio.h"所对应的函数库/
/这次代码为500行/

#include "stdio.h"
#include "string.h"
#include "conio.h"
#define zds 50000
#define drs 100
#define ts 15
char *a[70][62];
int ii=8,i,jj,tt=1,j,d=0,c,kz,su,jzs;
enum kk { ss=1, zz=2, xx=3, yy=4 };
struct tank{  int x;  int y;  int f;  int p;	};
struct zd {          int x;          int y;          int f;          int p;};
struct dr {  int x;  int y;  int f;  int p;};
struct tank t;struct dr drr[drs];
struct zd z[drs+1][zds];
void inittank() {  t.x = 30;  t.y= 36;  t.p= 1;  t.f = ss;}
void win(struct tank bb) {    if (ii<0  && su== 0) {    tt = 0;    for(i=0;i<70;i++)    for(j=0;j<62;j++)      a[i][j] = "  ";    for (i = 0; i < 70; i++) {      for (j = 0; j < 62; j++)        printf("%s", a[i][j]);      printf("n");    }    gotoxy(62/ 2, 70 / 2);    printf("33[0;35m你赢了33[m");    }    ii--;  if ((strcmp(a[bb.y+1][bb.x],"")==0 ||      strcmp(a[bb.y-1][bb.x],"")==0 ||     strcmp(a[bb.y][bb.x-1],"")==0 ||     strcmp(a[bb.y][bb.x+1],"")==0 ||      strcmp(a[bb.y+1][bb.x+1],"")==0 ||       strcmp(a[bb.y+1][bb.x-1],"")==0) && bb.f==ss)    jj = 1;      if ((strcmp(a[bb.y+1][bb.x],"")==0 ||      strcmp(a[bb.y-1][bb.x],"")==0 ||     strcmp(a[bb.y][bb.x-1],"")==0 ||     strcmp(a[bb.y][bb.x+1],"")==0 ||      strcmp(a[bb.y+1][bb.x+1],"")==0 ||       strcmp(a[bb.y-1][bb.x+1],"")==0) && bb.f==zz)        jj = 1;          if ((strcmp(a[bb.y+1][bb.x],"")==0 ||      strcmp(a[bb.y-1][bb.x],"")==0 ||     strcmp(a[bb.y][bb.x-1],"")==0 ||     strcmp(a[bb.y][bb.x+1],"")==0 ||      strcmp(a[bb.y-1][bb.x-1],"")==0 ||       strcmp(a[bb.y-1][bb.x+1],"")==0) && bb.f==xx)            jj = 1;              if ((strcmp(a[bb.y+1][bb.x],"")==0 ||      strcmp(a[bb.y-1][bb.x],"")==0 ||     strcmp(a[bb.y][bb.x-1],"")==0 ||     strcmp(a[bb.y][bb.x+1],"")==0 ||      strcmp(a[bb.y-1][bb.x-1],"")==0 ||       strcmp(a[bb.y+1][bb.x-1],"")==0) && bb.f==yy)                jj = 1;     if(jj==1)      {    tt = 0;    for(i=0;i<70;i++)    for(j=0;j<62;j++)      a[i][j] = "  ";    for (i = 0; i < 70; i++) {      for (j = 0; j < 62; j++) printf("%s", a[i][j]);      printf("n");    }    gotoxy(62/ 2, 70/ 2);    printf("33[1;31m你输了33[m");  }}
struct dr jz(struct dr pp) {if(pp.f==ss)  {  if (pp.p == 1 && (strcmp(a[pp.y - 1][pp.x], "") == 0 ||         strcmp(a[pp.y][pp.x + 1], "") == 0 ||         strcmp(a[pp.y][pp.x - 1], "") == 0 ||         strcmp(a[pp.y + 1][pp.x], "") == 0 ||         strcmp(a[pp.y + 1][pp.x + 1], "") == 0 ||         strcmp(a[pp.y + 1][pp.x - 1], "") == 0)) {    pp.p = 0;    jzs++;    }}   if(pp.f==zz)    {     if (pp.p == 1 && (strcmp(a[pp.y][pp.x - 1], "") == 0 ||          strcmp(a[pp.y][pp.x + 1], "") == 0 ||          strcmp(a[pp.y + 1][pp.x], "") == 0 ||          strcmp(a[pp.y - 1][pp.x], "") == 0 ||          strcmp(a[pp.y + 1][pp.x + 1], "") == 0 ||          strcmp(a[pp.y - 1][pp.x + 1], "") == 0)) {       pp.p = 0;       jzs++;     }   }      if(pp.f==xx)       {        if (pp.p == 1 && (strcmp(a[pp.y][pp.x - 1], "") == 0 ||             strcmp(a[pp.y][pp.x + 1], "") == 0 ||             strcmp(a[pp.y + 1][pp.x], "") == 0 ||             strcmp(a[pp.y - 1][pp.x], "") == 0 ||             strcmp(a[pp.y - 1][pp.x + 1], "") == 0 ||             strcmp(a[pp.y - 1][pp.x - 1], "") == 0) ) {          pp.p = 0;          jzs++;        }      }      if (pp.f == yy) {        if (pp.p == 1 && (strcmp(a[pp.y][pp.x - 1], "") == 0 ||             strcmp(a[pp.y][pp.x + 1], "") == 0 ||             strcmp(a[pp.y + 1][pp.x], "") == 0 ||             strcmp(a[pp.y - 1][pp.x], "") == 0 ||             strcmp(a[pp.y + 1][pp.x - 1], "") == 0 ||             strcmp(a[pp.y - 1][pp.x - 1], "") == 0)) {          pp.p = 0;          jzs++;        }      }  return pp;}
struct dr movedrr(struct dr ii){ if (ii.f == ss) {    if (ii.y > 2) ii.y -= 1;  }  if (ii.f == zz){  if( ii.x>2)     ii.x -= 1;  }  if (ii.f ==xx){  if( ii.y<67)     ii.y += 1;  }  if (ii.f == yy) {    if (ii.x < 58)      ii.x += 1;  }  return ii;}
struct dr initdr(struct dr pp) {  pp.x =rand()%54+6;  pp.y = rand()%57+2;  pp.p = 1;  pp.f = rand()%4+1;  return pp;}
struct zd initzd(struct zd ii) {  if (t.f == ss) {    ii.x = t.x;   ii.y = t.y-2;    ii.f=ss;    ii.p= 1;  }  if (t.f == zz) {    ii.x = t.x-2;    ii.y = t.y;    ii.f=zz;    ii.p = 1;  }  if (t.f == xx) {    ii.x = t.x;    ii.y = t.y+2;    ii.f =xx;    ii.p = 1;  }  if (t.f == yy) {    ii.x = t.x+2;    ii.y = t.y;    ii.f = yy;    ii.p = 1;  }  return ii;}
struct zd initdrzd(int o,struct zd ii) {  if (drr[o].f == ss) {    ii.x = drr[o].x;   ii.y = drr[o].y-2;    ii.f=ss;    ii.p= 1;  }  if (drr[o].f == zz) {    ii.x = drr[o].x-2;    ii.y = drr[o].y;    ii.f=zz;    ii.p = 1;  }  if (drr[o].f == xx) {    ii.x = drr[o].x;    ii.y = drr[o].y+2;    ii.f =xx;    ii.p = 1;  }  if (drr[o].f == yy) {    ii.x = drr[o].x + 2;    ii.y = drr[o].y;    ii.f = yy;    ii.p = 1;  }  return ii;}
struct zd movedrzd(struct zd ii) {  if (ii.f == ss) {    if (ii.y > 1)      ii.y -= 1;    else      ii.p = 0;  }  if (ii.f == zz){  if( ii.x>1)     ii.x -= 1;  else    ii.p = 0;  }  if (ii.f ==xx){  if( ii.y<68)     ii.y += 1;  else    ii.p = 0;  }  if (ii.f == yy) {    if (ii.x < 59)      ii.x += 1;  else
      ii.p = 0;  }  return ii;}
      struct zd movezd(struct zd ii) {  if (ii.f == ss) {    if (ii.y > 1)       ii.y -= 1;    else      ii.p = 0;  }  if (ii.f == zz){  if( ii.x>1)     ii.x -= 1;  else    ii.p = 0;  }  if (ii.f == xx) {    if (ii.y < 68)      ii.y += 1;    else      ii.p = 0;  }  if (ii.f == yy) {  if( ii.x<59)    ii.x += 1;  else    ii.p = 0;  }  return ii;}
void movet(){  switch (getch()) {  case '.':    if (c < zds) {      z[drs][c] = initzd(z[drs][c]);      c++;    }    break;  case '4':    if (t.f == zz) {      if (t.x - 3 > 2)        t.x -= 3;      else if (t.x > 2)        t.x -= 1;    }    else      t.f = zz;    break;  case '6':    if (t.f == yy) {      if (t.x + 3 < 60)        t.x += 3;      else if (t.x < 58)        t.x += 1;    }    else       t.f = yy;    break;  case '2':    if (t.f == ss) {      if (t.y - 2 > 2) t.y -= 2;    else  if (t.y > 2)       t.y -= 1;    } else      t.f = ss;    break;  case '8':    if (t.f == xx) {      if (t.y + 2 < 67) t.y += 2;    else  if (t.y < 67) t.y += 1;    } else      t.f = xx;    break;  }}
void play() {for(i=0;i<70;i++)  {for(j=0;j<61;j++)  printf("%s",a[i][j]);    printf("n");  }  printf("敌人总数: %d || 击中敌人数: %d", drs, jzs);	}
void tanks()  {          a[t.y][t.x] = "";          a[t.y][t.x+1] = "";          a[t.y][t.x-1] = "";          a[t.y+1][t.x] = "";          a[t.y+1][t.x+1] = "";          a[t.y+1][t.x-1] = "";          a[t.y - 1][t.x] = ""; 	} 
void tankz() {          a[t.y][t.x] = "";          a[t.y][t.x+1] = "";          a[t.y][t.x-1] = "";          a[t.y+1][t.x] = "";          a[t.y+1][t.x+1] = "";          a[t.y-1][t.x+1] = "";          a[t.y -1][t.x] = "";        }        
void tankx() {          a[t.y][t.x] = "";          a[t.y][t.x+1] = "";          a[t.y][t.x-1] = "";          a[t.y+1][t.x] = "";          a[t.y-1][t.x+1] = "";          a[t.y-1][t.x-1] = "";          a[t.y - 1][t.x] = "";        }        
void tanky() {          a[t.y][t.x] = "";          a[t.y][t.x+1] = "";          a[t.y][t.x-1] = "";          a[t.y+1][t.x] = "";          a[t.y+1][t.x-1] = "";          a[t.y-1][t.x-1] = "";          a[t.y - 1][t.x] = "";        }        
struct dr tanks1(struct dr pp)  {          a[pp.y][pp.x] = "";          a[pp.y][pp.x+1] = "";          a[pp.y][pp.x-1] = "";          a[pp.y+1][pp.x] = "";          a[pp.y+1][pp.x+1] = "";          a[pp.y+1][pp.x-1] = "";          a[pp.y - 1][pp.x] = "";          return pp; 	} 
struct dr  tankz1(struct dr pp) {          a[pp.y][pp.x] = "";          a[pp.y][pp.x+1] = "";          a[pp.y][pp.x-1] = "";          a[pp.y+1][pp.x] = "";          a[pp.y+1][pp.x+1] = "";          a[pp.y-1][pp.x+1] = "";          a[pp.y - 1][pp.x] = "";          return pp;        }        
struct dr tankx1(struct dr pp) {           a[pp.y][pp.x] = "";          a[pp.y][pp.x+1] = "";          a[pp.y][pp.x-1] = "";          a[pp.y+1][pp.x] = "";          a[pp.y-1][pp.x+1] = "";          a[pp.y-1][pp.x-1] = "";          a[pp.y - 1][pp.x] = "";          return pp;        }        
struct dr tanky1(struct dr pp) {          a[pp.y][pp.x] = "";          a[pp.y][pp.x+1] = "";          a[pp.y][pp.x-1] = "";          a[pp.y+1][pp.x] = "";          a[pp.y+1][pp.x-1] = "";          a[pp.y-1][pp.x-1] = "";          a[pp.y - 1][pp.x] = "";          return pp;        }
void graphics() {for(i=0;i<70;i++)  for(j=0;j<62;j++)  a[i][j]="  ";  for(i=0;i<70;i++)    for (j = 0; j < 61; j++) {      a[0][j] = "";      a[69][j] = "";      a[i][0] = "";      a[i][60] = "";    }  if (t.f == ss) tanks();  if (t.f == zz) tankz();  if (t.f == xx) tankx();  if (t.f == yy) tanky();  for (i = 0; i  

效果图是这样的

游戏比较难 移动比较别扭 可能是手机运行原因
运行玩一下吧

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

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

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