c语言贪吃蛇的源码,用'A''S''D''W'操作

#include
#include
#include
#include

typedefstruct snake
{
int a;
int b;
struct snake*u;
struct snake*n;
}snake,*snake1;
typedefstruct food
{
int a;
int b;
}food;
void main()
{ 
char c,c0 = 'd';
int i,j,k,n=1,t,at;
snake p,q;
snake *dd,*dd0,*dd1,*dd2;
food f;
srand()(time(NULL));
p.u = NULL;
p.n = &q;
p.a = 5;p.b = 6;q.a = 5;q.b = 5;
q.u = &p;q.n = NULL;
dd=dd2= &q;
f.a=(rand()()%15+1);
f.b=(rand()()%15+1);
while(1)
{
srand(time(NULL));
system("cls");
for(i = 0;i < 17;i ++)
{
for(j = 0; j < 17;j++)
{

if(i == 0 )
printf("▁");
else if(i == 16)
printf("▔");
else if(j == 0)
printf("▕");
else if(j == 16)
printf("▏");
else if(i == p.a && j == p.b)
printf("■");
else if(i == f.a && j == f.b)
printf("★");
else 
{
t = 0;
dd = dd2;
for(k = 0; k < n ;k++)
{ 
if(i == dd->a && j == dd->b)
{
printf("□");
t = 1;
break;
}

dd = dd->u; 
}
if(t == 0)
printf(" ");
}

}printf("\n");
}
at = 0;
dd =dd2;
for(i=0;ia && p.b == dd->b)
{
printf("game over!!\n");
exit(0);
}
dd = dd->u;
}
if(p.a == f.a && p.b == f.b)
{
dd = dd2;
at =1;
f.a = (rand()%15+1);
f.b = (rand()%15+1);
for(i=0;ia && f.b == dd->b)
{
f.a = dd2->a;
f.b = dd2->b;
break;
}
}
n++;
}
if(kbhit())
{
c = getch()();
dd = dd2;
if(c == 'w' && c0 != 's')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; iu;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.a == 1)
p.a = 15;
else
p.a = (p.a-1)%15;
}
else if(c == 's' && c0 != 'w')
{ 
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; iu;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
p.a = (p.a%15)+1;
}
else if(c == 'a' && c0 != 'd')
{ 
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; iu;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.b == 1)
p.b = 15;
else
p.b = (p.b-1)%15;
}
else if(c == 'd' && c0 != 'a')
{ 
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
 
  

  http://www.huihui.cn/share/32085516

  http://www.huihui.cn/share/32086062

  http://www.huihui.cn/share/32086460

  http://www.huihui.cn/share/32086902

  http://www.huihui.cn/share/32087540

  http://www.huihui.cn/share/32088042

  http://www.huihui.cn/share/32088540

  http://www.huihui.cn/share/32088980

  http://www.huihui.cn/share/32089946

  http://www.huihui.cn/share/32090314

  http://www.huihui.cn/share/32091338

  http://www.huihui.cn/share/32091870

  http://www.huihui.cn/share/32092320

  http://www.huihui.cn/share/32092780

  http://www.huihui.cn/share/32093232

  http://www.huihui.cn/share/32093726

  http://www.huihui.cn/share/32094168

  http://www.huihui.cn/share/32094774

  http://www.huihui.cn/share/32095230

  http://www.huihui.cn/share/32095744

  http://www.huihui.cn/share/32096204

  http://www.huihui.cn/share/32096586

  http://www.huihui.cn/share/32097012

  http://www.huihui.cn/share/32097454

  http://www.huihui.cn/share/32097908

  http://www.huihui.cn/share/32098344

  http://www.huihui.cn/share/32098902

  http://www.huihui.cn/share/32099278

  http://www.huihui.cn/share/32099690

  http://www.huihui.cn/share/32100098

  http://www.huihui.cn/share/32100502

  http://www.huihui.cn/share/32101128

  http://www.huihui.cn/share/32101556

  http://www.huihui.cn/share/32102210

  http://www.huihui.cn/share/32103274

  http://www.huihui.cn/share/32103798

  http://www.huihui.cn/share/32104280

  http://www.huihui.cn/share/32104786

  http://www.huihui.cn/share/32105234

  http://www.huihui.cn/share/32105826

  http://www.huihui.cn/share/32106354

  http://www.huihui.cn/share/32106792

  http://www.huihui.cn/share/32107316

  http://www.huihui.cn/share/32107962

  http://www.huihui.cn/share/32108410

  http://www.huihui.cn/share/32108974

  http://www.huihui.cn/share/32109544

  http://www.huihui.cn/share/32110134

  http://www.huihui.cn/share/32110740

  http://www.huihui.cn/share/32111290

  http://www.huihui.cn/share/32111862

  http://www.huihui.cn/share/32112468

  http://www.huihui.cn/share/32114722

  http://www.huihui.cn/share/32117666

  http://www.huihui.cn/share/32118256

  http://www.huihui.cn/share/32120098

  http://www.huihui.cn/share/32120644

  http://www.huihui.cn/share/32121382

  http://www.huihui.cn/share/32125100

  http://www.huihui.cn/share/32125730

  http://www.huihui.cn/share/32126162

  http://www.huihui.cn/share/32126698

  http://www.huihui.cn/share/32151652

  http://www.huihui.cn/share/32152160

  http://www.huihui.cn/share/32153714

  http://www.huihui.cn/share/32154340

  http://www.huihui.cn/share/32155058

  http://www.huihui.cn/share/32159676

  http://www.huihui.cn/share/32172238

  http://www.huihui.cn/share/32173152

  http://www.huihui.cn/share/32173782

  http://www.huihui.cn/share/32174352

  http://www.huihui.cn/share/32174920

  http://www.huihui.cn/share/32175576

  http://www.huihui.cn/share/32176140

  http://www.huihui.cn/share/32176780

  http://www.huihui.cn/share/32177318

  http://www.huihui.cn/share/32177858

  http://www.huihui.cn/share/32178394

  http://www.huihui.cn/share/32179108

  http://www.huihui.cn/share/32187636

  http://www.huihui.cn/share/32188162

  http://www.huihui.cn/share/32193002

  http://www.huihui.cn/share/32198494

  http://www.huihui.cn/share/32199012

  http://www.huihui.cn/share/32200718

  http://www.huihui.cn/share/32201590

  http://www.huihui.cn/share/32202668

  http://www.huihui.cn/share/32204074

  http://www.huihui.cn/share/32206528

  http://www.huihui.cn/share/32208680

  http://www.huihui.cn/share/32209208

  http://www.huihui.cn/share/32209734

  http://www.huihui.cn/share/32225096

  http://www.huihui.cn/share/32225524

  http://www.huihui.cn/share/32226046

  http://www.huihui.cn/share/32226410

  http://www.huihui.cn/share/32226832

  http://www.huihui.cn/share/32227310

  http://www.huihui.cn/share/32227720

  http://www.huihui.cn/share/32228310

  http://www.huihui.cn/share/32229516

  http://www.huihui.cn/share/32230042

  http://www.huihui.cn/share/32230516

  http://www.huihui.cn/share/32230886

  http://www.huihui.cn/share/32231390

  http://www.huihui.cn/share/32231776

  http://www.huihui.cn/share/32232158

  http://www.huihui.cn/share/32232526

  http://www.huihui.cn/share/32232914

  http://www.huihui.cn/share/32233276

  http://www.huihui.cn/share/32233754

  http://www.huihui.cn/share/32234242

  http://www.huihui.cn/share/32234714

  http://www.huihui.cn/share/32235140

  http://www.huihui.cn/share/32235714

  http://www.huihui.cn/share/32236134

  http://www.huihui.cn/share/32236642

  http://www.huihui.cn/share/32237682

  http://www.huihui.cn/share/32241870

  http://www.huihui.cn/share/32242318

  http://www.huihui.cn/share/32242972

  http://www.huihui.cn/share/32244090

  http://www.huihui.cn/share/32244552

  http://www.huihui.cn/share/32261208

  http://www.huihui.cn/share/32262616

  http://www.huihui.cn/share/32263554

  http://www.huihui.cn/share/32264280

  http://www.huihui.cn/share/32265442

  http://www.huihui.cn/share/32266146

  http://www.huihui.cn/share/32266654

  http://www.huihui.cn/share/32267218

  http://www.huihui.cn/share/32267650

  http://www.huihui.cn/share/32268068

  http://www.huihui.cn/share/32268516

  http://www.huihui.cn/share/32269098

  http://www.huihui.cn/share/32269602

  http://www.huihui.cn/share/32270186

  http://www.huihui.cn/share/32270842

  http://www.huihui.cn/share/32271650

  http://www.huihui.cn/share/32272436

  http://www.huihui.cn/share/32275454

  http://www.huihui.cn/share/32285302

  http://www.huihui.cn/share/32285774

  http://www.huihui.cn/share/32286216

  http://www.huihui.cn/share/32286682

  http://www.huihui.cn/share/32287148

  http://www.huihui.cn/share/32287744

  http://www.huihui.cn/share/32288154

  http://www.huihui.cn/share/32288618

  http://www.huihui.cn/share/32289104

  http://www.huihui.cn/share/32289658

  http://www.huihui.cn/share/32290984

  http://www.huihui.cn/share/32291466

  http://www.huihui.cn/share/32293404

  http://www.huihui.cn/share/32293886

  http://www.huihui.cn/share/32294546

  http://www.huihui.cn/share/32295008

  http://www.huihui.cn/share/32295378

  http://www.huihui.cn/share/32295854

  http://www.huihui.cn/share/32296304

  http://www.huihui.cn/share/32296702

  http://www.huihui.cn/share/32297286

  http://www.huihui.cn/share/32297794

  http://www.huihui.cn/share/32298330

  http://www.huihui.cn/share/32298850

  http://www.huihui.cn/share/32299456

  http://www.huihui.cn/share/32299908

  http://www.huihui.cn/share/32300278

  http://www.huihui.cn/share/32302006

  http://www.huihui.cn/share/32302466

  http://www.huihui.cn/share/32304464

  http://www.huihui.cn/share/32305386

  http://www.huihui.cn/share/32306214

  http://www.huihui.cn/share/32306692

  http://www.huihui.cn/share/32307766

  http://www.huihui.cn/share/32308194

  http://www.huihui.cn/share/32309094

  http://www.huihui.cn/share/32309574

  http://www.huihui.cn/share/32310530

  http://www.huihui.cn/share/32310918

  http://www.huihui.cn/share/32315730

  http://www.huihui.cn/share/32316042

  http://www.huihui.cn/share/32316428

  http://www.huihui.cn/share/32317308

  http://www.huihui.cn/share/32317824

  http://www.huihui.cn/share/32318448

  http://www.huihui.cn/share/32319058

  http://www.huihui.cn/share/32322508

  http://www.huihui.cn/share/32323000

  http://www.huihui.cn/share/32323446

  http://www.huihui.cn/share/32323954

  http://www.huihui.cn/share/32324312

  http://www.huihui.cn/share/32327336

  http://www.huihui.cn/share/32332016

  http://www.huihui.cn/share/32332374

  http://www.huihui.cn/share/32332732

  http://www.huihui.cn/share/32333272

  http://www.huihui.cn/share/32333660

  http://www.huihui.cn/share/32333974

  http://www.huihui.cn/share/32337772

  http://www.huihui.cn/share/32338154

  http://www.huihui.cn/share/32338514

  http://www.huihui.cn/share/32338938

  http://www.huihui.cn/share/32345002

  http://www.huihui.cn/share/32345296

  http://www.huihui.cn/share/32346354

  http://www.huihui.cn/share/32346632

  http://www.huihui.cn/share/32346892

  http://www.huihui.cn/share/32347328

  http://www.huihui.cn/share/32347684

  http://www.huihui.cn/share/32348048

  http://www.huihui.cn/share/32348554

  http://www.huihui.cn/share/32350474

  http://www.huihui.cn/share/32350756

  http://www.huihui.cn/share/32351022

  http://www.huihui.cn/share/32351288

  http://www.huihui.cn/share/32351846

  http://www.huihui.cn/share/32352260

  http://www.huihui.cn/share/32356536

  http://www.huihui.cn/share/32357130

  http://www.huihui.cn/share/32357522

  http://www.huihui.cn/share/32359228

  http://www.huihui.cn/share/32359456

  http://www.huihui.cn/share/32360372

  http://www.huihui.cn/share/32360696

  http://www.huihui.cn/share/32360998

  http://www.huihui.cn/share/32361404

  http://www.huihui.cn/share/32361794

  http://www.huihui.cn/share/32362114

  http://www.huihui.cn/share/32362518

  http://www.huihui.cn/share/32362872

  http://www.huihui.cn/share/32365314

  http://www.huihui.cn/share/32365698

  http://www.huihui.cn/share/32366016

  http://www.huihui.cn/share/32366386

  http://www.huihui.cn/share/32366660

  http://www.huihui.cn/share/32367070

  http://www.huihui.cn/share/32367308

  http://www.huihui.cn/share/32367582

  http://www.huihui.cn/share/32367902

  http://www.huihui.cn/share/32368474

  http://www.huihui.cn/share/32368812

  http://www.huihui.cn/share/32369238

  http://www.huihui.cn/share/32369584

  http://www.huihui.cn/share/32370146

  http://www.huihui.cn/share/32370762

  http://www.huihui.cn/share/32371030

  http://www.huihui.cn/share/32371358

  http://www.huihui.cn/share/32371588

  http://www.huihui.cn/share/32371914

  http://www.huihui.cn/share/32372194

  http://www.huihui.cn/share/32372614

  http://www.huihui.cn/share/32378628

  http://www.huihui.cn/share/32379974

  http://www.huihui.cn/share/32380390

  http://www.huihui.cn/share/32385820

  http://www.huihui.cn/share/32386452

  http://www.huihui.cn/share/32386706

  http://www.huihui.cn/share/32387050

  http://www.huihui.cn/share/32387550

  http://www.huihui.cn/share/32397408

  http://www.huihui.cn/share/32398220

  http://www.huihui.cn/share/32398962

  http://www.huihui.cn/share/32399486

  http://www.huihui.cn/share/32399930

  http://www.huihui.cn/share/32400554

  http://www.huihui.cn/share/32400974

  http://www.huihui.cn/share/32401498

  http://www.huihui.cn/share/32401920

  http://www.huihui.cn/share/32402658

  http://www.huihui.cn/share/32403048

  http://www.huihui.cn/share/32403482

  http://www.huihui.cn/share/32410368

  http://www.huihui.cn/share/32410848

  http://www.huihui.cn/share/32411754

  http://www.huihui.cn/share/32412154

  http://www.huihui.cn/share/32412544

  http://www.huihui.cn/share/32412836

  http://www.huihui.cn/share/32413128

  http://www.huihui.cn/share/32413462

  http://www.huihui.cn/share/32413754

  http://www.huihui.cn/share/32414130

  http://www.huihui.cn/share/32414516

  http://www.huihui.cn/share/32414858

  http://www.huihui.cn/share/32415194

dd = dd2; for(i = 0; iu; dd->b = dd1->b; dd->a = dd1->a; dd = dd->u; } p.b = (p.b%15)+1; } else { goto qq; } c0 = c; } else { qq: if(c0 == 'w') { if(at == 1) { dd0 =(snake1)malloc(sizeof(snake)); dd0->a = dd2->a;dd0->b = dd2->b; dd0->n = NULL;dd0->u = dd2; dd2=dd0; } dd = dd2; for(i = 0; iu; dd->b = dd1->b; dd->a = dd1->a; dd = dd->u; } if(p.a == 1) p.a = 15; else p.a=(p.a-1)%15; } else if(c0 == 's') { if(at == 1) { dd0 =(snake1)malloc(sizeof(snake)); dd0->a = dd2->a;dd0->b = dd2->b; dd0->n = NULL;dd0->u = dd2; dd2=dd0; } dd = dd2; for(i = 0; iu; dd->b = dd1->b; dd->a = dd1->a; dd = dd->u; } p.a=(p.a%15)+1; } else if(c0 == 'a') { if(at == 1) { dd0 =(snake1)malloc(sizeof(snake)); dd0->a = dd2->a;dd0->b = dd2->b; dd0->n = NULL;dd0->u = dd2; dd2=dd0; } dd = dd2; for(i = 0; iu; dd->b = dd1->b; dd->a = dd1->a; dd = dd->u; } if(p.b == 1) p.b = 15; else p.b=(p.b-1)%15; } else if(c0 == 'd') { if(at == 1) { dd0 =(snake1)malloc(sizeof(snake)); dd0->a = dd2->a;dd0->b = dd2->b; dd0->n = NULL;dd0->u = dd2; dd2=dd0; } dd = dd2; for(i = 0; iu; dd->b = dd1->b; dd->a = dd1->a; dd = dd->u; } p.b=(p.b%15)+1; } } fflush( stdin); dd = &q; _sleep(200); } }

你可能感兴趣的:(c语言数数小游戏,c语言迷宫游戏代码)