Red de conocimiento informático - Conocimiento del nombre de dominio - Cómo escribir Tetris en lenguaje C, por favor avise, ¡gracias!

Cómo escribir Tetris en lenguaje C, por favor avise, ¡gracias!

Primero debe descargar vc++. Los principiantes pueden usar vs98 para instalarlo. En el proyecto, pueden agregar el siguiente código #include?"graphics.h"

#include?

#include?

int?gcW?=?20,?gcColor[] =?{GRIS OSCURO,?AZUL CLARO,?VERDE CLARO ,?CYAN CLARO,

ROJO CLARO,?MAGENTA CLARO,MAGENTA,?AMARILLO};

struct?tetris?{

int?_pool[? ], ? ( *pool)[32],?tmap[8][4][16];

int?x,?y,?s,?st,?t;

} gt;

void?trsInit()?{

int?sp[8][4]?{{15,4369},{23,785,116,547},{71,275,113,802 },

{39,305,114,562},{54,561},{99,306},{51,51},{-1}};

int?*p,?i,?j ,?b;

for?(p?=?sp[0];? *p?>=?0;? ++p)?if?(? *p?==?0? )?*p ?=?p[-2];

gt.pool?=? >._pool[4];

para?(j?=?0;? j?

para?(i?=?0;?i?

para?(b ?=?0 ;?b?

gt.tmap[j+1][i][b]? =?(sp[j][i]? &?1) ?*?(j?+?1),

sp[j][i]? >>=?1;

memset(gt._pool,? -1,? sizeof(gt._pool));

para?(i?=?0;?i?

memset(> .pool[i ],?0,?sizeof(int[21]));

Retorno;

}

int?trsCopy(int?sp [],?int?x,?int?y,?int?c)?{

int?m[]?{0,32,64,96,1,33,65,97, 2,34, 66,98,3,35,67,99},?i,?cx,?cy;

for?(i?=?0;?i?

cx?=?x?+? (m[i]? >>?5),?cy?=?y?+ ? (m[ i]? &?31);

if?(gt.pool[cx][cy])?if?(c?==?2)?gt.pool[cx] [cy]? =?0;?else?

if?(c==1)?gt.pool[cx][cy] =?sp[i];

}

return?1;

}

int?trsScene()?{

int?x,?y?= ?0;

gt.s?=?random(7)?+?1,?gt.st?=?gt.t?=?0;

gt.x ?=?4 ,?gt

.y?=?0;

for(--gt.t?; ? ;?retraso(10),? --gt.t)?{

int?k ?=?0;

mientras?{

k?=?getch();

si?(k?==?27)?regresar? 0;

si?(k?==?A'? ||?k?==?A')?{

si?(trsCopy(gt.tmap[gt .s][gt.st],?gt.x-1,?gt.y,?0))?--gt.x;

}?else?if?(k?== ?' D'? ||?k?==?' d')?{

si?(trsCopy(gt.tmap[gt.s][gt.st],?gt.x+ 1 ,?gt.y,?0))?++gt.x;

}?else?if?(k?==?'W'?||?k?==?' W ')?{

if?(trsCopy(gt.tmap[gt.s][(gt.st+1)? %?4],?gt.x,?gt.y,? 0 ))

gt.st?=?(gt.st+1)?%?4;

}

}}

if?(k?==?' S'? ||?k?==?' s'? ||?gt.t?

if?(trsCopy ( gt.tmap[gt.s][gt.st],?gt.x,?gt.y+1,?0))++gt.y,gt.t=50;

más ?{

trsCopy(gt.tmap[gt.s][gt.st],?gt.x,?gt.y,?1);

para?( - -y;?y?>?0;? --y)?{

para?(x?=?0;?gt.pool[x][y]? >?0;? + +x);

si?(gt.pool[x][y]?

para?(k?=?y++;?k?>? 0 ;?

for?(x?=?0;?gt.pool[x][0]? >=?0;? ++x)

gt.pool [ x][k]? =?gt.pool[x][k-1];

}

¿regresar?;

}

}

trsCopy(gt.tmap[gt.s][gt.st],?gt.x,?gt.y,?1);

para ? (x?=?0;?gt.pool[x][0]? >=?0;? ++x)?{

para?(y?=?1;?gt. pool [x][y]? >=?0;? ++y)?{

setfillstyle(1,?gcColor[gt.pool[x][y]]);

bar(201?+?x*gcW,?1?+?y*gcW,?200?+?gcW?+?x*gcW,?gcW?+?y*gcW);

}

}

trsCopy(gt.tmap[gt.s][gt.st],?gt.x,?gt.y,?2);

p>

}

}

}

int?main()?{

int?g?=? DETECT ,?m?=?0;

initgraph(&g,? &m,?"") ;

randomize();

trsInit();

¿mientras?(trsScene());

¿regresar?