【自用14.3】C++俄罗斯方块-方块的表示

该系列文章会根据项目的编写步骤来出

方块的表示

由于设备问题,暂时出的代码是未进行运行检验的,后期会补上运行后的版本

#include //C语言形式的输入输出
#include //图形库的头文件

int score = 0;//总分
int rank = 0;//等级

#define BLOCK_COUNT 5
#define BLOCK_WIDTH 5
#define BLOCK_HEIGHT 5
int block [BLOCK_COUNT*4][BLOCK_HEIGHT][BLOCK_WIDTH]={
    // | 形方块
	{ 0,0,0,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,0,0,0,
	  0,1,1,1,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,0,0,0,
	  0,1,1,1,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	// L 形方块
	{ 0,0,0,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,1,1,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,0,0,0,
	  0,1,1,1,0,
	  0,1,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,0,1,0,0,
	  0,0,1,0,0,
	  0,0,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,0 },

	// 田 形方块
	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,1,1,0,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,1,1,0,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,1,1,0,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,1,1,0,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	// T 形方块
	{ 0,0,0,0,0,
	  0,1,1,1,0,
	  0,0,1,0,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,0,1,0,
	  0,0,1,1,0,
	  0,0,0,1,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,0,1,0,0,
	  0,1,1,1,0,
	  0,0,0,0,0,
	  0,0,0,0,0 },

	{ 0,0,0,0,0,
	  0,1,0,0,0,
	  0,1,1,0,0,
	  0,1,0,0,0,
	  0,0,0,0,0 },

	// Z 形方块
	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,0,1,1,0,
	  0,0,0,0,0,
	  0,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,0,0 },

	{ 0,0,0,0,0,
	  0,1,1,0,0,
	  0,0,1,1,0,
	  0,0,0,0,0,
	  0,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,0,0 },
};

//实现欢迎界面
void welcome(void);

//初始化游戏场景
void initGameScene(void);

int main(void){
    welcome();
    initGameScene();

    //产生新方块
    nextblock();

    system("pause");
    colsegraph();
    return 0;
}

void welcome(void){
    //初始化画布
    initgraph(550,660);

    //设置窗口标题
    HWND window=GetHWnd();//获取窗口
    SetWindowText(window,_T("俄罗斯方块 .远_"))//设置窗口标题

    //设置文本的字体样式
    setfont(40,0,_T("微软雅黑"));//0代表自适应宽度
    setcolor(WHITE);
    outtextxy(205,200,_T("俄罗斯方块"));//在指定位置输出文本

    setfont(20,0,_T("楷体"));//0代表自适应宽度
    outtextxy(175,300,_T("编程,从俄罗斯方块开始!"));//在指定位置输出文本

    Sleep(3000);//暂停3秒钟
}

void initGameScene(void){
    char str[16];

    //清除屏幕
    cleardevice();

    rectangle(27,27,336,635);
    rectangle(29,29,334,633);
    rectangle(370,50,515,195);

    setfont(24,0,_T("楷体"));
    setcolor(LIGHTGRAY);
    outtextxy(405,215,_T("下一个"));

    setcolor(RED);
    outtextxy(405,280,_T("分数"));

    sprintf(str,"%d",score);
    outtextxy(415,310,str);
    //这里需要修改项目属性,操作方法如下
    //右击项目名称-》选择属性-》配置属性-》字符集-》使用多字节字符集

    outtextxy(405,375,_T("等级"));
    sprintf(str,"%d",rank);
    outtextxy(425,405,rank);

    //操作说明
    setcolor(LIGHTBLUE);
    outtextxy(390,475,_T("操作说明"));
    outtextxy(390,500,_T("↑:旋转"));
    outtextxy(390,525,_T("↓:下降"));
    outtextxy(390,550,_T("←:左移"));
    outtextxy(390,575,_T("→:右移"));
    outtextxy(390,600,_T("空格:暂停"));    
}

你可能感兴趣的:(Pro,学习笔记,C++,c++,开发语言,算法,游戏)