使用C语言+EasyX完成消灭星星游戏(2)
上一篇简单介绍一下项目和创建游戏界面
本篇介绍如何达到消除方块的功能。具体思路,代码都有详细注释。
下一篇消除同色方块后其他方块的下落。
#include<stdio.h>
#include<graphics.h>
#include<time.h>
#include <conio.h>
#include <mmsystem.h>
#pragma comment(lib,"Winmm.lib")
#pragma warning(disable:4996)
#define N 40
IMAGE bgImage;//游戏页面背景图片
IMAGE RegbgImage;//注册页面背景图片
IMAGE nowImage; //当前
MOUSEMSG m; //鼠标
COLORREF colorArr[6] = {
RGB(200, 0, 0), RGB(0, 200, 0),
RGB(0, 200, 200), RGB(200, 0, 200),RGB(200,200,0) };//颜色池
typedef struct position
{
int x;
int y;
}posType; //位置信息
posType mou; //鼠标位置结构体
posType sameArr[100]; //同色方块坐标
int index = 0; //同色方块个数
void game(void); //初始化游戏界面
void playgame(void); //游戏玩法
void getsameclolr(posType, COLORREF);//获取同颜色的方块
int isValid(posType, COLORREF); //判断方块附近颜色是否一样
int main() {
initgraph(700, 700);//初始化窗口
game();
playgame();
system