📄 mainform.cpp
字号:
{
int value = GridArray[_Index(i,j,GridCol)].value;
int & view = GridArray[_Index(i,j,GridCol)].view;
if (value == -1) {
if (view == b_Blank) view = b_Bomb;
if (view == b_Blank_Down) view = b_Exploded;
} else if (view == b_Flag)
{
view = b_Wrong;
}
DrawBlock(i,j,view);
}
}
}
//###########################################################################
void TMainWin::GameWin()
{
if (isHaveSound) {
sndPlaySound(g_Win_SoundPath, SND_ASYNC );
}
GameTimer->Enabled = false;
ChangeFace(f_Win);
GameStatus = g_Gameover;
LeftBombCount = 0;
DrawNumber(Image_Left,0);
for (int i=0; i<GridCol; ++i)
{
for (int j=0; j<GridRow; ++j)
{
int status = GridArray[_Index(i,j,GridCol)].status;
if (status != s_Opened)
{
DrawBlock(i,j,b_Flag);
GridArray[_Index(i,j,GridCol)].view = b_Flag;
}
}
}
}
//###########################################################################
/***************************************************************************/
void TMainWin::LeftBtnDown(int col, int row)
{
int & view = GridArray[row*GridCol + col].view;
if (view == b_Blank) view = b_Blank_Down;
if (view == b_QuestionMark) view = b_QuestionMark_Down;
DrawBlock(col, row, view);
}
/***************************************************************************/
void TMainWin::LeftBtnMoveOut(int col, int row)
{
int & view = GridArray[row*GridCol + col].view;
int & status = GridArray[row*GridCol + col].status;
if (view==b_Blank_Down && status!=s_Opened) view = b_Blank;
if (view == b_QuestionMark_Down) view = b_QuestionMark;
DrawBlock(col, row, view);
}
/***************************************************************************/
void TMainWin::LeftBtnUp(int col, int row)
{
int index = _Index(col,row,GridCol);
int & view = GridArray[index].view;
int & value = GridArray[index].value;
int & status = GridArray[index].status;
if (view==b_Blank
|| view==b_QuestionMark
|| view==b_Blank_Down
|| view==b_QuestionMark_Down)
{
if (value == -1) {
GameLost();
} else if (value == 0)
{
SearchBlankBlock(col,row);
} else if (status!=s_Opened) {
view = 15 - value;
DrawBlock(col, row, view);
status = s_Opened;
++BlockOpenCount;///////////////////////
}
}
}
/***************************************************************************/
void TMainWin::RightBtnDown(int col, int row)
{
int & view = GridArray[ _Index(col,row,GridCol) ].view;
if (view == b_Blank)
{
view = b_Flag;
--LeftBombCount;
}
else if (view == b_QuestionMark)
{
view = b_Blank;
}
else if (view == b_Flag)
{
view = isHaveQuestionMark ? b_QuestionMark : b_Blank;
++LeftBombCount;
}
DrawNumber(Image_Left, LeftBombCount);
DrawBlock(col, row, view);
}
/***************************************************************************/
void TMainWin::LeftAndRightBtnDown(int col, int row)
{
int x, y;
for (int i=0; i<9; ++i)
{
x = col + DIR[i].x; y = row + DIR[i].y;
if (x<0 || x>=GridCol || y<0 || y>=GridRow) continue;
LeftBtnDown(x,y);
}
}
/***************************************************************************/
void TMainWin::LeftAndRightBtnMoveOut(int col, int row)
{
int x, y;
for (int i=0; i<9; ++i)
{
x = col + DIR[i].x; y = row + DIR[i].y;
if (x<0 || x>=GridCol || y<0 || y>=GridRow) continue;
int & view = GridArray[_Index(x,y,GridCol)].view;
int status = GridArray[_Index(x,y,GridCol)].status;
if (view==b_Blank_Down && status!=s_Opened) view = b_Blank;
else if (view==b_QuestionMark_Down) view = b_QuestionMark;
DrawBlock(x,y,view);
}
}
/***************************************************************************/
void TMainWin::LeftAndRightBtnUp(int col, int row)
{
int value = GridArray[_Index(col,row,GridCol)].value;
int & status = GridArray[_Index(col,row,GridCol)].status;
if (status==s_Opened && value>0)
{
int marked_num = 0;
for (int i=0; i<8; ++i)
{
int x = col + DIR[i].x;
int y = row + DIR[i].y;
if (x<0 || x>=GridCol || y<0 || y>=GridRow) continue;
if (GridArray[_Index(x,y,GridCol)].view == b_Flag)
{
++marked_num;
}
}
if (marked_num == value) {
for (int i=0; i<8; ++i)
{
int x = col + DIR[i].x;
int y = row + DIR[i].y;
if (x<0 || x>=GridCol || y<0 || y>=GridRow) continue;
LeftBtnUp(x,y);
}
}
else {
LeftAndRightBtnMoveOut(col,row);
}
}
else
{
LeftAndRightBtnMoveOut(col,row);
}
}
/***************************************************************************/
void TMainWin::ProcHeroName()
{
TLabel *label;
struct _hero * p;
switch (GameLevel)
{
case l_Easy:
if (UsedTime < hero[0].time) {
hero[0].time = UsedTime;
HeroForm->Label_Easy_Seconds->Caption = UsedTime;
HeroNameForm->Label_Hint->Caption = "已破初级记录。";
label = HeroForm->Label_Easy_Name;
p = & hero[0];
} else {
return;
}
break;
case l_Middle:
if (UsedTime < hero[1].time) {
hero[1].time = UsedTime;
HeroForm->Label_Middle_Seconds->Caption = UsedTime;
HeroNameForm->Label_Hint->Caption = "已破中级记录。";
label = HeroForm->Label_Middle_Name;
p = & hero[1];
} else {
return;
}
break;
case l_Expert:
if (UsedTime < hero[2].time) {
hero[2].time = UsedTime;
HeroForm->Label_Expert_Seconds->Caption = UsedTime;
HeroNameForm->Label_Hint->Caption = "已破高级记录。";
label = HeroForm->Label_Expert_Name;
p = & hero[2];
} else {
return;
}
break;
case l_Professional:
if (UsedTime < hero[3].time) {
hero[3].time = UsedTime;
HeroForm->Label_Professional_Seconds->Caption = UsedTime;
HeroNameForm->Label_Hint->Caption = "已破猛级记录。";
label = HeroForm->Label_Professional_Name;
p = & hero[3];
} else {
return;
}
break;
default:
return;
}
HeroNameForm->Left = MainWin->Left + 2;
HeroNameForm->Top = MainWin->Top + MainWin->Panel_Top->Height + 42;
HeroNameForm->ShowModal();
if (HeroNameForm->Edit_Name->Text == "")
{
HeroNameForm->Edit_Name->Text = "匿名";
}
p->name = HeroNameForm->Edit_Name->Text;
label->Caption = p->name;
N_HeroClick(NULL);
}
/***************************************************************************/
__fastcall TMainWin::TMainWin(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::FormCreate(TObject *)
{
randomize();
for (int i=0;i<4;++i) {
hero[i].time = 999;
hero[i].name = "匿名";
}
Xpos = Left; Ypos = Top;
ReadRegister();
Left = Xpos; Top = Ypos;
if (isHaveSound) {
N_Sound->Checked = true;
} else {
N_Sound->Checked = false;
}
if (isHaveQuestionMark) {
N_Mark->Checked = true;
} else {
N_Mark->Checked = false;
}
if (isHaveColor) {
N_Color->Checked = true;
Image_Block = Image_Color_Block;
Image_Number = Image_Color_Number;
Image_Face = Image_Color_Face;
} else {
N_Color->Checked = false;
Image_Block = Image_Gray_Block;
Image_Number = Image_Gray_Number;
Image_Face = Image_Gray_Face;
}
SetGameLevel(GameLevel,GridCol,GridRow,BombCount);
Panel_Bottom->DoubleBuffered = true;
Panel_Top->DoubleBuffered = true;
Application->Title = "扫雷";
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::N11Click(TObject *)
{
InitGridArray(GridCol,GridRow,BombCount,TPoint(0,0));
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::Image_MiddleMouseDown(TObject *,
TMouseButton Button, TShiftState , int , int )
{
if (Button == mbLeft) {
ChangeFace(f_Smile_Down);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_MiddleMouseUp(TObject *Sender,
TMouseButton Button, TShiftState , int , int )
{
if (Button == mbLeft)
{
ChangeFace(f_Smile);
N_StartupClick(Sender);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Panel_TopMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
if (Button == mbLeft)
{
ChangeFace(f_O);
}
Image_MainMouseDown(Sender,Button,Shift,X-Image_Main->Left,Y-Image_Main->Top-Panel_Bottom->Top);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Panel_TopMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Image_MainMouseMove(Sender,Shift,X-Image_Main->Left,Y-Image_Main->Top-Panel_Bottom->Top);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Panel_TopMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
ChangeFace(f_Smile);
Image_MainMouseUp(Sender,Button,Shift,X-Image_Main->Left,Y-Image_Main->Top-Panel_Bottom->Top);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_LeftMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseDown(
Sender,
Button,
Shift,
X+Panel_Left->Left+Image_Left->Left,
Y+Panel_Left->Top+Image_Left->Top
);
}
//---------------------------------------------------------------------------
void __fastcall TMainWin::Image_LeftMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if (GameStatus == g_Gameover)
{
return;
}
Panel_TopMouseMove(
Sender,
Shift,
X+Panel_Left->Left+Image_Left->Left,
Y+Panel_Left->Top+Image_Left->Top
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -