C语言可以写手机游戏吗?

c语言可以编译手机游戏。你可以叫他去死,不过我这里有蛇的代码,你可以看看(肯定是用TC编的)

# include & ltstdlib.h & gt

# include & ltgraphics.h & gt

# include & ltbios.h & gt

# include & ltdos.h & gt

# include & ltconio.h & gt

#定义输入7181

#定义ESC 283

#向上定义18432

#向下定义20480

#定义左侧19200

#定义权限19712

#ifdef __cplusplus

#define __CPPARGS...

#否则

#define __CPPARGS

#endif

void中断(* old handler)(_ _ CPPARGS);

void中断new handler(_ _ CPP args);

void SetTimer(void interrupt(* int proc)(_ _ CPPARGS));

void kill timer(void);

void Initgra(void);

void the first block(void);

void draw map(void);

void Initsnake(void);

void init food(void);

void Snake _ Headmv(void);

void标志(int,int,int,int);

void game over(void);

void Snake _ body mv(void);

void Snake _ body add(void);

void PrntScore(void);

void定时器(void);

void Win(无效);

void TheSecondBlock(void);

作废食物(void);

void Dsnkorfd(int,int,int);

无效延迟(int);

结构蛇

{ int x;int y;int颜色;} Snk[12];

结构食品

{ int x;int y;int颜色;} Fd

int flag1=1,flag2=0,flag3=0,flag4=0,flag5=0,flag6=0,

checkx,checky,num,key=0,Times,Score,Hscore,Snkspeed,TimerCounter,TureorFalse

char Sco[2],Time[6];

void main()

{ init gra();

SetTimer(new handler);

TheFirstBlock();

while(1)

{ draw map();

snake _ Headmv();

game over();

snake _ body mv();

snake _ body add();

PrntScore();

timer();

win();

if(key==ESC)

打破;

if(key==Enter)

{ clear device();

TheFirstBlock();

}

TheSecondBlock();

食物();

延迟(snk speed);

}

closegraph();

kill timer();

}

void中断newhandler(__CPPARGS)

{

timer counter++;

old handler();

}

void SetTimer(void interrupt(* int proc)(_ _ CPPARGS))

{

old handler = get vect(0x 1c);

disable();

setvect(0x1c,int proc);

enable();

}

void KillTimer()

{

disable();

setvect(0x1c,old handler);

enable();

}

void Initgra()

{int gd=DETECT,GM;

init graph(& amp;gd,& ampgm," d:\ \ TC ");

}

void第一块()

{ set color(11);

settextstyle(0,0,4);

outtextxy(100,220,“第一块”);

loop:key = BIOS key(0);

if(key==Enter)

{ clear device();

init snake();

init food();

得分= 0;

hs core = 1;

snk speed = 10;

num = 2;

次数= 0;

key = 0;

TureorFalse = 1;

timer counter = 0;

time[0]= ' 0 ';time[1]= ' 0 ';time[2]= ':';time[3]= ' 1 ';time[4]= ' 0 ';time[5]= ' \ 0 ';

}

else if(key = = ESC)clear device();

否则转到循环;

}

void DrawMap()

{line(10,10,470,10);

行(470,10,470,470);

线(470,470,10,470);

行(10,470,10,10);

线(480,20,620,20);

线(620,20,620,460);

线(620,460,480,460);

线(480,460,480,20);

}

void Initsnake()

{ randomize();

num = 2;

Snk[0]。x =随机(440);

Snk[0]。x=Snk[0]。x-Snk[0]。x % 20+50;

Snk[0]。y =随机(440);

Snk[0]。y=Snk[0]。y-Snk[0]。y % 20+50;

Snk[0]。颜色= 4;

Snk[1]。x=Snk[0]。x;

Snk[1]。y=Snk[0]。y+20;

Snk[1]。颜色= 4;

}

void Initfood()

{ randomize();

FD . x = random(440);

FD . x = FD . x-FD . x % 20+30;

FD . y = random(440);

FD . y = FD . y-FD . y % 20+30;

FD . color = random(14)+1;

}

void Snake_Headmv()

{if(bioskey(1))

{ key = BIOS key(0);

开关(钥匙)

{case UP:Flag(1,0,0,0);打破;

case DOWN:Flag(0,1,0,0);打破;

case LEFT:Flag(0,0,1,0);打破;

case RIGHT:Flag(0,0,0,1);打破;

默认:break

}

}

if(flag1)

{checkx=Snk[0]。x;

checky=Snk[0]。y;

Dsnkorfd(Snk[0])。x,Snk[0]。y,0);

Snk[0]。y-= 20;

Dsnkorfd(Snk[0])。x,Snk[0]。y,Snk[0]。颜色);

}

if(标志2)

{checkx=Snk[0]。x;

checky=Snk[0]。y;

Dsnkorfd(Snk[0])。x,Snk[0]。y,0);

Snk[0]。y+= 20;

Dsnkorfd(Snk[0])。x,Snk[0]。y,Snk[0]。颜色);

}

if(标志3)

{checkx=Snk[0]。x;

checky=Snk[0]。y;

Dsnkorfd(Snk[0])。x,Snk[0]。y,0);

Snk[0]。x-= 20;

Dsnkorfd(Snk[0])。x,Snk[0]。y,Snk[0]。颜色);

}

if(标志4)

{checkx=Snk[0]。x;

checky=Snk[0]。y;

Dsnkorfd(Snk[0])。x,Snk[0]。y,0);

Snk[0]。x+= 20;

Dsnkorfd(Snk[0])。x,Snk[0]。y,Snk[0]。颜色);

}

}

void标志(int a,int b,int c,int d)

{ flag 1 = a;flag 2 = b;flag 3 = c;flag 4 = d;}

void GameOver()

{ int I;

if(Snk[0])。x & lt20||Snk[0]。x & gt460||Snk[0]。y & lt20||Snk[0]。y & gt460)

{ clear device();

set color(11);

settextstyle(0,0,4);

outtextxy(160,220,“游戏结束”);

loop 1:key = BIOS key(0);

if(key==Enter)

{ clear device();

TheFirstBlock();

}

其他

if(key==ESC)

clear device();

其他

goto loop 1;

}

for(I = 3;我& ltnumi++)

{if(Snk[0])。x==Snk[i]。x & amp& ampSnk[0]。y==Snk[i]。y)

{ clear device();

set color(11);

settextstyle(0,0,4);

outtextxy(160,220,“游戏结束”);

loop 2:key = BIOS key(0);

if(key==Enter)

{ clear device();

TheFirstBlock();

}

其他

if(key==ESC)

clear device();

否则转到loop2

}

}

}

void Snake_Bodymv()

{int i,s,t;

for(I = 1;我& ltnumi++)

{Dsnkorfd(checkx,checky,Snk[i])。颜色);

Dsnkorfd(Snk[i].x,Snk[i]。y,0);

s=Snk[i]。x;

t=Snk[i]。y;

Snk[i]。x = checkx

Snk[i]。y = checky

checkx = s;

checky = t;

}

}

无效食物()

{if(flag5)

{ randomize();

FD . x = random(440);

FD . x = FD . x-FD . x % 20+30;

FD . y = random(440);

FD . y = FD . y-FD . y % 20+30;

FD . color = random(14)+1;

flag 5 = 0;

}

Dsnkorfd(Fd.x,Fd.y,FD . color);

}

void Snake_Bodyadd()

{if(Snk[0])。x = = Fd.x & amp& ampSnk[0]。y==Fd.y)

{if(Snk[num-1]。x & gtSnk[num-2]。x)

{ num++;

snk[编号-1]。x=Snk[num-2]。x+20;

snk[编号-1]。y=Snk[num-2]。y;

snk[编号-1]。color = Fd.color

}

其他

if(Snk[num-1]。x & ltSnk[num-2]。x)

{ num++;

snk[编号-1]。x=Snk[num-2]。x-20;

snk[编号-1]。y=Snk[num-2]。y;

snk[编号-1]。color = Fd.color

}

其他

if(Snk[num-1]。y & gtSnk[num-2]。y)

{ num++;

snk[编号-1]。x=Snk[num-2]。x;

snk[编号-1]。y=Snk[num-2]。y+20;

snk[编号-1]。color = Fd.color

}

其他

if(Snk[num-1]。y & ltSnk[num-2]。y)

{ num++;

snk[编号-1]。x=Snk[num-2]。x;

snk[编号-1]。y=Snk[num-2]。y-20;

snk[编号-1]。color = Fd.color

}

flag 5 = 1;

得分++;

}

}

void PrntScore()

{if(Hscore!=分数)

{ set color(11);

settextstyle(0,0,3);

outtextxy(490,100,“分数”);

set color(2);

setfillstyle(1,0);

矩形(520,140,580,180);

漫填(530,145,2);

Sco[0]=(char)(分数+48);

SCO[1]= ' \ 0 ';

Hscore =分数;

set color(4);

settextstyle(0,0,3);

outtextxy(540,150,Sco);

}

}

无效计时器()

{ if(timer counter & gt;18)

{ Time[4]=(char)(Time[4]-1);

if(Time[4]& lt;'0')

{ Time[4]= ' 9 ';

Time[3]=(char)(Time[3]-1);

}

if(Time[3]& lt;'0')

{ Time[3]= ' 5 ';

Time[1]=(char)(Time[1]-1);

}

if(TureorFalse)

{ set color(11);

settextstyle(0,0,3);

outtextxy(490,240,“定时器”);

set color(2);

setfillstyle(1,0);

矩形(490,280,610,320);

洪水填土(530,300,2);

set color(11);

settextstyle(0,0,3);

outtextxy(495,290,时间);

TureorFalse = 0;

}

if(Time[1]= ' 0 ' & amp;& amptime[3]= = ' 0 ' & amp;& amp时间[4]=='0 ')

{ set color(11);

settextstyle(0,0,4);

outtextxy(160,220,“游戏结束”);

loop:key = BIOS key(0);

if(key==Enter)

{ clear device();

TheFirstBlock();

}

else if(key = = ESC)clear device();

否则转到循环;

}

timer counter = 0;

TureorFalse = 1;

}

}

void Win()

{if(分数==3)

times++;

如果(次数==2)

{ clear device();

set color(11);

settextstyle(0,0,4);

outtextxy(160,220,“你赢了”);

loop:key = BIOS key(0);

if(key==Enter)

{ clear device();

TheFirstBlock();

key = 0;

}

else if(key = = ESC)clear device();

否则转到循环;

}

}

使第二个块无效()

{if(分数==3)

{ clear device();

set color(11);

settextstyle(0,0,4);

outtextxy(100,220,“第二块”);

loop:key = BIOS key(0);

if(key==Enter)

{ clear device();

init snake();

init food();

得分= 0;

hs core = 1;

snk speed = 8;

num = 2;

key = 0;

}

else if(key = = ESC)clear device();

否则转到循环;

}

}

void Dsnkorfd(int x,int y,int color)

{setcolor(颜色);

setfillstyle(1,颜色);

圆(x,y,10);

floodfill(x,y,颜色);

}

无效延迟(整数倍)

{ int I;

for(I = 1;我& lt= timesi++)

延时(15000);

}