📄 unboundmodedemomain.cpp
字号:
{
switch (AMineCountChangedEventType) {
case mcIncMineCount: FMineCount++; break;
case mcDecMineCount: FMineCount--; break;
}
DrawMineCount();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::HandleEvGameStatusChanged(TObject* Sender, TGameStatus AGameStatus, const TGameDifficulty &AGameDifficulty)
{
switch (AGameStatus) {
case gsNew: {
FGameDifficulty = AGameDifficulty;
FImageIndex = 2;
FTime = 0;
Timer->Enabled = false;
FMineCount = FGameDifficulty.MineCount;
CheckMenuItem(FGameDifficulty.DifficultyType);
OnPaint(this);
}; break;
case gsRun: {
// Timer on
Timer->Enabled = true;
TimerTimer(this);
}; break;
case gsLost: {
FImageIndex = 1;
OnPaint(this);
// Timer off
Timer->Enabled = false;
}; break;
case gsWon: {
Timer->Enabled = false;
FImageIndex = 3;
FMineCount = 0;
OnPaint(this);
CheckBestTimes();
}; break;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::HandleEvImageChanged(TObject* Sender, int AImageIndex)
{
switch(AImageIndex) {
case imSmile: FImageIndex = 2; break;
case imAstonisment: FImageIndex = 0; break;
case imWon: FImageIndex = 3; break;
case imLost: FImageIndex = 1; break;
}
DrawButton();
}
//---------------------------------------------------------------------------
bool __fastcall TUnboundModeDemoMainForm::IsPointInRect(TPoint APoint, TRect ARect)
{
return ((ARect.Left <= APoint.x) && (APoint.x <= ARect.Right) &&
(ARect.Top <= APoint.y) && (APoint.y <= ARect.Bottom));
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::SetButtonBounds(TRect &ARect)
{
int AButtonXPos = (Width >> 1) - (biButtonWidth >> 1);
ARect = Rect(AButtonXPos, psBoardInnerIndent,
AButtonXPos + biButtonWidth, psBoardInnerIndent + biButtonWidth);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FireGameDifficultyChangedEvent(const TGameDifficulty ANewGameDifficulty)
{
if (FOnChangeGameDifficulty != NULL)
FOnChangeGameDifficulty(this, ANewGameDifficulty);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::DrawMineCount()
{
TArrInteger mCount;
if (FMineCount >=0)
MakeArrayFromInt(FMineCount, mCount, biMineDigitCount);
else {
MakeArrayFromInt(abs(FMineCount), mCount, biMineDigitCount);
mCount[biMineDigitCount - 1] = 10; // minus
}
TRect Rct = Rect(psBoardInnerIndent, psBoardInnerIndent,
psBoardInnerIndent + biMineDigitCount * ilNumbers->Width + 2*biCountersBorderWidth,
biNumberHeight + 2*biCountersBorderWidth);
Frame3D(Canvas, Rct,
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor],
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dBottomColor],
biCountersBorderWidth);
for(int i=0; i < biMineDigitCount; i++)
ilNumbers->Draw(Canvas, Rct.Left + ilNumbers->Width * i, Rct.Top, mCount[biMineDigitCount - 1 - i], true);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::DrawTime()
{
TArrInteger tArr;
MakeArrayFromInt(FTime, tArr, biTimerDigitCount);
int ATimerWidth = biTimerDigitCount * ilNumbers->Width + 2 * biCountersBorderWidth;
TRect Rct = Rect(ClientWidth - ATimerWidth - psBoardInnerIndent,
psBoardInnerIndent, ClientWidth - psBoardInnerIndent,
biNumberHeight + 2 * biCountersBorderWidth);
Frame3D(Canvas, Rct,
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor],
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dBottomColor],
biCountersBorderWidth);
for (int i=0; i < biTimerDigitCount; i++)
ilNumbers->Draw(Canvas, Rct.Left + ilNumbers->Width * i, Rct.Top, tArr[biTimerDigitCount - 1 - i], true);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::DrawButton()
{
TRect Rct, RctBk, RctPressed;
SetButtonBounds(Rct);
Canvas->Brush->Style = bsSolid;
RctBk.Left = Rct.Left - 1;
RctBk.Top = Rct.Top - 1;
RctBk.Right = Rct.Right + 1;
RctBk.Bottom = Rct.Bottom + 1;
Canvas->Brush->Color = SchemeColors[(int)IntMinerField->ColorScheme][cliButtonColor];
Canvas->FillRect(Rect(RctBk.Left, RctBk.Top, RctBk.Right + 1, RctBk.Bottom + 1));
Canvas->Brush->Color =
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor];
Canvas->FrameRect(RctBk);
if(!FMouseButtonPressed) {
Frame3D(Canvas, Rct,
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dBottomColor],
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor], 2);
ilFaces->Draw(Canvas, Rct.Left + 1, Rct.Top + 1, FImageIndex, true);
}
else {
RctPressed.Left = RctBk.Left + 1;
RctPressed.Top = RctBk.Top + 1;
RctPressed.Right = RctBk.Right + 1;
RctPressed.Bottom = RctBk.Bottom + 1;
Canvas->FrameRect(RctPressed);
Canvas->Brush->Color = SchemeColors[(int)IntMinerField->ColorScheme][8];
Canvas->FillRect(
Rect(RctPressed.Left + 1, RctPressed.Top + 1, RctPressed.Right - 1, RctPressed.Bottom-1));
ilFaces->Draw(Canvas, Rct.Left + 4, Rct.Top + 4 , 2, true);
};
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::DrawIndicatorBoard()
{
TRect Rct = Rect(psBorder, psBorder,
(ClientWidth - (psBorder - psOuterFrameWidth)), biBoardHeight);
Frame3D(Canvas, Rct,
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor],
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dBottomColor], 2);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::DrawOuterFrame()
{
TRect Rct = Rect(1, 1, Width, Height);
Frame3D(Canvas, Rct,
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dTopColor],
SchemeColors[(int)IntMinerField->ColorScheme][cliFrame3dBottomColor],
psOuterFrameWidth);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::ReadMinerSettings()
{
TRegistry* Registry = new TRegistry();
try {
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey(Section, False);
if(Registry->ValueExists(Difficulty)) {
int Diff = Registry->ReadInteger(Difficulty);
if ((Diff >= 0) && (Diff <= 3))
FGameDifficulty.DifficultyType = TDifficultyType(Diff);
else
FGameDifficulty.DifficultyType = dtBeginner;
};
if(FGameDifficulty.DifficultyType == dtCustom) {
if(Registry->ValueExists("Width"))
FGameDifficulty.Width = Registry->ReadInteger(UnboundModeDemoTypesH::Width);
if(Registry->ValueExists("Height"))
FGameDifficulty.Height = Registry->ReadInteger(UnboundModeDemoTypesH::Height);
if(Registry->ValueExists("MineCount"))
FGameDifficulty.MineCount = Registry->ReadInteger(MineCount);
};
if(Registry->ValueExists(UnboundModeDemoTypesH::Mark))
Registry->ReadInteger(UnboundModeDemoTypesH::Mark);
if(Registry->ValueExists(Name1))
FNames[0] = Registry->ReadString(Name1);
if(Registry->ValueExists(Name2))
FNames[1] = Registry->ReadString(Name2);
if(Registry->ValueExists(Name3))
FNames[2] = Registry->ReadString(Name3);
if(Registry->ValueExists(Time1))
FTimes[0] = Registry->ReadInteger(Time1);
if(Registry->ValueExists(Time2))
FTimes[1] = Registry->ReadInteger(Time2);
if(Registry->ValueExists(Time3))
FTimes[2] = Registry->ReadInteger(Time3);
}
__finally {
Registry->CloseKey();
delete Registry;
};
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::WriteMinerSettings()
{
TRegistry* Registry = new TRegistry();
try {
Registry->RootKey = HKEY_CURRENT_USER;
if(!Registry->OpenKey(Section, false)) {
Registry->CreateKey(Section);
Registry->OpenKey(Section, false);
};
Registry->WriteInteger(Difficulty, (int)FGameDifficulty.DifficultyType);
Registry->WriteInteger("Width", FGameDifficulty.Width);
Registry->WriteInteger("Height", FGameDifficulty.Height);
Registry->WriteInteger("MineCount", FGameDifficulty.MineCount);
Registry->WriteInteger(UnboundModeDemoTypesH::Mark, 1);
for(int i=0; i < 3; i++) {
Registry->WriteString("Name" + IntToStr(i+1), FNames[i]);
Registry->WriteInteger("Time" + IntToStr(i+1), FTimes[i]);
};
}
__finally {
Registry->CloseKey();
delete Registry;
};
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::InitGameSettings()
{
FGameDifficulty.DifficultyType = dtBeginner;
ResetFastestTimes();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::ResetFastestTimes()
{
for(int i=0; i < 3; i++) {
FTimes[i] = 999;
FNames[i] = "Anonymous";
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::CheckBestTimes()
{
String Level;
if (FGameDifficulty.DifficultyType == dtCustom)
return;
if (FTimes[(int)FGameDifficulty.DifficultyType] > FTime) {
switch (FGameDifficulty.DifficultyType) {
case dtBeginner: Level = "beginner"; break;
case dtIntermediate: Level = "intermediate"; break;
case dtExpert: Level = "expert"; break;
}
FTimes[(int)FGameDifficulty.DifficultyType] = FTime;
FNames[(int)FGameDifficulty.DifficultyType] = InputBox("You are the champion in the "+ Level+" level", "Please enter your name.",
FNames[(int)FGameDifficulty.DifficultyType]);
miBestTimesClick(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::CheckMenuItem(TDifficultyType AGameDifficulty)
{
switch(AGameDifficulty) {
case dtBeginner: miBeginner->Checked = true; break;
case dtIntermediate: miIntermediate->Checked = true; break;
case dtExpert: miExpert->Checked = true; break;
case dtCustom: miCustom->Checked = true; break;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::TimerTimer(TObject *Sender)
{
if (FTime < 999) FTime++;
DrawTime();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -