#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup")
#include <graphics.h> // EasyX图形库头文件
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
// 宏定义
#define TRUE 1
#define FALSE 0
#define MAX_SIZE 7 // 最大拼图规模
#define N 9 // 拼图块种类数
#define ROWS 3 // 行数
#define COLS 3 // 列数
// 全局变量
int WINDOW_WIDTH = 1000; // 窗口宽度
int WINDOW_HEIGHT =1000; // 窗口高度
int BUTTON_X = 300; // 按钮X坐标
int BUTTON_Y = 200; // 按钮Y坐标
int BUTTON_WIDTH = 200; // 按钮宽度
int BUTTON_HEIGHT = 50; // 按钮高度
int degrees[] = { 3,4,5,6,7 }; // 难度级别对应的拼图尺寸
char str[N][1000]; // 存储传统文化描述的数组
int key = 0; // 全局键值变量
ExMessage msg; // 消息结构体变量
// 新增计时相关全局变量
time_t start_time; // 游戏开始时间
int is_time_up = FALSE; // 超时标志
const int TIMELIMIT = 120; // 2分钟倒计时(秒)
// 可选图片结构体
typedef struct {
const char* name; // 图片名称
int num; // 图片编号
} Pictures;
// 图片资源数组
Pictures picture[] = {
{"京剧脸谱",1}, {"中国结",2}, {"剪纸",3},
{"书法",4}, {"国画",5}, {"陶瓷",6},
{"刺绣",7}, {"皮影",8}, {"灯笼",9}
};
// 拼图游戏结构体
typedef struct {
int size; //拼图规模
int matrix[MAX_SIZE][MAX_SIZE]; //拼图块版块
int emptyRow, emptyCol; //空白格位置
int moves; //移动步数
int picIndex; //选择的图片索引
int species[N]; //选择的图片
} Blocks;
void ReadData();//数据读取函数(从文件读取传统文化描述)
void WriteSingleSelectedData(int i);//显示单个传统文化描述
void WriteAllData();//显示所有传统文化描述
void GetImage(const char* filename, int lx, int ly);//加载并显示图片
void cut_image(const char* filename, int size);//切割图片函数(备用)
int isClick(int x, int y);//按钮点击检测函数
void Button(int, int, const char* word);//绘制按钮函数
int ModeSelection();//模式选择界面
int Selectpicture();//图片选择界面
void Information(int key);//游戏说明界面
void InitPuzzle(Blocks* game, int size, int picIndex);//初始化拼图游戏
int CheckWin(Blocks* game);//检查是否胜利
int MoveTile(Blocks* game, int direction);//移动拼图块
void DrawPuzzle(Blocks* game);//绘制拼图界面
void ShowWinScreen(Blocks* game);//显示胜利界面
void ShowTimeOverScreen();//显示超时界面
void PuzzlePage(int degree, int picIndex);//拼图游戏主循环
void Menu();//菜单
void DisplayTraditionalElements();
int main() {
// 初始化随机数种子
srand((unsigned)time(NULL));
// 读取传统文化描述数据
ReadData();
// 进入主菜单循环
while (TRUE) {
Menu();
}
closegraph();//关闭图形窗口
return 0;
}
//数据读取函数(从文件读取传统文化描述)
void ReadData() {
FILE* file = fopen("data.txt", "r");
if (file == NULL) {
// 文件打开失败时使用默认文本
for (int i = 0; i < N; i++) {
sprintf(str[i], "元素 %d 描述加载失败", i + 1);
}
return;
}
// 逐行读取描述
for (int i = 0; i < N; i++) {
if (fgets(str[i], sizeof(str[i]), file) != NULL) {
// 去除换行符
size_t len = strlen(str[i]);
if (len > 0 && str[i][len - 1] == '\n') {
str[i][len - 1] = '\0';
}
}
}
fclose(file);
}
//显示单个传统文化描述
void WriteSingleSelectedData(int i) {
outtextxy(0, 0, str[i]);
}
//显示所有传统文化描述
void WriteAllData() {
for (int i = 0; i < N; i++) {
outtextxy(i, i * 5, str[i]);
}
}
//加载并显示图片
void GetImage(const char* filename, int lx, int ly) {
IMAGE image;
loadimage(&image, filename);
putimage(lx, ly, &image);
}
//切割图片函数
void cut_image(const char* filename, int size) {
IMAGE img;
loadimage(&img, filename); // 加载图片
if (img.getwidth() == 0 || img.getheight() == 0) {
// 加载失败
outtextxy(100, 100, "图片加载失败!");
return;
}
// 获取图片宽度和高度
int width = img.getwidth();
int height = img.getheight();
//目标宽高
int targetWidth = 200;
int targetHeight = 200;
// 定义切割块的大小
const int blockWidth = width / size;
const int blockHeight = height / size;
// 分配二维指针数组
IMAGE*** blocks = (IMAGE***)malloc(size * sizeof(IMAGE*));
for (int i = 0; i < size; i++) {
blocks[i] = (IMAGE**)malloc(size * sizeof(IMAGE*));
for (int j = 0; j < size; j++) {
blocks[i][j] = (IMAGE*)malloc(sizeof(IMAGE));
/*切割*/
// 初始化每个块的大小
blocks[i][j] = new IMAGE(blockWidth, blockHeight);
// 从原图中截取对应区域
// 切换到img作为绘图设备
SetWorkingImage(&img);
getimage(blocks[i][j], j * blockWidth, i * blockHeight, blockWidth, blockHeight);
SetWorkingImage(); // 恢复到窗口
Resize(blocks[i][j], targetWidth, targetHeight);
}
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
//putimage(200 + blockWidth * i, 200 + blockHeight * j, blocks[i][j]);
if (i == size - 1 && i == j) {
setfillcolor(RGB(30, 30, 30));
solidrectangle(100 + targetWidth * i, 100 + targetHeight * j, targetWidth + 100 + targetWidth * i, targetHeight + 100 + targetHeight * j);
return;
}
putimage(100 + targetWidth * i, 100 + targetHeight * j, blocks[j][i]);
setlinecolor(RGB(0, 0, 0));
rectangle(100 + targetWidth * i, 100 + targetHeight * j, targetWidth + 100 + targetWidth * i, targetHeight + 100 + targetHeight * j);
}
}
//释放内存
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
delete blocks[i][j];
}
free(blocks[i]);
}
free(blocks);
}
//按钮点击检测函数
int isClick(int x, int y) {
// 检查鼠标消息队列中的所有消息
while (peekmessage(&msg, EX_MOUSE)) {
if (msg.message == WM_LBUTTONDOWN) {
// 检查是否在按钮区域内
int inArea = (msg.x >= BUTTON_X + x &&
msg.y >= BUTTON_Y + y &&
msg.x <= BUTTON_X + x + BUTTON_WIDTH &&
msg.y <= BUTTON_Y + y + BUTTON_HEIGHT);
// 移除已处理的消息
while (peekmessage(&msg, EX_MOUSE));
return inArea;
}
// 移除其他鼠标消息
peekmessage(&msg, EX_MOUSE, PM_REMOVE);
}
return FALSE;
}
//绘制按钮函数
void Button(int x, int y, const char* word) {
//设置按钮样式
setbkmode(TRANSPARENT);//设置背景模式透明
setfillcolor(RGB(231, 250, 235));
solidroundrect(BUTTON_X + x, BUTTON_Y + y, BUTTON_X + x + BUTTON_WIDTH, BUTTON_Y + y + BUTTON_HEIGHT, 20, 20);//透明边框矩形图
// 设置文字样式
settextstyle(50, 15, "华文宋体");
setbkmode(TRANSPARENT);
settextcolor(RGB(35, 30, 30));
// 计算文字居中位置输出
int w = (BUTTON_WIDTH - textwidth(word)) / 2;
int h = (BUTTON_HEIGHT - textheight(word)) / 2;
outtextxy(BUTTON_X + x + w, BUTTON_Y + y + h, word);
}
//模式选择界面
int ModeSelection() {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 五种难度按钮
const char* str[] = { "简单模式","初级模式","中级模式","高级模式","终极模式" };
for (int i = 0; i < 5; i++) {
Button(100, i * 100, str[i]);
}
// 显示提示信息
settextstyle(35, 20, "华文宋体");
outtextxy(300, 120, "请点击选择游戏难度");
// 等待选择
while (TRUE) {
// 处理所有鼠标消息
while (peekmessage(&msg, EX_MOUSE)) {
if (msg.message == WM_LBUTTONDOWN) {
// 检查点击了哪个按钮
for (int i = 0; i < 5; i++) {
int buttonTop = BUTTON_Y + i * 100;
int buttonBottom = buttonTop + BUTTON_HEIGHT;
if (msg.x >= BUTTON_X && msg.x <= BUTTON_X + BUTTON_WIDTH &&
msg.y >= buttonTop && msg.y <= buttonBottom) {
return degrees[i];
}
}
}
// 移除已处理的消息
peekmessage(&msg, EX_MOUSE, PM_REMOVE);
}
Sleep(10);
}
}
//图片选择界面
int Selectpicture() {
cleardevice();
const int startX = 0, startY = 10;
int selected = -1;
// 3x3网格显示9种传统文化图片选项
for (int i = 0; i < 9; i++) {
int row = i / 3, col = i % 3;
Button(startX + col * 180, startY + row * 150, picture[i].name);
}
// 显示提示信息
settextstyle(35, 20, "华文宋体");
outtextxy(300, 120, "请点击选择拼图图片");
// 等待选择
while (selected == -1) {
// 处理所有鼠标消息
while (peekmessage(&msg, EX_MOUSE)) {
if (msg.message == WM_LBUTTONDOWN) {
// 检查点击了哪个图片按钮
for (int i = 0; i < 9; i++) {
int row = i / 3, col = i % 3;
int buttonX = BUTTON_X + col * 200;
int buttonY = BUTTON_Y + row * 150;
if (msg.x >= buttonX && msg.x <= buttonX + BUTTON_WIDTH &&
msg.y >= buttonY && msg.y <= buttonY + BUTTON_HEIGHT) {
selected = i;
break;
}
}
}
// 移除已处理的消息
peekmessage(&msg, EX_MOUSE, PM_REMOVE);
}
Sleep(10);
}
return selected;
}
//游戏说明界面
void Information(int key) {
while (true) {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 设置文本样式
settextcolor(RGB(255, 215, 0)); // 金色
setbkmode(TRANSPARENT);
settextstyle(25, 10, "华文宋体");
// 游戏说明文本
const char instructions[] =
"这是一个传统文化主题的数字拼图游戏。\n"
"目标是通过移动拼图块,使所有数字按顺序排列,右下角为空白格。\n"
"每个数字对应一种中国传统文化元素:\n"
"1: 京剧脸谱\n2: 中国结\n3: 剪纸\n"
"4: 书法\n5: 国画\n6: 陶瓷\n"
"7: 刺绣\n8: 皮影\n9: 灯笼\n\n"
"操作方式:\n"
"方向键 - 移动拼图\n"
"ESC - 退出游戏\n"
"L - 查看传统文化元素列表\n"
"点击右下角按钮返回主菜单...";
// 计算文本位置
int startX = 50, startY = 100;
int lineHeight = 50;
// 分行输出文本
char* context = NULL;
char* line = strtok_s((char*)instructions, "\n", &context);
while (line != NULL) {
outtextxy(startX, startY, line);
startY += lineHeight;
line = strtok_s(NULL, "\n", &context);
}
// 绘制返回按钮
Button(400, 500, "返回主菜单");
// 处理事件
bool exitLoop = false;
while (!exitLoop) {
// 处理所有类型的事件
if (peekmessage(&msg, EX_MOUSE | EX_KEY)) {
// 按键处理
if (msg.message == WM_KEYDOWN) {
if (msg.vkcode == 'L' || msg.vkcode == 'l') {
// 显示传统文化元素列表
DisplayTraditionalElements();
exitLoop = true; // 退出内层循环,重新绘制当前界面
}
else {
// 其他任意键返回主菜单
return;
}
}
// 鼠标处理
if (msg.message == WM_LBUTTONDOWN) {
// 检查是否点击了返回按钮
if (msg.x >= BUTTON_X + 400 &&
msg.x <= BUTTON_X + 400 + BUTTON_WIDTH &&
msg.y >= BUTTON_Y + 500 &&
msg.y <= BUTTON_Y + 500 + BUTTON_HEIGHT) {
return;
}
}
// 移除已处理的消息
peekmessage(&msg, EX_MOUSE | EX_KEY, PM_REMOVE);
}
Sleep(10);
}
}
}
// 显示传统文化元素列表
void DisplayTraditionalElements() {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 设置标题样式
settextcolor(RGB(255, 215, 0)); // 金色
setbkmode(TRANSPARENT);
settextstyle(50, 25, "华文行楷");
outtextxy(300, 30, "传统文化元素列表");
// 设置文本样式
settextstyle(25, 10, "华文宋体");
settextcolor(WHITE);
// 显示所有元素描述
int yPos = 100;
const int lineHeight = 40;
for (int i = 0; i < N; i++) {
// 显示元素编号和名称
char title[50];
sprintf(title, "%d: %s", i + 1, picture[i].name);
outtextxy(50, yPos, title);
// 显示元素描述
outtextxy(100, yPos + lineHeight, str[i]);
yPos += 3 * lineHeight; // 增加间距
}
// 添加返回按钮
Button(400, WINDOW_HEIGHT - 150, "返回");
// 等待返回
while (true) {
// 处理所有事件
while (peekmessage(&msg, EX_MOUSE | EX_KEY)) {
// 任意键或点击返回
if (msg.message == WM_KEYDOWN ||
(msg.message == WM_LBUTTONDOWN &&
msg.x >= BUTTON_X + 400 &&
msg.x <= BUTTON_X + 400 + BUTTON_WIDTH &&
msg.y >= BUTTON_Y + (WINDOW_HEIGHT - 150) &&
msg.y <= BUTTON_Y + (WINDOW_HEIGHT - 150) + BUTTON_HEIGHT)) {
// 移除所有待处理消息
while (peekmessage(&msg, EX_MOUSE | EX_KEY, PM_REMOVE));
return;
}
// 移除已处理的消息
peekmessage(&msg, EX_MOUSE | EX_KEY, PM_REMOVE);
}
Sleep(10);
}
}
//初始化拼图游戏
void InitPuzzle(Blocks* game, int size, int picIndex) {
game->size = size;
game->picIndex = picIndex;
game->moves = 0;
// 初始化拼图数据
int num = 1;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
game->matrix[i][j] = (i == size - 1 && j == size - 1) ? 0 : num++;
}
}
game->emptyRow = size - 1;
game->emptyCol = size - 1;
// 随机打乱拼图(减少循环次数,避免卡顿)
for (int i = 0; i < size * size * 20; i++) { // 原为100,现为20
int dir = rand() % 4;
int newRow = game->emptyRow, newCol = game->emptyCol;
switch (dir) {
case 0: newRow--; break; // 上
case 1: newRow++; break; // 下
case 2: newCol--; break; // 左
case 3: newCol++; break; // 右
}
// 检查移动是否有效
if (newRow >= 0 && newRow < size && newCol >= 0 && newCol < size) {
// 交换空白格和目标格
game->matrix[game->emptyRow][game->emptyCol] = game->matrix[newRow][newCol];
game->matrix[newRow][newCol] = 0;
game->emptyRow = newRow;
game->emptyCol = newCol;
}
}
// 记录开始时间
start_time = time(NULL);
is_time_up = FALSE; // 重置超时标志
}
//检查是否胜利
int CheckWin(Blocks* game) {
int num = 1;
for (int i = 0; i < game->size; i++) {
for (int j = 0; j < game->size; j++) {
// 检查右下角是否为空白格
if (i == game->size - 1 && j == game->size - 1) {
if (game->matrix[i][j] != 0) return FALSE;
}
else {
// 检查其他格子是否按顺序排列
if (game->matrix[i][j] != num++) return FALSE;
}
}
}
return TRUE;
}
//移动拼图块
int MoveTile(Blocks* game, int direction) {
int newRow = game->emptyRow;
int newCol = game->emptyCol;
// 计算目标位置
switch (direction) {
case 0: newRow--; break; // 上
case 1: newRow++; break; // 下
case 2: newCol--; break; // 左
case 3: newCol++; break; // 右
default: return FALSE;
}
// 检查边界
if (newRow < 0 || newRow >= game->size || newCol < 0 || newCol >= game->size) {
return FALSE;
}
// 交换空白格和目标格
game->matrix[game->emptyRow][game->emptyCol] = game->matrix[newRow][newCol];
game->matrix[newRow][newCol] = 0;
game->emptyRow = newRow;
game->emptyCol = newCol;
game->moves++;
return TRUE;
}
// 绘制拼图界面(续)
void DrawPuzzle(Blocks* game) {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 设置文本样式
settextstyle(30, 15, "华文宋体");
setbkmode(TRANSPARENT);
// 显示标题和步数
settextcolor(WHITE);
outtextxy(50, 20, "传统文化拼图游戏");
char movesText[50];
sprintf(movesText, "步数: %d", game->moves);
outtextxy(50, 60, movesText);
// 显示倒计时(调整位置,避免超出窗口)
time_t current_time = time(NULL);
int elapsed = (int)(current_time - start_time);
int remaining = TIMELIMIT - elapsed;
if (remaining < 0) remaining = 0; // 防止负数显示
char time_str[50];
sprintf(time_str, "剩余时间: %02d:%02d", remaining / 60, remaining % 60);
// 时间小于10秒时显示红色警告
settextcolor(remaining <= 10 ? RED : WHITE);
outtextxy(WINDOW_WIDTH - 300, 20, time_str);
// 仅设置超时标志,不直接跳转界面
if (remaining == 0) {
is_time_up = TRUE;
}
// 计算拼图块大小和位置
int blockSize = 80;
int startX = (WINDOW_WIDTH - game->size * blockSize) / 2;
int startY = 150;
// 加载选中的图片
char filename[100];
sprintf(filename, "picture/%d.jpg", game->picIndex + 1);
IMAGE img;
loadimage(&img, filename);
// 检查图片是否成功加载
if (img.getwidth() <= 0 || img.getheight() <= 0) {
// 如果图片加载失败,使用默认数字块并显示提示
outtextxy(200, 200, "图片加载失败,使用数字模式");
for (int i = 0; i < game->size; i++) {
for (int j = 0; j < game->size; j++) {
int x = startX + j * blockSize;
int y = startY + i * blockSize;
if (game->matrix[i][j] == 0) {
// 绘制空白格
setfillcolor(RGB(200, 200, 200));
fillrectangle(x, y, x + blockSize, y + blockSize);
settextcolor(BLACK);
outtextxy(x + blockSize / 2 - 10, y + blockSize / 2 - 10, "●");
}
else {
// 绘制拼图块
setfillcolor(RGB(231, 250, 235));
fillrectangle(x, y, x + blockSize, y + blockSize);
// 显示数字
char numText[10];
sprintf(numText, "%d", game->matrix[i][j]);
settextcolor(BLACK);
outtextxy(x + blockSize / 2 - 10, y + blockSize / 2 - 10, numText);
}
// 绘制边框
setlinecolor(BLACK);
rectangle(x, y, x + blockSize, y + blockSize);
}
}
}
else {
// 图片加载成功,切割图片并显示
int imgWidth = img.getwidth();
int imgHeight = img.getheight();
for (int i = 0; i < game->size; i++) {
for (int j = 0; j < game->size; j++) {
int x = startX + j * blockSize;
int y = startY + i * blockSize;
if (game->matrix[i][j] == 0) {
// 绘制空白格
setfillcolor(RGB(200, 200, 200));
fillrectangle(x, y, x + blockSize, y + blockSize);
}
else {
// 计算当前拼图块在原图中的位置
int pieceIndex = game->matrix[i][j] - 1; // 0到size*size-1
int pieceRow = pieceIndex / game->size;
int pieceCol = pieceIndex % game->size;
// 计算在原图中的坐标和大小
int srcX = pieceCol * (imgWidth / game->size);
int srcY = pieceRow * (imgHeight / game->size);
int pieceWidth = imgWidth / game->size;
int pieceHeight = imgHeight / game->size;
// 切割并显示拼图块
IMAGE piece;
loadimage(&piece, NULL, pieceWidth, pieceHeight);
// 设置原图为当前绘图设备
SetWorkingImage(&img);
// 从原图中切割指定区域
getimage(&piece, srcX, srcY, pieceWidth, pieceHeight);
// 恢复默认绘图设备
SetWorkingImage(NULL);
putimage(x, y, &piece);
}
// 绘制边框
setlinecolor(BLACK);
rectangle(x, y, x + blockSize, y + blockSize);
}
}
}
// 显示操作提示
settextstyle(20, 10, "华文宋体");
outtextxy(50, WINDOW_HEIGHT - 60, "方向键: 移动拼图 ESC: 退出游戏 L: 查看元素列表");
}
// 显示胜利界面(移除音效)
void ShowWinScreen(Blocks* game) {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 设置胜利信息样式
settextstyle(50, 25, "华文行楷");
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 215, 0)); // 金色
// 显示胜利信息
outtextxy(WINDOW_WIDTH / 2 - 150, WINDOW_HEIGHT / 2 - 100, "恭喜你完成了拼图!");
// 显示步数
char movesText[50];
sprintf(movesText, "总步数: %d", game->moves);
outtextxy(WINDOW_WIDTH / 2 - 100, WINDOW_HEIGHT / 2, movesText);
// 显示用时
time_t end_time = time(NULL);
int total_seconds = (int)(end_time - start_time);
char timeText[50];
sprintf(timeText, "用时: %02d:%02d", total_seconds / 60, total_seconds % 60);
outtextxy(WINDOW_WIDTH / 2 - 100, WINDOW_HEIGHT / 2 + 50, timeText);
// 显示返回提示
settextstyle(30, 15, "华文宋体");
outtextxy(WINDOW_WIDTH / 2 - 100, WINDOW_HEIGHT / 2 + 100, "按任意键返回主菜单");
// 等待按键
_getch();
}
// 显示超时界面(移除音效)
void ShowTimeOverScreen() {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
// 设置文字样式
settextstyle(50, 25, "华文行楷");
setbkmode(TRANSPARENT);
settextcolor(RED);
// 显示超时信息
outtextxy(WINDOW_WIDTH / 2 - 200, WINDOW_HEIGHT / 2 - 100, "时间到!拼图失败!");
// 显示返回提示
settextstyle(30, 15, "华文宋体");
outtextxy(WINDOW_WIDTH / 2 - 150, WINDOW_HEIGHT / 2 + 50, "按任意键返回主菜单");
// 等待按键
_getch();
}
// 拼图游戏主循环(移除音效)
void PuzzlePage(int degree, int picIndex) {
cleardevice();
GetImage("picture/bk.jpg", 0, 0);
Blocks game;
InitPuzzle(&game, degree, picIndex);
while (TRUE) {
DrawPuzzle(&game);
if (CheckWin(&game)) {
ShowWinScreen(&game);
return;
}
if (is_time_up) {
ShowTimeOverScreen();
return;
}
// 处理键盘输入
if (peekmessage(&msg, EX_KEY)) {
if (msg.message == WM_KEYDOWN) {
switch (msg.vkcode) {
case VK_UP: MoveTile(&game, 0); break;
case VK_DOWN: MoveTile(&game, 1); break;
case VK_LEFT: MoveTile(&game, 2); break;
case VK_RIGHT: MoveTile(&game, 3); break;
case 'L':
// 显示传统文化元素列表
DisplayTraditionalElements();
// 重新绘制游戏界面
cleardevice();
DrawPuzzle(&game);
break;
case VK_ESCAPE:
return; // 返回上级菜单
}
}
}
Sleep(50); // 控制刷新率
}
}
// 主菜单界面(移除音效)
void Menu() {
// 初始化图形窗口
initgraph(WINDOW_WIDTH, WINDOW_HEIGHT);
// 设置背景
GetImage("picture/bk.jpg", 0, 0);
// 设置标题样式
settextcolor(RGB(39, 220, 220));
setbkmode(TRANSPARENT);
settextstyle(100, 30, "华文行楷");
outtextxy(150, 50, "传统文化拼图游戏");
// 绘制菜单按钮
const char* word[] = { "开始游戏", "游戏说明", "退出" };
for (int i = 0; i < 3; i++) {
Button(100, i * 150, word[i]);
}
// 处理菜单选择
while (1) {
// 处理所有鼠标消息
while (peekmessage(&msg, EX_MOUSE)) {
if (msg.message == WM_LBUTTONDOWN) {
// 检查开始游戏按钮
if (msg.x >= BUTTON_X + 100 && msg.x <= BUTTON_X + 100 + BUTTON_WIDTH &&
msg.y >= BUTTON_Y + 0 && msg.y <= BUTTON_Y + 0 + BUTTON_HEIGHT) {
int degree = ModeSelection();
int picIndex = Selectpicture();
PuzzlePage(degree, picIndex);
return;
}
// 检查游戏说明按钮
else if (msg.x >= BUTTON_X + 100 && msg.x <= BUTTON_X + 100 + BUTTON_WIDTH &&
msg.y >= BUTTON_Y + 150 && msg.y <= BUTTON_Y + 150 + BUTTON_HEIGHT) {
Information(key);
return;
}
// 检查退出按钮
else if (msg.x >= BUTTON_X + 100 && msg.x <= BUTTON_X + 100 + BUTTON_WIDTH &&
msg.y >= BUTTON_Y + 300 && msg.y <= BUTTON_Y + 300 + BUTTON_HEIGHT) {
closegraph();
exit(0);
}
}
// 移除已处理的消息
peekmessage(&msg, EX_MOUSE, PM_REMOVE);
}
Sleep(10);
}
}
被读取的data文件中的文字成为显示传统文化元素列表的输出
最新发布