| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1511 人关注过本帖
标题:俄罗斯方块源程序
只看楼主 加入收藏
yywyai
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-12-9
收藏
 问题点数:0 回复次数:5 
俄罗斯方块源程序

/*此程序还有很多不完善的地方,有兴趣的可以继续改进

希望大家多和我交流,我的油箱是yywyai@sina.com*/

#include<stdio.h> #include <graphics.h> #include <dos.h> #include <stdlib.h> #define UP 0x48 #define DOWN 0x50 #define LEFT 0x4b #define RIGHT 0x4d #define ESC 0x01 #define P 0x19 #define ENTER 0x1c #define PAGEUP 0x49 #define PAGEDOWN 0x51 #define add_D 0x0d #define add_d 0x4e #define sub_D 0x0c #define sub_d 0x4a #define RST 0x13 #define PAUSE 0x19

long score; int brick_width=20; char str[9]={'0','0','0','0','0','0','0','0','\0'}; /*积分数组!*/ int m_speed=0; int difficulty=0;

/************************************************/ /*以下定义的是砖块的形状*/ int brick [6][4][4][4]= { { {{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0}}, {{0,1,1,0},{1,1,0,0},{0,0,0,0},{0,0,0,0}}, {{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0}}, {{0,1,1,0},{1,1,0,0},{0,0,0,0},{0,0,0,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}} }, { {{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,0,0,0}}, {{0,1,1,0},{0,0,1,1},{0,0,0,0},{0,0,0,0}}, {{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,0,0,0}}, {{0,1,1,0},{0,0,1,1},{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,0},{1,1,1,1},{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,0},{1,1,1,1},{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,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}} }, { {{1,1,1,0},{1,0,0,0},{0,0,0,0},{0,0,0,0}}, {{1,1,0,0},{0,1,0,0},{0,1,0,0},{0,0,0,0}}, {{0,0,1,0},{1,1,1,0},{0,0,0,0},{0,0,0,0}}, {{1,0,0,0},{1,0,0,0},{1,1,0,0},{0,0,0,0}} } };

/*以下定义的是游戏窗口的矩阵,在游戏进行时,通过检查此矩阵来获知砖块的堆积情况*/ int board[22][12]={ {2,2,2,2,2,2,2,2,2,2,2,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,0,0,0,0,0,0,0,0,0,0,2}, {2,2,2,2,2,2,2,2,2,2,2,2} }; /*以下是程序中用到汉字的点阵——————————————————*/ char e_16[]={ /* 以下是 '俄' 的 16点阵宋体 字模,32 byte */ 0x10,0x20,0x19,0xA8,0x16,0x24,0x22,0x24, 0x3F,0xFE,0x62,0x20,0xA2,0x24,0x22,0xA6, 0x23,0x2C,0x26,0x28,0x2A,0x10,0x22,0x30, 0x22,0x4A,0x2E,0x8A,0x24,0x04,0x00,0x00, }; char luo_16[]={ /* 以下是 '罗' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x3F,0xFC,0x22,0x44,0x22,0x44, 0x22,0x44,0x3F,0xFC,0x22,0x00,0x03,0xFC, 0x06,0x08,0x0C,0x08,0x12,0x10,0x61,0x20, 0x00,0xC0,0x03,0x00,0x0C,0x00,0xF0,0x00, }; char si_16[]={ /* 以下是 '斯' 的 16点阵宋体 字模,32 byte */ 0x22,0x0C,0x22,0x70,0xFF,0x40,0x22,0x40, 0x3E,0x40,0x22,0x7E,0x22,0x48,0x3E,0x48, 0x22,0x48,0x22,0x48,0xFF,0x48,0x00,0x48, 0x24,0x88,0x62,0x88,0x83,0x08,0x00,0x08, }; char fang_16[]={ /* 以下是 '方' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x01,0x00,0x00,0x80,0xFF,0xFE, 0x02,0x00,0x02,0x00,0x03,0xF0,0x02,0x10, 0x04,0x10,0x04,0x10,0x08,0x10,0x08,0x10, 0x10,0x10,0x20,0x90,0xC0,0x60,0x00,0x00, }; char kuai_16[]={ /* 以下是 '块' 的 16点阵宋体 字模,32 byte */ 0x20,0x80,0x20,0x80,0x20,0x80,0x23,0xF8, 0xF8,0x88,0x20,0x88,0x20,0x88,0x20,0x88, 0x2F,0xFE,0x20,0x80,0x39,0x40,0xE1,0x20, 0x42,0x18,0x02,0x0E,0x04,0x04,0x08,0x00, }; char kai_16[]={ /* 以下是 '开' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x7F,0xFE,0x04,0x20,0x04,0x20, 0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x20, 0x04,0x20,0x04,0x20,0x08,0x20,0x08,0x20, 0x10,0x20,0x20,0x20,0x40,0x20,0x00,0x00, }; char shi_16[]={ /* 以下是 '始' 的 16点阵宋体 字模,32 byte */ 0x10,0x20,0x18,0x30,0x10,0x20,0x10,0x48, 0xFC,0x84,0x25,0xFE,0x24,0x84,0x44,0x00, 0x44,0xFC,0x28,0x84,0x18,0x84,0x14,0x84, 0x22,0x84,0x42,0xFC,0x80,0x84,0x00,0x00, }; char tui_16[]={ /* 以下是 '退' 的 16点阵宋体 字模,32 byte */ 0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0, 0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88, 0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18, 0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00, }; char chu_16[]={ /* 以下是 '出' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04, 0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04, 0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04, 0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00, }; char you_16[]={ /* 以下是 '游' 的 16点阵宋体 字模,32 byte */ 0x44,0x20,0x22,0x20,0x22,0x20,0x0F,0xBE, 0x84,0x40,0x54,0xBC,0x57,0x08,0x25,0x10, 0x25,0x10,0x25,0x7E,0xC5,0x10,0x49,0x10, 0x49,0x10,0x49,0x10,0x55,0x50,0x42,0x20, }; char xi_16[]={ /* 以下是 '戏' 的 16点阵宋体 字模,32 byte */ 0x00,0x40,0x00,0x50,0x7E,0x48,0x02,0x48, 0x44,0x40,0x25,0xFE,0x18,0x40,0x08,0x44, 0x0C,0x28,0x14,0x30,0x12,0x20,0x22,0x50, 0x41,0x92,0x06,0x0A,0x00,0x06,0x00,0x02, }; char xia_16[]={ /* 以下是 '下' 的 16点阵宋体 字模,32 byte */ 0x00,0x04,0x7F,0xFE,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0xC0,0x01,0x60,0x01,0x30, 0x01,0x20,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00, }; char ge_16[]={ /* 以下是 '个' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x40, 0x04,0x20,0x09,0x18,0x11,0x0E,0x61,0x04, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00, }; char tu_16[]={ /* 以下是 '图' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x7F,0xFC,0x44,0x04,0x47,0xE4, 0x44,0x44,0x4A,0x84,0x71,0x04,0x42,0xC4, 0x4C,0x3C,0x71,0x14,0x40,0x84,0x42,0x04, 0x41,0x84,0x41,0x04,0x7F,0xFC,0x40,0x04, }; char xing_16[]={ /* 以下是 '形' 的 16点阵宋体 字模,32 byte */ 0x00,0x04,0x7F,0x86,0x12,0x0C,0x12,0x10, 0x12,0x20,0x12,0x08,0xFF,0xCC,0x12,0x18, 0x12,0x20,0x12,0x44,0x12,0x86,0x12,0x0C, 0x22,0x10,0x22,0x20,0x42,0x40,0x80,0x80, }; char fen_16[]={ /* 以下是 '分' 的 16点阵宋体 字模,32 byte */ 0x08,0x80,0x0C,0x80,0x08,0x40,0x10,0x20, 0x10,0x30,0x20,0x18,0x40,0x0E,0x9F,0xE4, 0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20, 0x08,0x20,0x10,0xA0,0x20,0x40,0x40,0x00, }; char shu_16[]={ /* 以下是 '数' 的 16点阵宋体 字模,32 byte */ 0x08,0x20,0x49,0x30,0x2A,0x20,0x1C,0x20, 0xFF,0x7E,0x1C,0x44,0x2B,0x44,0x48,0xC4, 0x08,0x28,0xFF,0x28,0x12,0x10,0x34,0x10, 0x0C,0x28,0x32,0x4E,0xC0,0x84,0x00,0x00, }; char bd_16[]={ /* 以下是 ':' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00, 0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00, }; char su_16[]={ /* 以下是 '速' 的 16点阵宋体 字模,32 byte */ 0x00,0x80,0x40,0x80,0x2F,0xFC,0x20,0x80, 0x00,0x80,0x07,0xF8,0xE4,0x88,0x24,0x88, 0x27,0xF8,0x21,0xA0,0x22,0x98,0x2C,0x88, 0x20,0x80,0x50,0x80,0x8F,0xFE,0x00,0x00, }; char du_16[]={ /* 以下是 '度' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20, 0x22,0x20,0x2F,0xFC,0x22,0x20,0x23,0xE0, 0x20,0x00,0x27,0xF8,0x22,0x10,0x21,0x20, 0x20,0xC0,0x41,0x30,0x46,0x0E,0x98,0x04, }; char cong_16[]={ /* 以下是 '从' 的 16点阵宋体 字模,32 byte */ 0x08,0x40,0x08,0x40,0x08,0x40,0x08,0x40, 0x08,0x40,0x08,0x40,0x08,0x40,0x08,0xA0, 0x14,0xA0,0x12,0x90,0x12,0x90,0x21,0x08, 0x23,0x0C,0x42,0x06,0x84,0x04,0x08,0x00, }; char xin_16[]={ /* 以下是 '新' 的 16点阵宋体 字模,32 byte */ 0x10,0x00,0x08,0x0E,0x7F,0x70,0x22,0x40, 0x14,0x40,0xFF,0x7E,0x08,0x48,0x08,0x48, 0xFF,0x48,0x08,0x48,0x2C,0x48,0x2A,0x88, 0x4A,0x88,0x89,0x08,0x2A,0x08,0x10,0x08, }; char nan_16[]={ /* 以下是 '难' 的 16点阵宋体 字模,32 byte */ 0x00,0xA0,0x00,0x90,0xF9,0x10,0x09,0xFE, 0x8B,0x20,0x4B,0x20,0x2D,0xFC,0x11,0x20, 0x19,0x20,0x29,0xFC,0x25,0x20,0x45,0x20, 0x81,0x20,0x01,0xFE,0x01,0x00,0x01,0x00, }; char xuan_16[]={ /* 以下是 '选' 的 16点阵宋体 字模,32 byte */ 0x00,0x40,0x22,0x40,0x12,0x40,0x13,0xF8, 0x04,0x40,0x00,0x40,0xF7,0xFC,0x11,0x20, 0x11,0x20,0x12,0x24,0x12,0x24,0x14,0x1C, 0x10,0x00,0x28,0x00,0x47,0xFE,0x00,0x00, }; char ze_16[]={ /* 以下是 '择' 的 16点阵宋体 字模,32 byte */ 0x20,0x00,0x23,0xF8,0x21,0x10,0xFC,0xA0, 0x20,0x40,0x20,0xA0,0x2B,0x58,0x30,0x46, 0x63,0xF8,0xA0,0x40,0x20,0x40,0x27,0xFE, 0x20,0x40,0x20,0x40,0xA0,0x40,0x40,0x40, };

/* 函数申明 */ int getkey(); void draw_brick(int kind,int stat,int start_x,int start_y,int *position); void display_brick(int *position,int xexcursion,int yexcursion); void draw_freezebrick(int *space); void draw_mainboard(); int is_movable(int *position,int *space,int dir); void freeze(int *position,int *space); int check_bottom(int *space,int hei); void ERASE(int top,int flag); int move_down(int *position,int *space,int *top,int *flag,int speed); void begin(); void rand_select(int *kind,int *stat); void updata_data(int *space,int *top,int flag); void preview(int kind_new,int stat_new); void convert_score(long score,char *str); void drawmat(char *,int,int,int,int); /**************************************************/

/**********************************************************/ void drawmat(char *mat,int matsize,int x,int y,int color) /*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/ { int i, j, k, n; n = (matsize - 1) / 8 + 1; for(j = 0; j < matsize; j++) for(i = 0; i < n; i++) for(k = 0;k < 8; k++) if(mat[j * n + i] & (0x80 >> k)) /*测试为1的位则显示*/ putpixel(x + i * 8 + k, y + j, color); }

/*初始化游戏板巨阵!*/ void init_data(int **space) { int hei,wid,i,j; *space=(int *)malloc(264*sizeof(int)); /*分配的空间,"264" 是数组的长度*/ for(i=0;i<difficulty;i++) for(j=0;j<12;j++) board[21-i][j]=random(2); for(hei=0;hei<22;hei++) for(wid=0;wid<12;wid++) *(*space+hei*12+wid)=board[hei][wid];

/*初始化*/ score=0; }

void convert_score(long score,char *str) { int i; long SCORE; SCORE=score; for(i=7;i>=0;i--) { str[i]='0'+SCORE%10; SCORE /=10; } } /**************************************************/

/*获取键盘扫描码 */ int getkey() { union REGS key; key.h.ah=0; int86(0x16,&key,&key); return key.h.ah; }

/*****************************************************/

/*画方格图形*/ void mydraw(int start_x,int start_y,int brick_width,int color) { settextstyle(4,0,5); setfillstyle(6,8); setcolor(color); rectangle(start_x,start_y,start_x+brick_width,start_y+brick_width); rectangle(start_x+2,start_y+2,start_x+brick_width-2,start_y+brick_width-2); outtextxy(start_x+7,start_y+7,"*"); }

/******************************************************/

/* 用mydraw函数和position数组在屏幕上画方块*/ void draw_brick(int kind,int stat,int start_x,int start_y,int *position) { int wid,hei,x,y,i=0; void *buf; setviewport(100,40,300,440,1); buf=malloc(400); for(i=0;i<8;i+=2) { x=position[i];y=position[i+1]; getimage(x,y,x+brick_width,y+brick_width,buf); putimage(x,y,buf,XOR_PUT); } i=0; for(hei=0;hei<4;hei++) { y=start_y+hei*brick_width; for(wid=0;wid<4;wid++) if(brick[kind][stat][hei][wid]==1) { x=start_x+wid*brick_width; position[i++]=x; position[i++]=y; position[10]= x > position[10] ? x : position[10]; position[11]= y > position[11] ? y : position[11]; mydraw(x,y,brick_width,10); } } position[8]=start_x; position[9]=start_y;

free(buf); /* 释放 "buf" 所占的内存*/ } void display_score(char *pstr) /*显示积分和速度(10000分加一级,最大9级)*/ { void *buf;int n,j;char speed[2]; buf=malloc(3200); itoa(m_speed,&speed,10);/*需要改进*/ setviewport(479,139,560,170,1); getimage(0,0,80,40,buf); putimage(0,0,buf,XOR_PUT); settextstyle(0,0,1); setcolor(WHITE); outtextxy(0,0,pstr); outtextxy(0,22,speed); if(m_speed<=9) { n=atoi(pstr); m_speed+=n/10000; } free(buf);

}

搜索更多相关主题的帖子: define 俄罗斯方块 sina include 
2004-12-09 15:19
yywyai
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-12-9
收藏
得分:0 

/***************************************************/

void preview(int kind_new,int stat_new) /*形成随机选择的方块4种图形到屏幕上*/ { int hei,wid; void *buf; display_score(str); setviewport(480,40,560,120,1); buf=malloc(10000); getimage(0,0,79,79,buf); putimage(0,0,buf,XOR_PUT);

for(hei=0;hei<4;hei++) { for(wid=0;wid<4;wid++) { if(brick[kind_new][stat_new][hei][wid]) { mydraw(wid*brick_width,hei*brick_width,brick_width,11); } } } free(buf); }

/**********************************************************/ /*当方块停下来时在屏上画方块!*/ void draw_freezebrick(int *space) { int wid,hei,x,y; setviewport(100,40,300,440,1);

for(hei=20;hei>0;hei--) { y=(hei-1)*brick_width; for(wid=1;wid<11;wid++) { x=(wid-1)*brick_width; if(space[hei*12+wid]==1) { mydraw(x,y,brick_width,6); } } } } /****************************************************************/

/*显示移动的方块!*/ void display_brick(int *position,int xexcursion,int yexcursion) { void *pBuf; int size,x,y,i;

x=position[0];y=position[1]; size=400; pBuf=malloc(size); getimage(x,y,x+brick_width,y+brick_width,pBuf);

for(i=0;i<8;i+=2) { x=position[i];y=position[i+1]; putimage(x,y,pBuf,COPY_PUT); putimage(x,y,pBuf,XOR_PUT); }

position[8]+=xexcursion; position[9]+=yexcursion; position[10]+=xexcursion; position[11]+=yexcursion;

for(i=0;i<8;i+=2) { x=position[i];y=position[i+1]; putimage(x+xexcursion,y+yexcursion,pBuf,COPY_PUT); position[i]+=xexcursion; position[i+1]+=yexcursion; } free(pBuf); } /***********************************************************/

/*选择方块的形状*/ int turnover(int stat) { if(stat==3) return 0; else return stat+1; }

/*********************************************************/

/*核对方块是能活动. 返回值: "1" : 不能再向左移动 "2" : 不能再向右移动 "3" : 不能再向下移动 */ int is_movable(int *position,int *space,int dir) { int i; /*0 向左;1 向右;2 向下 */ switch(dir) { case 0: for(i=0;i<8;i+=2) { if(space[(position[i+1]/brick_width+1)*12+(position[i]/brick_width)]>0) return 1; } case 1: for(i=0;i<8;i+=2) { if(space[(position[i+1]/brick_width+1)*12+(position[i]/brick_width)+2]>0) return 2; } case 2: for(i=0;i<8;i+=2) { if(space[ (position[i+1]/brick_width+2)*12+(position[i]/brick_width+1) ]>0) return 3; } } }

/************************************************************************/ /* 更改背景方块,到数组中?, 储存未消除的方块! */ void freeze(int *position,int *space) { int i,hei,wid; for(i=0;i<8;i+=2) { hei=(position[i+1]/brick_width)+1; wid=(position[i]/brick_width)+1; space[hei*12+wid]=1; } }

/*********************************************************/

/* 判行是否满! */ int check_bottom(int *space,int hei) { int wid,change=1;

for(wid=1;wid<=10;wid++) { if(space[hei*12+wid]==0) { change=0; break; } } if(change) return 1; else return 0; }

/**************************************************/

void ERASE(int top,int flag) { int hei,wid; void *buf;

setviewport(100,40,300,440,1); buf=malloc(400); for(hei=top-1;hei<=flag;hei++) for(wid=1;wid<=10;wid++) { getimage((wid-1)*brick_width,(hei-1)*brick_width,wid*brick_width,hei*brick_width,buf); putimage((wid-1)*brick_width,(hei-1)*brick_width,buf,XOR_PUT); } free(buf); }

/*****************************************************/ /* 当方块停下来时更新数组中的空位! */ void updata_data(int *space,int *top,int flag) { int hei,wid,FLAG,hei_1,count; hei_1=flag; hei_1=20; while(hei_1>=*top&&hei_1!=21) { count=0; while(check_bottom(space,hei_1)) { ERASE(*top,hei_1); for(hei=hei_1;hei>=*top-1;hei--) { for(wid=1;wid<=10;wid++) { space[hei*12+wid]=space[(hei-1)*12+wid]; } } *top=*top+1;

count+=1; if(count>1) score+=150; if(count>=3) score+=200; if(count<=1) score+=100;

convert_score(score,str); draw_freezebrick(space); continue; } hei_1=hei_1 - 1; } }

/**********************************************/ /* 用随机数选择一个方块! */ void rand_select(int *kind,int *stat) { randomize(); *kind=random(6); *stat=random(4); }

int move_down(int *position,int *space,int *top,int *flag,int speed) { if(kbhit()) return 1; else while(!kbhit()) { display_brick(position,0,brick_width/2); if(is_movable(position,space,2)==3) {

freeze(position,space); if(position[9]/brick_width+1<*top) *top=position[9]/brick_width+1; *flag=position[11]/brick_width+1; updata_data(space,top,*flag); draw_freezebrick(space); return 0; }

delay(10000-speed*100); if(!speed) delay(50000); } } void game_set(void) { int ch; char difficulty_[2]; char speed[2]; void *buf=malloc(1600); do { if(ch==ESC)exit(0); setviewport(479,155,490,200,1); getimage(0,0,40,40,buf); putimage(0,0,buf,XOR_PUT); settextstyle(0,0,1); setcolor(WHITE); itoa(m_speed,speed,10); outtextxy(0,5,speed); itoa(difficulty,difficulty_,10); outtextxy(0,25,difficulty_); if(ch==PAGEUP&&difficulty<9)difficulty++; if(ch==PAGEDOWN&&difficulty>0)difficulty--; if((ch==add_D||ch==add_d)&&m_speed<9)m_speed++; if((ch==sub_D||ch==sub_d)&&m_speed>0)m_speed--; }while((ch=getkey())!=ENTER);/*游戏设置*/ } /*游戏开始 */ /*****************************/ void begin() { int * space, * newposition, position[12], newkind, newstat, start_x, start_y, kind, stat, kind_new, stat_new, top, flag, change_direct, i;

game_set();

init_data(&space); draw_freezebrick(space); rand_select(&kind_new,&stat_new); top=20; while(1) { for(i=0;i<12;i++) position[i]=0; display_score(str);

kind=kind_new;stat=stat_new; rand_select(&kind_new,&stat_new); preview(kind_new,stat_new);

setviewport(100,40,300,440,1); draw_brick(kind,stat,60,0,position);

while(move_down(position,space,&top,&flag,m_speed)) { switch(getkey()) { case LEFT:

if(is_movable(position,space,0)!=1) { display_brick(position,-brick_width,0); delay(50000); continue; }

if(is_movable(position,space,0)==1) continue;

case RIGHT:

if(is_movable(position,space,1)!=2) { display_brick(position,brick_width,0); delay(50000); continue; }

if(is_movable(position,space,1)==2) continue; case DOWN: change_direct=move_down(position,space,&top,&flag,(m_speed+1)*30);

if(change_direct) continue; if(!change_direct) break; case UP:

stat=turnover(stat); start_x=position[8]; start_y=position[9]; draw_brick(kind,stat,start_x,start_y,position); if(position[10]>=180) display_brick(position,-brick_width,0); continue;

case ESC: closegraph(); exit(1);

case RST: break;

default: continue; } break; } } }

/******画游戏面板********/ void draw_mainboard() {

setfillstyle(9,7); bar(1,1,639,5); bar(1,2,5,476); bar(1,475,639,479); bar(639,2,635,479); bar(400,2,403,636); setfillstyle(11,9); bar(94,33,308,39); bar(94,439,308,445); bar(93,40,99,440); bar(304,40,309,440); rectangle(479,39,561,121); line(404,130,635,130); drawmat(e_16,16,140,15,WHITE); drawmat(luo_16,16,160,15,RED); drawmat(si_16,16,180,15,GREEN); drawmat(fang_16,16,200,15,BLUE); drawmat(kuai_16,16,220,15,YELLOW); drawmat(xia_16,16,480,15,GREEN); drawmat(ge_16,16,500,15,GREEN); drawmat(tu_16,16,520,15,GREEN); drawmat(xing_16,16,540,15,GREEN); drawmat(fen_16,16,420,135,WHITE); drawmat(shu_16,16,440,135,WHITE); drawmat(bd_16,16,460,135,WHITE); drawmat(su_16,16,420,155,WHITE); drawmat(du_16,16,440,155,WHITE); drawmat(bd_16,16,460,155,WHITE); drawmat(nan_16,16,420,175,WHITE); drawmat(du_16,16,440,175,WHITE); drawmat(bd_16,16,460,175,WHITE); drawmat(kai_16,16,460,300,RED); drawmat(shi_16,16,480,300,RED); drawmat(you_16,16,500,300,RED); drawmat(xi_16,16,520,300,RED); drawmat(tui_16,16,460,340,RED); drawmat(chu_16,16,480,340,RED); drawmat(you_16,16,500,340,RED); drawmat(xi_16,16,520,340,RED); drawmat(nan_16,16,460,380,RED); drawmat(du_16,16,480,380,RED); drawmat(xuan_16,16,500,380,RED); drawmat(ze_16,16,520,380,RED); drawmat(su_16,16,460,420,RED); drawmat(du_16,16,480,420,RED); drawmat(xuan_16,16,500,420,RED); drawmat(ze_16,16,520,420,RED); setcolor(6); outtextxy(540,305,"(Enter)"); outtextxy(540,345, "(Esc)"); outtextxy(540,385,"(PageUp/Down)"); outtextxy(540,425,"(+ or -)"); }

void main() { int driver=DETECT,mode; registerbgidriver(EGAVGA_driver); initgraph(&driver,&mode,"d:\\turboc2"); cleardevice(); draw_mainboard(); begin(); getch(); closegraph(); }

2004-12-09 15:20
shallpp
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-12-24
收藏
得分:0 
强!
2004-12-24 17:47
huang
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2004-12-19
收藏
得分:0 
2004-12-25 13:39
zeroshine
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-12-28
收藏
得分:0 
bug 很多啊~~

2004-12-29 10:06
yywyai
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-12-9
收藏
得分:0 
写这个程序只是一时兴趣,现在也不想再去改了,如果你有兴趣可以参考star_cn对方块处理的函数改写一下。
2005-01-04 10:23
快速回复:俄罗斯方块源程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021612 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved