📄 mainform.cpp
字号:
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_LeftMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseUp(
Sender,
Button,
Shift,
X+Panel_Left->Left+Image_Left->Left,
Y+Panel_Left->Top+Image_Left->Top
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_RightMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseDown(
Sender,
Button,
Shift,
X + Panel_Right->Left + Image_Right->Left,
Y + Panel_Right->Top + Image_Right->Top
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_RightMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseMove(
Sender,
Shift,
X + Panel_Right->Left + Image_Right->Left,
Y + Panel_Right->Top + Image_Right->Top
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_RightMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseUp(
Sender,
Button,
Shift,
X + Panel_Right->Left + Image_Right->Left,
Y + Panel_Right->Top + Image_Right->Top
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_MainMouseDown(TObject *,
TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
TKeyboardState keystate;
TPoint p;
GetKeyboardState(keystate);
if ((keystate[VK_LBUTTON]&0x80) && (keystate[VK_RBUTTON]&0x80)) {
isLeftAndRightBtnDown = true;
} else {
isLeftAndRightBtnDown = false;
}
if (keystate[VK_LBUTTON] & 0x80) {
isLeftBtnDown = true;
} else {
isLeftBtnDown = false;
}
if (keystate[VK_RBUTTON] & 0x80) {
isRightBtnDown = true;
} else {
isRightBtnDown = false;
}
p = ChangePixelToBlock(Point(X,Y));
if (p.x<0 || p.x>=GridCol ||p.y<0 || p.y>=GridRow)
{
if (Button == mbLeft) isLeftBtnDown = true;
if (Button == mbRight) isRightBtnDown == true;
return;
}
CurrentPosition = p;
if (isLeftAndRightBtnDown)
{
ChangeFace(f_O);
LeftAndRightBtnDown(p.x, p.y);
return;
}
if (Button == mbLeft)
{
ChangeFace(f_O);
LeftBtnDown(p.x, p.y);
}
else if (Button == mbRight)
{
RightBtnDown(p.x, p.y);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_MainMouseMove(TObject *,
TShiftState , int X, int Y)
{
TPoint p;
if (GameStatus == g_Gameover)
{
return;
}
p = ChangePixelToBlock(Point(X,Y));
if (p.x==CurrentPosition.x && p.y==CurrentPosition.y) return;
if (isLeftAndRightBtnDown)
{
LeftAndRightBtnMoveOut(CurrentPosition.x,CurrentPosition.y);
CurrentPosition = p;
if (!(p.x<0 || p.x>=GridCol || p.y<0 || p.y>=GridRow))
{
LeftAndRightBtnDown(p.x,p.y);
}
}
else if (isLeftBtnDown)
{
LeftBtnMoveOut(CurrentPosition.x,CurrentPosition.y);
CurrentPosition = p;
if (!(p.x<0 || p.x>=GridCol || p.y<0 || p.y>=GridRow))
{
LeftBtnDown(p.x,p.y);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_MainMouseUp(TObject *,
TMouseButton Button, TShiftState , int X, int Y)
{
TPoint p;
if (GameStatus == g_Gameover)
{
return;
}
p = ChangePixelToBlock(Point(X,Y));
if (p.x<0 || p.x>=GridCol ||p.y<0 || p.y>=GridRow) //out of renge
{
if (Button == mbLeft) {
isLeftBtnDown = false;
isLeftAndRightBtnDown = false;
}
if (Button == mbRight) {
isRightBtnDown == false;
isLeftAndRightBtnDown = false;
}
return;
};
ChangeFace(f_Smile);
if (Button == mbLeft)
{
if (GameStatus == g_Waiting)
{
GameStatus = g_Sweeping;
InitGridArray(GridCol,GridRow,BombCount,p);
UsedTime = 1;
DrawNumber(Image_Right,UsedTime);
GameTimer->Enabled = true;
}
if (isRightBtnDown) {
LeftAndRightBtnUp(p.x,p.y);
} else if (isLeftBtnDown) {
LeftBtnUp(p.x, p.y);
}
isRightBtnDown = false;
isLeftBtnDown = false;
isLeftAndRightBtnDown = false;
}
if (Button == mbRight)
{
if (isLeftBtnDown)
{
LeftAndRightBtnUp(p.x,p.y);
}
isLeftBtnDown = false;
isRightBtnDown =false;
isLeftAndRightBtnDown =false;
}
if (BlockOpenCount == (GridCol*GridRow-BombCount))
{
GameWin();
ProcHeroName();
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_StartupClick(TObject *)
{
GameTimer->Enabled = false;
for (int i=0; i<GridCol*GridRow; ++i)
{
GridArray[i].value = 0;
GridArray[i].view = b_Blank;
GridArray[i].status = s_Default;
}
BlockOpenCount = 0;
LeftBombCount = BombCount;
UsedTime = 0;
CurrentFace = f_Smile;
DrawGame(GridCol,GridRow);
GameStatus = g_Waiting;
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N24Click(TObject *)
{
for (int i=0; i<GridCol; ++i)
{
for (int j=0; j<GridRow; ++j)
{
int value = GridArray[j*GridCol +i].value;
if (value >= 0)
DrawBlock(i,j,15-value);
else DrawBlock(i,j,b_Flag);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_MarkClick(TObject *)
{
isHaveQuestionMark = !isHaveQuestionMark;
N_Mark->Checked = isHaveQuestionMark;
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_ColorClick(TObject *)
{
isHaveColor = !isHaveColor;
N_Color->Checked = isHaveColor;
if (isHaveColor)
{
Image_Block = Image_Color_Block;
Image_Face = Image_Color_Face;
Image_Number = Image_Color_Number;
}
else
{
Image_Block = Image_Gray_Block;
Image_Face = Image_Gray_Face;
Image_Number = Image_Gray_Number;
}
DrawGame(GridCol,GridRow);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::FormClose(TObject *, TCloseAction &)
{
Xpos = Left; Ypos = Top;
WriteRegister();
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_SoundClick(TObject *)
{
isHaveSound = !isHaveSound;
N_Sound->Checked = isHaveSound;
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_Level_EasyClick(TObject *)
{
SetGameLevel(l_Easy);
N_StartupClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_Level_MiddleClick(TObject *)
{
SetGameLevel(l_Middle);
N_StartupClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_Level_ExpertClick(TObject *)
{
SetGameLevel(l_Expert);
N_StartupClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_Level_ProfessionalClick(TObject *)
{
SetGameLevel(l_Professional);
N_StartupClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_Level_CustomizeClick(TObject *)
{
LevelForm->Left = MainWin->Left + 2;
LevelForm->Top = MainWin->Top + MainWin->Panel_Top->Height + 2;
LevelForm->Edit_Height->Text = IntToStr( GridRow );
LevelForm->Edit_Width->Text = IntToStr( GridCol );
LevelForm->Edit_Mines->Text = IntToStr( BombCount );
LevelForm->ShowModal();
SetGameLevel(l_Customize,GridCol,GridRow,BombCount);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::GameTimerTimer(TObject *)
{
if (isHaveSound) {
sndPlaySound(g_Second_SoundPath, SND_ASYNC );
}
if (UsedTime >= 999) {
UsedTime = 999;
} else {
++UsedTime;
}
DrawNumber(Image_Right, UsedTime);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_HeroClick(TObject *)
{
HeroForm->Left = MainWin->Left + 2;
HeroForm->Top = MainWin->Top + MainWin->Panel_Top->Height + 42;
HeroForm->Label_Easy_Name->Caption = hero[0].name;
HeroForm->Label_Easy_Seconds->Caption = IntToStr(hero[0].time);
HeroForm->Label_Middle_Name->Caption = hero[1].name;
HeroForm->Label_Middle_Seconds->Caption = IntToStr(hero[1].time);
HeroForm->Label_Expert_Name->Caption = hero[2].name;
HeroForm->Label_Expert_Seconds->Caption = IntToStr(hero[2].time);
HeroForm->Label_Professional_Name->Caption = hero[3].name;
HeroForm->Label_Professional_Seconds->Caption = IntToStr(hero[3].time);
HeroForm->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N31Click(TObject *)
{
HeroNameForm->Left = MainWin->Left + 2;
HeroNameForm->Top = MainWin->Top + MainWin->Panel_Top->Height + 42;
HeroNameForm->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N_QuitClick(TObject *)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N18Click(TObject *)
{
ShellExecute(Application->Handle,"OPEN",g_ChmFile_Path,NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N16Click(TObject *)
{
ShellExecute(Application->Handle,"OPEN",g_ChmFile_Path,NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::H1Click(TObject *)
{
ShellExecute(Application->Handle,"OPEN",g_SysHelpFile_Path,NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N17Click(TObject *)
{
AboutForm->ShowModal();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -