2024年3月21日发(作者:)

第一个Cpp

#include

#include

#include

#include

#include

#pragma comment(lib,"") //播放背景音乐的头文件

#include "colorConsole.h"

#include

#define SQUARE_COLOR BACKGROUD_BLUE|BACKGROUD_RED|

BACKGROUD_INTENSITY //背景颜色

#define SQUARE_COLOR

FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY //方块的颜色

#define up 72

#define down 80

#define left 75

#define right 77

#define esc 27

#define MAPW 15 //地图的宽度

#define MAPH 25 //地图的高度

void initiate1();

int * build(); //创建方块

//初始化工作

BOOL isavailable(int a[],int x,int y,int w,int h); //判定是否能放下

void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors);

void delete_cache(); //清除键盘缓冲区

void revolve(int a[][4],int w,int h,int *x,int y); //转动方块

void pro();

void end();

void delete_blocks(int *a,int w,int h,int x,int y);

void gameover();

void deletefull_line(int m[][MAPW],int row,int w,int h); //消除一行

int dx=30,dy=5; //屏幕上的偏移量

int score=0,level=0;

int map[MAPH][MAPW];

int a1[4][4]={{1},{1,1,1}};

int a2[4][4]={{0,1},{1,1,1}};

int a3[4][4]={{1,1},{0,1,1}};

int a4[4][4]={{0,0,1},{1,1,1}};

int a5[4][4]={{0,1,1},{1,1}};

int a6[4][4]={{1,1,1,1}};

int a7[4][4]={{1,1},{1,1}};

int a[4][4];

int main()

{

HANDLE handle;

handle=initiate();

WORD wColors[1]={FOREGROUND_BLUE|

FOREGROUND_GREEN|FOREGROUND_INTENSITY };

while(1)

{

sndPlaySound("ResourceJust ",SND_LOOP|SND_ASYNC);//用异步

方式播放音乐,PlaySound函数在开始播放后立即返回

system("CLS");

int n=0;

printf("目录n1.开始游戏n2.退出游戏nnn");

scanf("%d",&n);

switch(n)

{

case 1:

system("CLS");

textout(handle,22,6,wColors+2,1,"请选择游戏等级:");

textout(handle,32,8,wColors+2,1,"1.初级");

textout(handle,32,10,wColors+2,1,"2.中级");

textout(handle,32,12,wColors+2,1,"3.高级");

while(1)

{

char choice;

choice=_getch();

if(choice=='1')

{

textout(handle,22,6,wColors+2,1,"开始游戏,初级");

textout(handle,32,8,wColors+2,1," ");

textout(handle,32,10,wColors+2,1," ");

textout(handle,32,12,wColors+2,1," ");

level=0,score=0;

Sleep(2000);

textout(handle,22,6,wColors+2,1," ");

break;

}

else if(choice=='2')

{

textout(handle,22,6,wColors+2,1,"开始游戏,中级");

textout(handle,32,8,wColors+2,1," ");

textout(handle,32,10,wColors+2,1," ");