一个俄罗斯方块的源代码
一个俄罗斯方块的源代码,自己写的,有点笨的……
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<bios.h>
#define LEFT 0x4b
#define RIGHT 0x4d
#define DOWN 0x50
#define CHANGE 0x20
#define ESC 0x1b
#define INTR 0x1C
#define DefaultX 5
#define DefaultY 1
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
static unsigned counter=0;
static unsigned shape[7][4][4][4]={
{
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
},
{
{{0,0,0,0},{1,1,1,1},{0,0,0,0},{0,0,0,0}},
{{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0}},
{{0,0,0,0},{1,1,1,1},{0,0,0,0},{0,0,0,0}},
{{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0}},
},
{
{{0,1,0,0},{1,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,0,0},{0,1,1,0},{0,1,0,0},{0,0,0,0}},
{{0,0,0,0},{1,1,1,0},{0,1,0,0},{0,0,0,0}},
{{0,1,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0}},
},
{
{{1,0,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0}},
{{0,0,0,0},{0,1,1,0},{1,1,0,0},{0,0,0,0}},
{{1,0,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0}},
{{0,0,0,0},{0,1,1,0},{1,1,0,0},{0,0,0,0}},
},
{
{{0,1,0,0},{1,1,0,0},{1,0,0,0},{0,0,0,0}},
{{0,0,0,0},{1,1,0,0},{0,1,1,0},{0,0,0,0}},
{{0,1,0,0},{1,1,0,0},{1,0,0,0},{0,0,0,0}},
{{0,0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1,1}};
char ShapeColor[7]={8,10,11,12,13,14,15};
char DigitalShape[10]={128+119,3,62,31,128+75,128+93,128+125,19,128+127,128+95};
char ZodiacBack[11]={4,6,12,13,11,10,2,3,9,1,8};
char ZodiacSoft[18][14]={{0,0,0,0,96,0,0,0,0,0,0,0,60,0},
{255,248,0,0,96,0,0,0,0,248,0,0,124,0},
{255,248,0,0,97,128,0,0,3,248,0,0,192,0},
{0,112,0,0,97,128,0,0,7,0,0,1,128,48},
{0,224,0,0,96,0,0,0,14,0,0,1,128,48},
{1,192,0,0,96,0,0,0,12,0,0,1,128,48},
{3,128,120,15,97,128,240,60,12,0,15,15,249,255},
{7,0,252,31,225,131,248,127,14,0,31,143,249,255},
{7,1,142,48,225,135,24,227,7,240,49,193,128,48},
{14,3,134,96,97,142,24,192,3,252,112,193,128,48},
{28,3,6,96,97,140,25,192,0,28,96,193,128,48},
{56,3,6,96,97,140,25,128,0,6,96,193,128,48},
{56,3,6,96,97,140,25,128,0,6,96,193,128,48},
{120,3,6,96,97,140,25,128,0,6,96,193,128,48},
{224,1,140,48,225,142,25,195,24,14,49,129,128,48},
{255,249,252,63,225,135,252,255,28,28,63,129,128,48},
{255,248,240,15,97,131,236,60,15,248,30,1,128,48},
{0,0,0,0,0,0,0,0,7,224,0,1,128,0}};
unsigned long TotalMark=0;
unsigned int Erasered=0,ETimes=0;
int Speed=0;
int CEr=0;
int NumOfLev[5]={0,0,0,0,0};
int TimeDelay[10]={21,18,17,15,13,11,9,7,5,3};
char NewShape[2];
unsigned PerOnce[4];
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt handler(__CPPARGS)
{
++counter;
oldhandler();
}
void DrawBackground()
{
//setlinestyle
}
void DrawDigital(int x,int y,int a)
{
int i=7;
setcolor(((DigitalShape[a]>>i)&1)*7+4);
//printf("%d",(DigitalShape[a]>>i)&1);
i--;
line(x,y+1,x,y+15);
line(x+1,y+2,x+1,y+14);
line(x+2,y+3,x+2,y+13);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x,y+17,x,y+31);
line(x+1,y+18,x+1,y+30);
line(x+2,y+19,x+2,y+29);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x,y+17,x,y+31);
line(x+1,y+18,x+1,y+30);
line(x+2,y+19,x+2,y+29);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+1,y,x+16,y);
line(x+2,y+1,x+15,y+1);
line(x+3,y+2,x+14,y+2);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+2,y+15,x+15,y+15);
line(x+1,y+16,x+16,y+16);
line(x+2,y+17,x+15,y+17);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+3,y+30,x+14,y+30);
line(x+2,y+31,x+15,y+31);
line(x+1,y+32,x+16,y+32);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+15,y+3,x+15,y+13);
line(x+16,y+2,x+16,y+14);
line(x+17,y+1,x+17,y+15);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
line(x+15,y+19,x+15,y+29);
line(x+16,y+18,x+16,y+30);
line(x+17,y+17,x+17,y+31);
}
void ArtClear()
{
for(int i=480;i>=0;i-=2)
{
setcolor(3);
line(0,i-6,639,i-6);
setcolor(9);
line(0,i-4,639,i-4);
setcolor(1);
line(0,i-2,639,i-2);
setcolor(getbkcolor());
line(0,i,639,i);
delay(1);
}
for(i=1;i<480;i+=2)
{
setcolor(3);
line(0,i+6,639,i+6);
setcolor(9);
line(0,i+4,639,i+4);
setcolor(1);
line(0,i+2,639,i+2);
setcolor(getbkcolor());
line(0,i,639,i);
delay(1);
}
}
void end()
{
for(int j=0;j<4;j++)
{
for(int i=j;i<480;i+=4)
{
setcolor(3);
line(0,i+8,639,i+8);
setcolor(9);
line(0,i+4,639,i+4);
setcolor(1);
line(0,i,639,i);
setcolor(getbkcolor());
line(0,i,639,i);
delay(1);
}
delay(5);
}
setcolor(YELLOW);
outtextxy(260,200,"[ Game Over ]");
gotoxy(14,16);
printf("This freeware is written by Daniel.Qu ZodiacSoft 2000");
gotoxy(12,17);
printf("Please e-mail to swami@yeah.net or visit my homepage at");
gotoxy(12,18);
printf("http://grocery.2699.com if you have question.");
gotoxy(14,20);
printf("I will soon provide something new,please wait...");
gotoxy(14,22);
printf("We hold these truths to be self-evident,that all codes");
gotoxy(12,23);
printf("are created FREE.");
getch();
clrscr();
closegraph();
exit(0);
}
void ShowTitle()
{
int gdriver=DETECT,gmode,errorcode,i,j,k;
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s