#include "Game_Class.h"
extern int pasin; // 当前关卡
int CPlay::point_num, CPlay::line_num; // 点数、线数
extern MOUSEMSG msg; // 鼠标消息
extern wchar_t best_time[100]; // 最佳时间
extern CPoint my_point[200], my_point_save[200]; // 点信息、点信息保存
extern CLine my_line[50000]; // 线信息
extern int my_x_flag, my_y_flag, paper[20][20]; // 纸盘信息
extern bool point_flag[200]; // 移动标记
extern int pass_num; // 关卡数
extern long long times, start_time; // 计时器
//***** 游戏界面类成员函数实现 *****//
CPlay::CPlay() {} // 构造函数
CPlay::~CPlay() {} // 构析函数
// 游戏界面
void CPlay::inter_Face_Running()
{
// 设置和初始化
CGame *in;
clear();
read_Level();
CButton_Image image;
bool rb = 0, ab = 0, nb = 0, ob = 0;
CButton return_button, again_button, next_button, ok_button;
return_button.set_Image(image.return_Button(RGB(224, 197, 150)));
again_button.set_Image(image.again_Button(RGB(224, 197, 150)));
next_button.set_Image(image.next_Button(RGB(224, 197, 150)));
ok_button.set_Image(image.ok_Button(RGB(66, 202, 184)));
return_button.set_X_Y( BEGIN_X + PAPER_WIDTH / 3 - return_button.get_Image().getwidth(),
(WIN_HEIGHT + BEGIN_Y + PAPER_HEIGHT - return_button.get_Image().getheight()) / 2);
again_button.set_X_Y( (WIN_WIDTH - again_button.get_Image().getwidth()) / 2,
(WIN_HEIGHT + BEGIN_Y + PAPER_HEIGHT - again_button.get_Image().getheight()) / 2);
next_button.set_X_Y( BEGIN_X + PAPER_WIDTH / 3 * 2,
(WIN_HEIGHT + BEGIN_Y + PAPER_HEIGHT - next_button.get_Image().getheight()) / 2);
ok_button.set_X_Y( (WIN_WIDTH - ok_button.get_Image().getwidth()) / 2,
(WIN_HEIGHT + BEGIN_Y + PAPER_HEIGHT - ok_button.get_Image().getheight()) / 2);
start_time = int(time(NULL));
// 进入游戏
while (1)
{
if (if_Win())
{
while (MouseHit())
{
msg = GetMouseMsg();
// O K 按钮
if (ok_button.if_Mouse_On(msg))
{
ob = 1;
if (msg.uMsg == WM_LBUTTONUP)
{
in = new CWin();
in->inter_Face_Running();
delete in;
in = NULL;
if (!pasin)
return;
clear();
read_Level();
}
}
else
ob = 0;
}
this->clear_Board();
this->draw_Title();
this->draw_Paper();
this->draw_Graph();
if (ob)
{
ok_button.set_Image(image.ok_Button(RGB(66 + 15, 202 + 15, 184 + 15)));
ok_button.draw_Button();
}
else
{
ok_button.set_Image(image.ok_Button(RGB(66, 202, 184)));
ok_button.draw_Button();
}
}
else
{
while (MouseHit())
{
msg = GetMouseMsg();
// 移动点
for (int i = 1; i <= point_num; i++)
this->point_Move(i);
// 返回按钮
if (return_button.if_Mouse_On(msg))
{
rb = 1;
if (msg.uMsg == WM_LBUTTONUP)
{
msg.uMsg = NULL;
return;
}
}
else
rb = 0;
// 重来按钮
if (again_button.if_Mouse_On(msg))
{
ab = 1;
if (msg.uMsg == WM_LBUTTONUP)
{
clear();
read_Level();
}
}
else
ab = 0;
// 下一关按钮
if (next_button.if_Mouse_On(msg))
{
nb = 1;
if (msg.uMsg == WM_LBUTTONUP)
{
clear();
pasin++;
if (pasin > pass_num)
pasin = pass_num;
read_Level();
}
}
else
nb = 0;
}
times = int(time(NULL)) - start_time;
this->clear_Board();
this->draw_Title();
this->draw_Paper();
this->draw_Graph();
// 返回按钮
if (rb)
{
return_button.set_Image(image.return_Button(RGB(224 + 15, 197 + 15, 150 + 15)));
return_button.draw_Button();
}
else
{
return_button.set_Image(image.return_Button(RGB(224, 197, 150)));
return_button.draw_Button();
}
// 重来按钮
if (ab)
{
again_button.set_Image(image.again_Button(RGB(224 + 15, 197 + 15, 150 + 15)));
again_button.draw_Button();
}
else
{
again_button.set_Image(image.again_Button(RGB(224, 197, 150)));
again_button.draw_Button();
}
// 下一关按钮
if (nb)
{
next_button.set_Image(image.next_Button(RGB(224 + 15, 197 + 15, 150 + 15)));
next_button.draw_Button();
}
else
{
next_button.set_Image(image.next_Button(RGB(224, 197, 150)));
next_button.draw_Button();
}
}
FlushBatchDraw();
Sleep(1);
}
}
// 游戏界面
// 读取关卡
void CPlay::read_Level()
{
// 打开文件
wchar_t app_name[100];
swprintf_s(app_name, TEXT("Level%d"), pasin);
GetPrivateProfileString(app_name, TEXT("Record"), TEXT("--:--:--"), best_time, 100, TEXT(".\\Level.ini"));
// 读取点信息
this->point_num = GetPrivateProfileInt(app_name, TEXT("DotCount"), 0, TEXT(".\\Level.ini"));
for (int i = 1; i <= this->point_num; i++)
{
wchar_t name[100];
swprintf_s(name, TEXT("DotData%d"), i);
wchar_t dot_data[100];
GetPrivateProfileString(app_name, name, TEXT("0,0,0"), dot_data, 100, TEXT(".\\Level.ini"));
int m = 0;
swscanf_s(dot_data, TEXT("%d,%d,%d"), &my_point[i].x, &my_point[i].y, &m);
my_point[i].move = m;
if (my_point[i].x == 0)
my_point[i].x = rand() % PAPER_POINT_HEIGHT + 1;
if (my_point[i].y == 0)
my_point[i].y = rand() % PAPER_POINT_WIDTH + 1;
while (1)
{
if (!paper[my_point[i].x][my_point[i].y])
break;
my_point[i].x = rand() % PAPER_POINT_HEIGHT + 1;
my_point[i].y = rand() % PAPER_POINT_WIDTH + 1;
}
paper[my_point[i].x][my_point[i].y] = i;
my_point[i].x = my_point[i].x * DISLEN + BEGIN_Y;
my_point[i].y = my_point[i].y * DISLEN + BEGIN_X;
my_point_save[i].x = my_point[i].x;
my_point_save[i].y = my_point[i].y;
}
// 读取线信息
this->line_num = GetPrivateProfileInt(app_name, TEXT("LineCount"), 0, TEXT(".\\Level.ini"));
for (int i = 1; i <= this->line_num; i++)
{
wchar_t name[100];
swprintf_s(name, TEXT("LineData%d"), i);
wchar_t line_data[100];
GetPrivateProfileString(app_name, name, TEXT("0,0"), line_data, 100, TEXT(".\\Level.ini"));
swscanf_s(line_data, TEXT("%d,%d"), &my_line[i].a, &my_line[i].b);
}
}
// 读取关卡
// 绘制标题
void CPlay::draw_Title()
{
setbkmode(TRANSPARENT);
LOGFONT font;
gettextstyle(&font);
font.lfHeight = 35;
font.lfQuality = ANTIALIASED_QUALITY;
wcscpy_s(font.lfFaceName, TEXT("微软雅黑"));
settextstyle(&font);
settextcolor(TEXT_COLOR);
wchar_t info[100];
swprintf_s( info, TEXT("关卡-%d %lld:%lld:%lld 最佳:%s"),
pasin, times / 3600, times / 60, times % 60, best_time);
outtextxy( (WIN_WIDTH - textwidth(info)) / 2,
(BEGIN_Y - textheight(info)) / 2, info);
}
// 绘制标题
// 绘制纸盘
void CPlay::draw_Paper()
{
// 画背景
setfillcolor(RGB(215, 196, 137));
solidrectangle(BEGIN_X, BEGIN_Y, BEGIN_X + PAPER_WIDTH, BEGIN_Y + PAPER_HEIGHT);
// 画格点
setfillcolor(TEXT_COLOR);
for (int i = 1; i <= PAPER_POINT_HEIGHT; i++)
for (int j = 1; j <= PAPER_POINT_WIDTH; j++)
solidcircle(j * DISLEN + BEGIN_X, i * DISLEN + BEGIN_Y, PAPER_POINT_R);
}
// 绘制纸盘
// 绘制图
void CPlay::draw_Graph()
{
// 绘制线
setlinestyle(PS_SOLID, 3);
for (int i = 1; i <= this->line_num; i++)
{
bool cross = 0;
for (int j = 1; j <= this->line_num; j++)
{
if (j == i)
continue;
if (my_line[i].line_Cross(my_line[j]))
{
cross = 1;
break;
}
}
if (cross)
setlinecolor(BASE_COLOR);
else
setlinecolor(RGB(225, 225, 225));
line(my_point[my_line[i].a].y, my_point[my_line[i].a].x,
my_point[my_line[i].b].y, my_point[my_line[i].b].x);
}
// 绘制固定点
for (int i = 1; i <= this->point_num; i++)
if (!my_point[i].move)
{
setfillcolor(BASE_COLOR);
solidcircle(my_point[i].y, my_point[i].x, SMALL_POINT_R);
}
// 绘制可移且不正在移动点
for (int i = 1; i <= this->point_num; i++)
if (my_point[i].move && !point_flag[i])
{
for (int j = 1; j <= this->line_num; j++)
{
if (my_line[j].a != i && my_line[j].b != i)
continue;
bool cross = 0;
for (int k = 1; k <= this->line_num; k++)
{
if (j == k)
continue;
if (my_line[k].line_Cross(my_line[j]))
{
cros