📄 unboundmodedemomain.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdlib.h>
#include "shellapi.hpp"
#pragma hdrstop
#include "UnboundModeDemoMain.h"
#include "AboutDemoForm.h"
#include "UnboundModeDemoMinerCore.h"
#include "UnboundModeDemoCustomField.h"
#include "UnboundModeDemoFastestSweepers.h"
#include "ExtCtrls.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxClasses"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDBData"
#pragma link "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxLookAndFeels"
#pragma resource "*.dfm"
TUnboundModeDemoMainForm *UnboundModeDemoMainForm;
//---------------------------------------------------------------------------
__fastcall TUnboundModeDemoMainForm::TUnboundModeDemoMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miAboutClick(TObject *Sender)
{
ShowAboutDemoForm();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormShow(TObject *Sender)
{
miNewClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormCreate(TObject *Sender)
{
MinerField = new TMinerField();
FOnChangeGameDifficulty = MinerField->HandleEvChangeGameDifficulty;
IntMinerField = new TIntMinerField(this, MinerField);
IntMinerField->Parent = this;
IntMinerField->Visible = true;
FImageIndex = imSmile;
IntMinerField->Images = ilGame;
IntMinerField->OnImageChanged = HandleEvImageChanged;
IntMinerField->OnMineCountChanged = HandleMineCountChangedEvent;
IntMinerField->OnGameStatusChanged = HandleEvGameStatusChanged;
InitGameSettings();
ReadMinerSettings();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TRect Rct;
if(Button != mbLeft) return;
SetButtonBounds(Rct);
if(!IsPointInRect(Point(X, Y), Rct)) {
if(FImageIndex == 2) {
FImageIndex = 0;
DrawButton();
};
return;
}
if(!FMouseButtonPressed) {
FMouseButtonPressed = true;
FDown = true;
DrawButton();
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TRect Rct;
SetButtonBounds(Rct);
if(FMouseButtonPressed) {
if(!IsPointInRect(Point(X, Y), Rct)) {
FMouseButtonPressed = false;
DrawButton();
}
}
else {
if((IsPointInRect(Point(X, Y), Rct)) && (Shift == (TShiftState() << ssLeft)) && FDown) {
FMouseButtonPressed = true;
DrawButton();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TRect Rct;
FDown = false;
if(FImageIndex == 0) {
FImageIndex = 2;
DrawButton();
}
SetButtonBounds(Rct);
if(IsPointInRect(Point(X, Y), Rct))
if(FMouseButtonPressed) {
FMouseButtonPressed = false;
miNewClick(NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormDestroy(TObject *Sender)
{
WriteMinerSettings();
delete MinerField;
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormPaint(TObject *Sender)
{
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color =
SchemeColors[(int)IntMinerField->ColorScheme][cliBackground];
Canvas->FillRect(Rect(0, 0, Width, Height));
DrawOuterFrame();
DrawIndicatorBoard();
DrawTime();
DrawMineCount();
DrawButton();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::FormResize(TObject *Sender)
{
if(Left + Width > Screen->Width)
Left = Screen->Width - Width;
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color = clBlueSky;
Canvas->FillRect(Rect(0, 0, Width, Height));
FormPaint(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miNewClick(TObject *Sender)
{
FTime = 0;
Timer->Enabled = false;
FireGameDifficultyChangedEvent(FGameDifficulty);
FMineCount = FGameDifficulty.MineCount;
DrawMineCount();
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miBeginnerClick(
TObject *Sender)
{
FGameDifficulty.DifficultyType = dtBeginner;
miNewClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miIntermediateClick(
TObject *Sender)
{
FGameDifficulty.DifficultyType = dtIntermediate;
miNewClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miExpertClick(TObject *Sender)
{
FGameDifficulty.DifficultyType = dtExpert;
miNewClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miCustomClick(TObject *Sender)
{
TUnboundModeDemoCustomFieldForm* CustomField = new TUnboundModeDemoCustomFieldForm(this);
try {
CustomField->edtHeight->Text = IntToStr(FGameDifficulty.Height);
CustomField->edtWidth->Text = IntToStr(FGameDifficulty.Width);
CustomField->edtMineCount->Text = IntToStr(FGameDifficulty.MineCount);
if(CustomField->ShowModal() == mrOk) {
FGameDifficulty.Height = StrToInt(CustomField->edtHeight->Text);
FGameDifficulty.Width = StrToInt(CustomField->edtWidth->Text);
FGameDifficulty.MineCount = StrToInt(CustomField->edtMineCount->Text);
FGameDifficulty.DifficultyType = dtCustom;
miNewClick(Sender);
}
}
__finally {
delete CustomField;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miBestTimesClick(
TObject *Sender)
{
TUnboundModeDemoFastestSweepersForm* FastestSweepersForm = new TUnboundModeDemoFastestSweepersForm(this);
try {
FastestSweepersForm->lbBeginnerTime->Caption = IntToStr(FTimes[0]);
FastestSweepersForm->lbIntermediateTime->Caption = IntToStr(FTimes[1]);
FastestSweepersForm->lbExpertTime->Caption = IntToStr(FTimes[2]);
FastestSweepersForm->lbBeginnerName->Caption = FNames[0];
FastestSweepersForm->lbIntermediateName->Caption = FNames[1];
FastestSweepersForm->ibExpertName->Caption = FNames[2];
FastestSweepersForm->ShowModal();
if(FastestSweepersForm->FastestTimesResetted)
ResetFastestTimes();
}
__finally {
delete FastestSweepersForm;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miMarksClick(TObject *Sender)
{
((TMenuItem*)Sender)->Checked = !((TMenuItem*)Sender)->Checked;
IntMinerField->QuestionMarkCell = ((TMenuItem*)Sender)->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miBlueClick(
TObject *Sender)
{
if(IntMinerField->ColorScheme != csBlue) {
IntMinerField->ColorScheme = csBlue;
FormPaint(this);
((TMenuItem*)Sender)->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miGreenClick(
TObject *Sender)
{
if(IntMinerField->ColorScheme != csGreen) {
IntMinerField->ColorScheme = csGreen;
FormPaint(this);
((TMenuItem*)Sender)->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miSystemClick(
TObject *Sender)
{
if(IntMinerField->ColorScheme != csSystem) {
IntMinerField->ColorScheme = csSystem;
FormPaint(this);
((TMenuItem*)Sender)->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::miGoldClick(
TObject *Sender)
{
if(IntMinerField->ColorScheme != csGold) {
IntMinerField->ColorScheme = csGold;
FormPaint(this);
((TMenuItem*)Sender)->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TUnboundModeDemoMainForm::HandleMineCountChangedEvent(TObject* Sender, TMineCountChangedEventType AMineCountChangedEventType)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -