——使用软件VC6.0(需要一个函数库——Easy_X)
#include <stdio.h>
#include <graphics.h
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib,"winmm.lib")
#define B1_x 0// 游戏矩形左边值#define B2_x 360//游戏矩形右边值#define B1_y 120//上边值#define B2_y 480
#define V_box 20//每个小方块边长#define H_box 20
#define M 18//一共有18个小方块#define N 18
#define left 1
#define right 2
#define down 3
#define up 4
#define space 5
#define F 0
#define T 1
struct MAX_BOX
{
int var;//填充值!
int color;}min_box[M][N];int R_top_x;//小游戏方块的最右边值
int R_top_y;
int bottom_y;//zuixiazhiint bottom_x;
int L_bottom_x;
int score=0;
int speed=0;
int n=1;
int full_row=0;
int flag_newbox=0;
int speed_step=30;
int sleeptime=1000;
#define MAX_BOX 19struct SHAPE{ char box[2];
int color;
int next;
}shapes[MAX_BOX]=
{ {0x88,0xc0,RED,1},
{0x8e,0x0,RED,2},
{0xc4,0x40,RED,3},
{0x2e,0x0,RED,0}, //******************* {0x44,0xc0,MAGENTA,5}, {0x8e,0x0,MAGENTA,6}, {0xc8,0x80,MAGENTA,7}, {0xe2,0x0,MAGENTA,4}, //++++++++++++++++++++ {0x8c,0x40,WHITE,9}, {0x6c,0x0,WHITE,8}, //******************* {0x4c,0x80,YELLOW,11}, {0xc6,0x0,YELLOW,10}, //____________________
{0x4e,0x0,BLUE,15},
{0x8c,0x80,BLUE,14},
{0xe4,0x0,BLUE,13},
{0x4c,0x40,BLUE,12}, //&&&&&&&&&&&&&&&&&&&&&& {0x88,0x88,RED,17},
{0xf0,0x0,RED,16}, //*********************** {0xcc,0x0,MAGENTA,18}, };
void interface_one()//第一幅画面
{
initgraph(640,480);
setbkcolor(BLACK);// 设置背景色为黑色 cleardevice();// 用背景色清空屏幕 settextcolor(RED);
settextstyle(50,0,_T("楷体"));
RECT r={0,0,640,480};// drawtext(_T("俄罗斯方块游戏"),&r,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
getch();
closegraph(); }
void interface_game()//游戏运行画面!
{
int i,j;
int x1=B1_x;
int y1=B1_y;
int x2=B2_x;
int y2=B2_y;
initgraph(640,480);
setbkcolor(BLACK);
cleardevice();
setlinecolor(RED);
line(0,30,640,30);
settextcolor(RED);
settextstyle(16,0,_T("楷体"));
RECT r={0,0,640,30};
drawtext(_T("欢迎来到俄罗斯方块游戏"),&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
setlinecolor(RED);
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
min_box[i][j].var=0;
min_box[i][j].color=BLACK; line(x1,y1,x1+H_box,y1); line(x1,y1+V_box,x1+H_box,y1+H_box); line(x1,y1,x1,y1+V_box); line(x1+H_box,y1,x1+H_box,y1+V_box); x1=x1+H_box; } x1=B1_x; y1=y1+H_box;
}
}
int born_box()//随机生成方块!
{
int box_numb; srand(time(NULL)); box_numb=(rand()%19);
return(box_numb);
}
int randomize()//初始化X的坐标!
{
int B_x;
srand(time(NULL));
B_x=(rand()%15)*20; return(B_x);
}
void show_score(int s)
{
char S[5];
setcolor(RED);
setfillcolor(RED); rectangle(480,120,640,180);
floodfill(501,121,RED);
RECT r={480,120,640,180}; settextcolor(RED); settextstyle(25,0,_T("宋体"));
drawtext(_T("当前得分"),&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
sprintf(S,"%d",s);
outtextxy(560,200,S);//指定位置输出字符串 }
void show_level(int k)
{
char L[5];
setcolor(RED);
setfillcolor(RED); rectangle(480,240,640,300);
floodfill(501,241,RED);
settextcolor(RED);
RECT r={480,240,640,300}; settextstyle(25,0,_T("宋体")); drawtext(_T("当前等级"),&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
sprintf(L,"%d",k);
outtextxy(560,320,L);
}
网友评论