Лабораторные работы: пятнашки и редактор фигур

This commit is contained in:
DverkuOff 2026-11-25 08:31:11 +03:00
commit a5dbf9d3a2

92
MenuUnit.cpp Normal file
View file

@ -0,0 +1,92 @@
#include <vcl.h>
#pragma hdrstop
#include "MenuUnit.h"
#include "GameUnit.h"
#include "ShapesUnit.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMenu *frmMenu;
__fastcall TfrmMenu::TfrmMenu(TComponent* Owner) : TForm(Owner)
{
}
void __fastcall TfrmMenu::FormCreate(TObject *Sender)
{
DrawIcons();
}
// значки 32x32 для кнопок меню
void TfrmMenu::DrawIcons()
{
for (int i = 0; i < 3; i++)
{
Vcl::Graphics::TBitmap *bmp = new Vcl::Graphics::TBitmap();
bmp->SetSize(32, 32);
TCanvas *c = bmp->Canvas;
c->Brush->Color = clFuchsia;
c->FillRect(Rect(0, 0, 32, 32));
c->Pen->Width = 1;
if (i == 0)
{
// поле 2x2 с одной пустой клеткой
c->Pen->Color = (TColor)RGB(44, 62, 80);
c->Brush->Color = (TColor)RGB(44, 62, 80);
c->RoundRect(1, 1, 31, 31, 6, 6);
c->Brush->Color = (TColor)RGB(236, 240, 241);
c->Pen->Color = (TColor)RGB(236, 240, 241);
c->RoundRect(4, 4, 15, 15, 4, 4);
c->RoundRect(17, 4, 28, 15, 4, 4);
c->RoundRect(4, 17, 15, 28, 4, 4);
}
if (i == 1)
{
// треугольник и круг
c->Pen->Color = clBlack;
c->Brush->Color = (TColor)RGB(255, 167, 38);
TPoint p[3] = { TPoint(11, 3), TPoint(21, 21), TPoint(1, 21) };
c->Polygon(p, 2);
c->Brush->Color = (TColor)RGB(66, 103, 178);
c->Ellipse(13, 13, 31, 31);
}
if (i == 2)
{
// значок "i"
c->Pen->Color = (TColor)RGB(0, 137, 123);
c->Brush->Color = (TColor)RGB(0, 137, 123);
c->Ellipse(1, 1, 31, 31);
c->Font->Name = "Georgia";
c->Font->Size = 15;
c->Font->Style = TFontStyles() << fsBold;
c->Font->Color = clWhite;
c->Brush->Style = bsClear;
c->TextOut(16 - c->TextWidth("i") / 2, 16 - c->TextHeight("i") / 2, "i");
}
imgButtons->AddMasked(bmp, clFuchsia);
delete bmp;
}
btnGame->ImageIndex = 0;
btnShapes->ImageIndex = 1;
btnAbout->ImageIndex = 2;
}
void __fastcall TfrmMenu::btnGameClick(TObject *Sender)
{
frmGame->ShowModal();
}
void __fastcall TfrmMenu::btnShapesClick(TObject *Sender)
{
frmShapes->ShowModal();
}
void __fastcall TfrmMenu::btnAboutClick(TObject *Sender)
{
String s = L"Лабораторные работы по дисциплине «Программирование»\n\n"
L"1. Игра «Пятнашки»\n"
L"2. Редактор «Фигуры»\n\n"
L"Среда: Embarcadero C++Builder, VCL\n\n" + lblAuthor->Caption;
Application->MessageBox(s.c_str(), L"О программе", MB_OK | MB_ICONINFORMATION);
}