B怎么到C才可以玩到Char 2C坦克

char 与 unsigned char的本质区别
& & & 在C中,默认的基础数据类型均为signed,现在我们以char为例,说明(signed) char与unsigned char之间的区别。
& & & 首先在内存中,char与unsigned char没有什么不同,都是一个字节,唯一的区别是,char的最高位为符号位,因此char能表示-127~127,unsigned char没有符号位,因此能表示0~255,这个好理解,8个bit,最多256种情况,因此无论如何都能表示256个数字。
& & & 在实际使用过程种有什么区别呢?主要是符号位,但是在普通的赋值,读写文件和网络字节流都没什么区别,反正就是一个字节,不管最高位是什么,最终的读取结果都一样,只是你怎么理解最高位而已,在屏幕上面的显示可能不一样。
& & & &二者的最大区别是:但是我们却发现在表示byte时,都用unsigned char,这是为什么呢?首先我们通常意义上理解,byte没有什么符号位之说,更重要的是如果将byte的值赋给int,long等数据类型时,系统会做一些额外的工作。如果是char,那么系统认为最高位是符号位,而int可能是16或者32位,那么会对最高位进行扩展(注意,赋给unsigned int也会扩展)而如果是unsigned char,那么不会扩展。最高位若为0时,二者没有区别,若为1时,则有区别了。同理可以推导到其它的类型,比如short, unsigned short,等等。
& & & &具体可以通过下面的小例子看看其区别
  include &stdio.h&
  void f(unsigned char v)  {    char c =    unsigned char uc =    unsigned int a = c, b =    int i = c, j =    printf("----------------\n");    printf("%%c: %c, %c\n", c, uc);    printf("%%X: %X, %X\n", c, uc);    printf("%%u: %u, %u\n", a, b);    printf("%%d: %d, %d\n", i, j);  }  
  int main(int argc, char *argv[])  {    f(0x80);    f(0x7F);    return 0;  }
   &结果输出如下:
   &结果分析:
  对于(signed)char来说,0x80用二进制表示为,当它作为char赋值给unsigned int或 int 时,系统认为最高位是符号位,会对最高位进行扩展。而0x7F用二进制表示为,最高位为0,不会扩展。
  对于unsigned char来说,不管最高位是0,还是1,都不会做扩展。
阅读(...) 评论()欢迎访问C语言网
比赛栏每月有奖月赛!举办比赛联系QQ:问题反馈、粉丝交流
蓝桥杯训练群:
申请群时请备注排名里的昵称C语言研究中心 为您提供有图、有料、解渴的C语言专题! 欢迎讨论!
好久没给大家看有意思的C语言实现的代码了,今天给大家分享一个C语言实现坦克大战的游戏源码,依旧是纯C语言,点c文件,但是是在TC的环境下,运行效果截图如下:
上下左右控制方向,空格为发射炮弹,还带声音哦!
小编亲自没有问题,大家可以自行上机实验,编译器下载见
下面上代码!
/* time: */
/* edit: */
#include &graphics.h&
#include &stdlib.h&
#include &dos.h&
#include &conio.h&
#include &bios.h&
#define KEY_ESC 0x01
#define KEY_SPACE 0x39
#define KEY_UP 0x48
#define KEY_LEFT 0x4b
#define KEY_RIGHT 0x4d
#define KEY_DOWN 0x50
int map[20][20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,2,2,0,0,2,2,2,2,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,2,0,0,2,0,1,1,1,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,
1,0,1,1,1,1,3,3,3,3,0,0,0,0,0,0,0,2,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,0,1,
1,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,3,3,3,1,1,1,1,1,1,1,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,2,2,2,0,0,0,2,2,0,0,0,1,
1,0,0,0,0,0,0,8,2,5,2,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
struct play
struct f fire[5];
char key_state[128],key_pressed[128];
void Init();
void End();
void DrawMap();
void DrawWater(int x,int y);
void DrawBrick(int x,int y);
void DrawTone(int x,int y);
void DrawHome(int x,int y);
void DrawBlack(int x,int y);
void DrawPlay(int x,int y);
void DrawAmy(int x,int y,int i);
void Score();
void GamePlay();
void GameOver();
void TimeDelay(unsigned long microsec);
int GetKey(int ScanCode);
void interrupt far (*OldInt9Handler)();
void far interrupt NewInt9();
void InstallKeyboard();
void ShutDownKeyboard();
void main(void)
DrawMap();
GamePlay();
void TimeDelay(unsigned long microsec)
union REGS
r.h.ah=0x86;
r.x.cx=microsec&&16;
int86(0x15,&r,&r);
void Init()
{int gd=DETECT,
initgraph(&gd,&gm,&C:\\TC20\\BGI&);
cleardevice();
InstallKeyboard();
void End()
ShutDownKeyboard();
closegraph();
void DrawTone(int x,int y)
setfillstyle(SOLID_FILL,7);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
void DrawWater(int x,int y)
setfillstyle(SOLID_FILL,BLUE);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
void DrawBrick(int x,int y)
setfillstyle(SOLID_FILL,6);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
setcolor(15);
line(100+x*20-9,50+y*20-4,100+x*20+9,50+y*20-4);
line(100+x*20-9,50+y*20+4,100+x*20+9,50+y*20+4);
line(100+x*20-4,50+y*20-9,100+x*20-4,50+y*20+9);
line(100+x*20+4,50+y*20-9,100+x*20+4,50+y*20+9);
void DrawHome(int x,int y)
setcolor(0);
setfillstyle(SOLID_FILL,GREEN);
fillellipse(100+x*20,50+y*20,9,9);
void DrawBlack(int x,int y)
setcolor(0);
setfillstyle(SOLID_FILL,0);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
void DrawPlay(int x,int y)
setcolor(4);
circle(100+x*20,50+y*20,7);
switch(Playone.direction)
case 1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);
case 2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);
case 3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);
case 4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);
void DrawAmy(int x,int y,int i)
if(amy[i].color==12)
setcolor(12);
else if(amy[i].color==13)
setcolor(13);
setcolor(14);
circle(100+x*20,50+y*20,7);
switch(amy[i].direction)
case 1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);
case 2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);
case 3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);
case 4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);
void Score()
char s[10];
Playone.score+=10;
sprintf(s,&%d&,Playone.score);
setfillstyle(SOLID_FILL,0);
bar(550,100,640,130);
settextstyle(0,0,2);
setcolor(YELLOW);
outtextxy(550,115,s);
void DrawMap()
{int i,j,k;
for(i=0;i&20;i++)
for(j=0;j&20;j++)
if(map[i][j]==1)
DrawTone(j,i);
else if(map[i][j]==2)
DrawBrick(j,i);
else if(map[i][j]==3)
DrawWater(j,i);
else if(map[i][j]==5)
DrawHome(j,i);
else if(map[i][j]==8)
Playone.x=i;
Playone.y=j;
Playone.direction=1;
DrawPlay(j,i);
for(k=0;k&5;k++)
Playone.fire[k].direction=-1;
else if(map[i][j]==9)
amy[0].x=1;amy[0].y=1;amy[0].direction=amy[0].directiontwo=3;
amy[0].color=12;
DrawAmy(j,i,0);
for(i=1;i&5;i++)
amy[i].direction=amy[i].fire.direction=-1;
outtextxy(210,450,&Edit By &);
settextstyle(0,0,2);
setcolor(9);
outtextxy(525,80,&Score&);
setcolor(YELLOW);
outtextxy(550,115,&0&);
void far interrupt NewInt9(void)
unsigned char ScanCode,
ScanCode=inportb(0x60);
temp=inportb(0x61);
outportb(0x61,temp | 0x80);
outportb(0x61,temp & 0x7f);
if(ScanCode&0x80)
ScanCode&=0x7f;
key_state[ScanCode]=0;
key_state[ScanCode]=1;
key_pressed[ScanCode]=1;
outportb(0x20,0x20);
void InstallKeyboard(void)
for(i=0;i&128;i++)
key_state[i]=key_pressed[i]=0;
OldInt9Handler=getvect(9);
setvect(9,NewInt9);
void ShutDownKeyboard(void)
setvect(9,OldInt9Handler);
int GetKey(int ScanCode)
res=key_state[ScanCode]|key_pressed[ScanCode];
key_pressed[ScanCode]=0;
void GameOver()
setcolor(0);
setfillstyle(SOLID_FILL,0);
fillellipse(100+9*20,50+18*20,9,9);
nosound();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(150,5,&GAME OVER&);
if(GetKey(KEY_ESC))
void GamePlay()
int i,j,lose=0;
randomize();
for(i=0;i&5;i++)
if(amy[i].fire.direction&0)
putpixel(100+amy[i].fire.y*20,50+amy[i].fire.x*20,11);
for(i=0;i&=4;i++)
if(Playone.fire[i].direction&0)
putpixel(100+Playone.fire[i].y*20,50+Playone.fire[i].x*20,11);
TimeDelay(500000);
for(i=0;i&5;i++)
if(amy[i].fire.direction&0)
putpixel(100+amy[i].fire.y*20,50+amy[i].fire.x*20,0);
for(i=0;i&=4;i++)
if(Playone.fire[i].direction&0)
putpixel(100+Playone.fire[i].y*20,50+Playone.fire[i].x*20,0);
for(i=0;i&=4;i++)
if(Playone.fire[i].direction&0)
if(Playone.fire[i].direction==1)
{Playone.fire[i].x--;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==2)
{Playone.fire[i].y++;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==3)
{Playone.fire[i].x++;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==4)
{Playone.fire[i].y--;Playone.fire[i].y=Playone.fire[i].y;}
if(map[Playone.fire[i].x][Playone.fire[i].y]==1)
Playone.fire[i].direction=-1;
if(map[Playone.fire[i].x][Playone.fire[i].y]==2)
Playone.fire[i].direction=-1;
DrawBlack(Playone.fire[i].y,Playone.fire[i].x);
map[Playone.fire[i].x][Playone.fire[i].y]=0;
if(map[Playone.fire[i].x][Playone.fire[i].y]==5)
for(j=0;j&5;j++)
if(amy[j].direction&0)
if(amy[j].x==Playone.fire[i].x&&amy[j].y==Playone.fire[i].y)
Playone.fire[i].direction=-1;
DrawBlack(Playone.fire[i].y,Playone.fire[i].x);
map[Playone.fire[i].x][Playone.fire[i].y]=0;
amy[j].fire.direction=amy[j].direction=-1;
for(i=0;i&5;i++)
if(amy[i].direction&0||amy[i].fire.direction&0)
if(amy[i].fire.direction==1)
{amy[i].fire.x--;amy[i].fire.y=amy[i].fire.y;}
else if(amy[i].fire.direction==2)
{amy[i].fire.y++;amy[i].fire.x=amy[i].fire.x;}
else if(amy[i].fire.direction==3)
{amy[i].fire.x++;amy[i].fire.y=amy[i].fire.y;}
else if(amy[i].fire.direction==4)
{amy[i].fire.y--;amy[i].fire.x=amy[i].fire.x;}
if(map[amy[i].fire.x][amy[i].fire.y]==1)
amy[i].fire.direction=-1;
if(map[amy[i].fire.x][amy[i].fire.y]==2)
amy[i].fire.direction=-1;
DrawBlack(amy[i].fire.y,amy[i].fire.x);
map[amy[i].fire.x][amy[i].fire.y]=0;
if(map[amy[i].fire.x][amy[i].fire.y]==5)
if(amy[i].fire.x==Playone.x&&amy[i].fire.y==Playone.y)
for(j=0;j&5;j++)
Playone.fire[j].direction=-1;
amy[i].fire.direction=-1;
DrawBlack(amy[i].fire.y,amy[i].fire.x);
map[amy[i].fire.x][amy[i].fire.y]=0;
nosound();
for(i=0;i&5;i++)
if(amy[i].direction&0)
amy[i].directiontwo=random(4)+1;
if(amy[i].direction==1&&amy[i].directiontwo==3)
if(amy[i].direction==3&&amy[i].directiontwo==1)
if(amy[i].direction==2&&amy[i].directiontwo==4)
if(amy[i].direction==4&&amy[i].directiontwo==2)
if(amy[i].directiontwo==3&&(map[amy[i].x+1][amy[i].y]==3||map[amy[i].x+1][amy[i].y]==1||map[amy[i].x+1][amy[i].y]==2))
if(amy[i].directiontwo==1&&(map[amy[i].x-1][amy[i].y]==3||map[amy[i].x-1][amy[i].y]==1||map[amy[i].x-1][amy[i].y]==2))
if(amy[i].directiontwo==2&&(map[amy[i].x][amy[i].y+1]==3||map[amy[i].x][amy[i].y+1]==1||map[amy[i].x][amy[i].y+1]==2))
if(amy[i].directiontwo==4&&(map[amy[i].x][amy[i].y-1]==3||map[amy[i].x][amy[i].y-1]==1||map[amy[i].x][amy[i].y-1]==2))
DrawBlack(amy[i].y,amy[i].x);
amy[i].direction=amy[i].
if(amy[i].direction==1)
{amy[i].x--;amy[i].y=amy[i].y;}
if(amy[i].direction==3)
{amy[i].x++;amy[i].y=amy[i].y;}
if(amy[i].direction==2)
{amy[i].y++;amy[i].x=amy[i].x;}
if(amy[i].direction==4)
{amy[i].y--;amy[i].x=amy[i].x;}
if(amy[i].x==Playone.x&&amy[i].y==Playone.y)
if(map[amy[i].x][amy[i].y]==5)
DrawAmy(amy[i].y,amy[i].x,i);
if(amy[i].fire.direction&0)
amy[i].fireplay=random(4);
if(amy[i].fireplay==1&&amy[i].fire.direction&0)
amy[i].fire.direction=amy[i].
amy[i].fire.x=amy[i].x;
amy[i].fire.y=amy[i].y;
{GameOver();}
if(GetKey(KEY_ESC))
if(GetKey(KEY_UP))
if(Playone.direction==1&&map[Playone.x-1][Playone.y]!=1&&map[Playone.x-1][Playone.y]!=2)
if(map[Playone.x-1][Playone.y]==3)
DrawBlack(Playone.y,Playone.x);
Playone.x--;
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
DrawBlack(Playone.y,Playone.x);
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
else if(GetKey(KEY_DOWN))
if(Playone.direction==3&&map[Playone.x+1][Playone.y]!=1&&map[Playone.x+1][Playone.y]!=2)
if(map[Playone.x+1][Playone.y]==3)
DrawBlack(Playone.y,Playone.x);
Playone.x++;
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
DrawBlack(Playone.y,Playone.x);
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
if(GetKey(KEY_RIGHT))
if(Playone.direction==2&&map[Playone.x][Playone.y+1]!=1&&map[Playone.x][Playone.y+1]!=2)
if(map[Playone.x][Playone.y+1]==3)
DrawBlack(Playone.y,Playone.x);
Playone.y++;
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
DrawBlack(Playone.y,Playone.x);
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
if(GetKey(KEY_LEFT))
if(Playone.direction==4&&map[Playone.x][Playone.y-1]!=1&&map[Playone.x][Playone.y-1]!=2)
if(map[Playone.x][Playone.y-1]==3)
DrawBlack(Playone.y,Playone.x);
Playone.y--;
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
DrawBlack(Playone.y,Playone.x);
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
if(GetKey(KEY_SPACE))
for(i=0;i&5;i++)
if(Playone.fire[i].direction&0)
sound(300);
Playone.fire[i].direction=Playone.
Playone.fire[i].x=Playone.x;
Playone.fire[i].y=Playone.y;
if(map[Playone.x][Playone.y]==5)
for(i=0;i&5;i++)
if(amy[i].direction&0)
if(amy[i].x==Playone.x&&amy[i].y==Playone.y)
{GameOver();}
for(i=0;i&5;i++)
if(amy[i].direction&0)
amy[i].direction=amy[i].directiontwo=3;
amy[i].x=1;
amy[i].y=random(3);
if(amy[i].y==0)
amy[i].y=1;
else if(amy[i].y==1)
amy[i].y=9;
amy[i].y=18;
amy[i].color=random(3)+12;
DrawAmy(amy[i].y,amy[i].x,i);
代码较长,大家可以分段复制,如发现问题欢迎随时留言!
有好东西记得分享哦!
C语言网, 版权所有丨如未注明 , 均为原创丨本网站采用协议进行授权 , 转载请注明!股票/基金&
交通工具中的庞然大物:法国Char 2C超重型坦克
  法国在上世纪30年代制造的Char 2C超重型坦克仍旧是迄今为止服役的最大并且最重的坦克。不过,Char 2C基本上就是一个宣传工具。
暂无专家推荐本文
同时转发到我的微博
将自动提交到和讯看点,
请输入您的观点并提交。
请输入您的观点 168字以内
同时转发到我的微博置顶我的观点
科技精品推荐
每日要闻推荐
精彩焦点图鉴
  【免责声明】本文仅代表作者本人观点,与和讯网无关。和讯网站对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。请读者仅作参考,并请自行承担全部责任。《战地1》法军DLC新演示 Char 2C巨兽坦克体型超大
今日,《战地1》今天公布了新DLC“誓死坚守(They Shall Not Pass)”,并为我们带来了该DLC的新内容。这次更新包括新地图苏瓦松,里面加入了陆地大型载具Char 2C 坦克以及攻击型...
今日,《战地1》今天公布了新DLC“誓死坚守(They Shall Not Pass)”,并为我们带来了该DLC的新内容。这次更新包括新地图苏瓦松,里面加入了陆地大型载具Char 2C 以及攻击型坦克St Chamond等。
除此以外,我们还能在DLC里看见新加入的法军。Char 2C巨兽坦克体型巨大,最多可以承载5名玩家。虽然由于体积过大转弯困难,但是Char 2C巨兽坦克的速度十分可观。
新加入的苏瓦松地图支持动态环境,天气能从艳阳高照变成和风细雨甚至电闪雷鸣。另外DLC还添加了法军的语音台词和新的建筑物搭配,比如树屋上架上机关枪等等。
本次DLC还将对“手雷”问题进行修复。玩过《战地1》的玩家可能知道,有的玩家利用手雷攻击会造成敌人屏幕震动的原理,疯狂地向敌方投掷手雷,导致敌方玩家不能正常瞄准。在新的DLC里《战地1》将打出补丁减少手雷的补给弹药量来修复这个问题,手雷狂魔的末日恐怕已经来临。
苏瓦松地图:
视频画面:
如转载涉及版权等问题,请作者与我司联系,我司将在第一时间删除或支付稿酬。
我来说两句
正在加载,请稍后...
植物大战僵尸1
安卓平台下载
苹果平台下载}

我要回帖

更多关于 99C 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信