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

This commit is contained in:
DverkuOff 2026-11-25 08:31:11 +03:00
commit a5dbf9d3a2
29 changed files with 2579 additions and 0 deletions

23
.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
# сборка C++Builder
Win32/
Win64/
Win64x/
__history/
__recovery/
*.local
*.identcache
*.res
*.obj
*.o
*.pch
*.#*
*.~*
*.tds
*.ilc
*.ild
*.ilf
*.ils
*.map
*.stat
*.dsk
.DS_Store

92
BaseFigure.cpp Normal file
View file

@ -0,0 +1,92 @@
#include <vcl.h>
#pragma hdrstop
#include "BaseFigure.h"
#pragma package(smart_init)
int InRange(int v, int a, int b)
{
if (v < a) return a;
if (v > b) return b;
return v;
}
TFigure::TFigure(int aNum)
{
num = aNum;
x = 0;
y = 0;
w = 110;
h = 90;
fillColor = clWhite;
lineColor = clBlack;
}
TFigure::~TFigure()
{
}
int TFigure::GetNum() { return num; }
int TFigure::GetX() { return x; }
int TFigure::GetY() { return y; }
int TFigure::GetW() { return w; }
int TFigure::GetH() { return h; }
TColor TFigure::GetFill() { return fillColor; }
TColor TFigure::GetLine() { return lineColor; }
// здесь проверяются все границы, снаружи поля напрямую не меняются
void TFigure::SetBounds(int ax, int ay, int aw, int ah)
{
x = InRange(ax, POS_MIN, POS_MAX);
y = InRange(ay, POS_MIN, POS_MAX);
w = InRange(aw, SIDE_MIN, SIDE_MAX);
h = InRange(ah, SIDE_MIN, SIDE_MAX);
}
void TFigure::MoveTo(int ax, int ay)
{
SetBounds(ax, ay, w, h);
}
void TFigure::SetFill(TColor c)
{
fillColor = c;
}
void TFigure::SetLine(TColor c)
{
lineColor = c;
}
void TFigure::SetupCanvas(TCanvas *c)
{
c->Pen->Style = psSolid;
c->Pen->Width = 2;
c->Pen->Color = lineColor;
c->Brush->Style = bsSolid;
c->Brush->Color = fillColor;
}
// номер в центре: на тёмной заливке белый, на светлой чёрный
void TFigure::PaintNumber(TCanvas *c)
{
int rgb = ColorToRGB(fillColor);
int r = GetRValue(rgb);
int g = GetGValue(rgb);
int b = GetBValue(rgb);
int bright = (r * 3 + g * 6 + b) / 10;
if (bright < 130)
c->Font->Color = clWhite;
else
c->Font->Color = clBlack;
c->Font->Name = "Verdana";
c->Font->Size = 11;
c->Font->Style = TFontStyles() << fsBold;
String s = IntToStr(num);
int tx = x + (w - c->TextWidth(s)) / 2;
int ty = y + (h - c->TextHeight(s)) / 2;
c->Brush->Style = bsClear;
c->TextOut(tx, ty, s);
c->Brush->Style = bsSolid;
}

51
BaseFigure.h Normal file
View file

@ -0,0 +1,51 @@
// Базовый (абстрактный) класс фигуры
#ifndef BaseFigureH
#define BaseFigureH
#include <vcl.h>
// ограничения из задания
const int SIDE_MIN = 20;
const int SIDE_MAX = 1000;
const int POS_MIN = -2000;
const int POS_MAX = 10000;
int InRange(int v, int a, int b);
class TFigure
{
protected:
int num; // номер фигуры
int x, y; // левый верхний угол
int w, h; // ширина и высота
TColor fillColor; // цвет заливки
TColor lineColor; // цвет обводки
void SetupCanvas(TCanvas *c);
void PaintNumber(TCanvas *c);
public:
TFigure(int aNum);
virtual ~TFigure();
// чисто виртуальные методы - их переопределяют наследники
virtual void Draw(TCanvas *c) = 0;
virtual bool Contains(int px, int py) = 0;
virtual String TypeName() = 0; // имя для файла
virtual String RusName() = 0; // имя для меню
int GetNum();
int GetX();
int GetY();
int GetW();
int GetH();
TColor GetFill();
TColor GetLine();
void SetBounds(int ax, int ay, int aw, int ah);
void MoveTo(int ax, int ay);
void SetFill(TColor c);
void SetLine(TColor c);
};
#endif

66
BoundsUnit.cpp Normal file
View file

@ -0,0 +1,66 @@
#include <vcl.h>
#pragma hdrstop
#include "BoundsUnit.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmBounds *frmBounds;
__fastcall TfrmBounds::TfrmBounds(TComponent* Owner) : TForm(Owner)
{
}
// TUpDown при показе пишет в поле свой Position, поэтому ставим и то и другое
void TfrmBounds::Put(TEdit *e, TUpDown *ud, int v)
{
ud->Position = v;
e->Text = IntToStr(v);
}
// показать окно; true - если нажали OK и фигура изменена
bool TfrmBounds::Edit(TFigure *f)
{
lblFigure->Caption = f->RusName() + L" №" + IntToStr(f->GetNum());
Put(edtX, udX, f->GetX());
Put(edtY, udY, f->GetY());
Put(edtW, udW, f->GetW());
Put(edtH, udH, f->GetH());
// по центру окна, из которого открыли
TForm *parent = Screen->ActiveForm;
if (parent)
{
Left = parent->Left + (parent->Width - Width) / 2;
Top = parent->Top + (parent->Height - Height) / 2;
}
ActiveControl = edtX;
if (ShowModal() != mrOk)
return false; // "Отмена" - фигура не меняется
f->SetBounds(StrToInt(edtX->Text), StrToInt(edtY->Text),
StrToInt(edtW->Text), StrToInt(edtH->Text));
return true;
}
bool TfrmBounds::Valid(TEdit *e, String what, int a, int b)
{
int v;
if (TryStrToInt(e->Text.Trim(), v) && v >= a && v <= b)
{
e->Text = IntToStr(v);
return true;
}
String msg = what + L" - введите целое число от " + IntToStr(a) + L" до " + IntToStr(b) + L".";
Application->MessageBox(msg.c_str(), L"Неверное значение", MB_OK | MB_ICONWARNING);
e->SetFocus();
e->SelectAll();
return false;
}
void __fastcall TfrmBounds::btnOkClick(TObject *Sender)
{
if (!Valid(edtX, "X", POS_MIN, POS_MAX)) return;
if (!Valid(edtY, "Y", POS_MIN, POS_MAX)) return;
if (!Valid(edtW, L"Ширина", SIDE_MIN, SIDE_MAX)) return;
if (!Valid(edtH, L"Высота", SIDE_MIN, SIDE_MAX)) return;
ModalResult = mrOk;
}

183
BoundsUnit.dfm Normal file
View file

@ -0,0 +1,183 @@
object frmBounds: TfrmBounds
Left = 0
Top = 0
BorderStyle = bsDialog
Caption = #1055#1086#1083#1086#1078#1077#1085#1080#1077' '#1080' '#1088#1072#1079#1084#1077#1088
ClientHeight = 300
ClientWidth = 300
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
Position = poDesigned
TextHeight = 16
object pnlTop: TPanel
Left = 0
Top = 0
Width = 300
Height = 44
Align = alTop
BevelOuter = bvNone
Color = 8096000
ParentBackground = False
TabOrder = 0
object lblFigure: TLabel
Left = 16
Top = 12
Width = 268
Height = 19
AutoSize = False
Caption = #1060#1080#1075#1091#1088#1072
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -16
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
end
object gbPos: TGroupBox
Left = 16
Top = 56
Width = 268
Height = 92
Caption = ' '#1055#1086#1083#1086#1078#1077#1085#1080#1077' '
TabOrder = 1
object lblX: TLabel
Left = 16
Top = 27
Width = 8
Height = 16
Caption = 'X:'
end
object lblY: TLabel
Left = 16
Top = 59
Width = 8
Height = 16
Caption = 'Y:'
end
object edtX: TEdit
Left = 110
Top = 24
Width = 120
Height = 24
TabOrder = 0
Text = '0'
end
object udX: TUpDown
Left = 230
Top = 24
Width = 17
Height = 24
Associate = edtX
Min = -2000
Max = 10000
Thousands = False
TabOrder = 1
end
object edtY: TEdit
Left = 110
Top = 56
Width = 120
Height = 24
TabOrder = 2
Text = '0'
end
object udY: TUpDown
Left = 230
Top = 56
Width = 17
Height = 24
Associate = edtY
Min = -2000
Max = 10000
Thousands = False
TabOrder = 3
end
end
object gbSize: TGroupBox
Left = 16
Top = 156
Width = 268
Height = 92
Caption = ' '#1056#1072#1079#1084#1077#1088' '
TabOrder = 2
object lblW: TLabel
Left = 16
Top = 27
Width = 50
Height = 16
Caption = #1064#1080#1088#1080#1085#1072':'
end
object lblH: TLabel
Left = 16
Top = 59
Width = 50
Height = 16
Caption = #1042#1099#1089#1086#1090#1072':'
end
object edtW: TEdit
Left = 110
Top = 24
Width = 120
Height = 24
TabOrder = 0
Text = '110'
end
object udW: TUpDown
Left = 230
Top = 24
Width = 17
Height = 24
Associate = edtW
Min = 20
Max = 1000
Position = 110
Thousands = False
TabOrder = 1
end
object edtH: TEdit
Left = 110
Top = 56
Width = 120
Height = 24
TabOrder = 2
Text = '90'
end
object udH: TUpDown
Left = 230
Top = 56
Width = 17
Height = 24
Associate = edtH
Min = 20
Max = 1000
Position = 90
Thousands = False
TabOrder = 3
end
end
object btnOk: TButton
Left = 96
Top = 260
Width = 90
Height = 30
Caption = 'OK'
Default = True
TabOrder = 3
OnClick = btnOkClick
end
object btnCancel: TButton
Left = 194
Top = 260
Width = 90
Height = 30
Cancel = True
Caption = #1054#1090#1084#1077#1085#1072
ModalResult = 2
TabOrder = 4
end
end

45
BoundsUnit.h Normal file
View file

@ -0,0 +1,45 @@
// Окно "Положение и размер"
#ifndef BoundsUnitH
#define BoundsUnitH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include "BaseFigure.h"
class TfrmBounds : public TForm
{
__published:
TPanel *pnlTop;
TLabel *lblFigure;
TGroupBox *gbPos;
TGroupBox *gbSize;
TLabel *lblX;
TLabel *lblY;
TLabel *lblW;
TLabel *lblH;
TEdit *edtX;
TEdit *edtY;
TEdit *edtW;
TEdit *edtH;
TUpDown *udX;
TUpDown *udY;
TUpDown *udW;
TUpDown *udH;
TButton *btnOk;
TButton *btnCancel;
void __fastcall btnOkClick(TObject *Sender);
private:
void Put(TEdit *e, TUpDown *ud, int v);
bool Valid(TEdit *e, String what, int a, int b);
public:
__fastcall TfrmBounds(TComponent* Owner);
bool Edit(TFigure *f);
};
extern PACKAGE TfrmBounds *frmBounds;
#endif

30
EllipseFigure.cpp Normal file
View file

@ -0,0 +1,30 @@
#include <vcl.h>
#pragma hdrstop
#include "EllipseFigure.h"
#pragma package(smart_init)
TEllipseFigure::TEllipseFigure(int aNum) : TFigure(aNum)
{
}
void TEllipseFigure::Draw(TCanvas *c)
{
SetupCanvas(c);
c->Ellipse(x, y, x + w, y + h);
PaintNumber(c);
}
// уравнение эллипса: (dx/a)^2 + (dy/b)^2 <= 1
bool TEllipseFigure::Contains(int px, int py)
{
double a = w / 2.0;
double b = h / 2.0;
double dx = (px - x - a) / a;
double dy = (py - y - b) / b;
return dx * dx + dy * dy <= 1;
}
String TEllipseFigure::TypeName() { return "ellipse"; }
String TEllipseFigure::RusName() { return L"Эллипс"; }

16
EllipseFigure.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef EllipseFigureH
#define EllipseFigureH
#include "BaseFigure.h"
class TEllipseFigure : public TFigure
{
public:
TEllipseFigure(int aNum);
void Draw(TCanvas *c);
bool Contains(int px, int py);
String TypeName();
String RusName();
};
#endif

235
FigureList.cpp Normal file
View file

@ -0,0 +1,235 @@
#include <vcl.h>
#pragma hdrstop
#include "FigureList.h"
#include "TriangleFigure.h"
#include "RectangleFigure.h"
#include "EllipseFigure.h"
#pragma package(smart_init)
const String FILE_HEADER = "FIGURES 1";
// цвет -> строка "#RRGGBB"
static String ColorToText(TColor c)
{
int rgb = ColorToRGB(c);
return "#" + IntToHex((int)GetRValue(rgb), 2) + IntToHex((int)GetGValue(rgb), 2) + IntToHex((int)GetBValue(rgb), 2);
}
// строка "#RRGGBB" -> цвет, false если строка неправильная
static bool TextToColor(String s, TColor &c)
{
if (s.Length() != 7 || s[1] != '#')
return false;
int v;
if (!TryStrToInt("$" + s.SubString(2, 6), v))
return false;
int r = (v >> 16) & 0xFF;
int g = (v >> 8) & 0xFF;
int b = v & 0xFF;
c = (TColor)RGB(r, g, b);
return true;
}
TFigureManager::TFigureManager()
{
lastNum = 0;
}
TFigureManager::~TFigureManager()
{
FreeAll();
}
void TFigureManager::FreeAll()
{
for (unsigned i = 0; i < list.size(); i++)
delete list[i];
list.clear();
}
TFigure* TFigureManager::MakeFigure(String type, int aNum)
{
if (type == "triangle") return new TTriangleFigure(aNum);
if (type == "rectangle") return new TRectangleFigure(aNum);
if (type == "ellipse") return new TEllipseFigure(aNum);
return NULL;
}
TFigure* TFigureManager::Add(String type, int ax, int ay, int aw, int ah, TColor fill, TColor line)
{
TFigure *f = MakeFigure(type, lastNum + 1);
if (!f)
return NULL;
lastNum++;
f->SetBounds(ax, ay, aw, ah);
f->SetFill(fill);
f->SetLine(line);
list.push_back(f);
return f;
}
void TFigureManager::Delete(TFigure *f)
{
for (unsigned i = 0; i < list.size(); i++)
{
if (list[i] == f)
{
delete f;
list.erase(list.begin() + i);
break;
}
}
}
void TFigureManager::Clear()
{
FreeAll();
lastNum = 0;
}
int TFigureManager::Count()
{
return (int)list.size();
}
// ищем с конца, потому что верхние фигуры лежат в конце списка
TFigure* TFigureManager::FindAt(int px, int py)
{
for (int i = Count() - 1; i >= 0; i--)
if (list[i]->Contains(px, py))
return list[i];
return NULL;
}
// поднять фигуру наверх, true - если порядок поменялся
bool TFigureManager::ToTop(TFigure *f)
{
if (list.empty() || list.back() == f)
return false;
for (unsigned i = 0; i < list.size(); i++)
{
if (list[i] == f)
{
list.erase(list.begin() + i);
list.push_back(f);
return true;
}
}
return false;
}
// полиморфизм: Draw() вызывается не зная, какая именно фигура
void TFigureManager::PaintAll(TCanvas *c)
{
for (unsigned i = 0; i < list.size(); i++)
list[i]->Draw(c);
}
void TFigureManager::Save(String fileName)
{
TStringList *sl = new TStringList();
try
{
sl->Add(L"# Фигуры: вид номер X Y ширина высота заливка обводка");
sl->Add(FILE_HEADER);
for (unsigned i = 0; i < list.size(); i++)
{
TFigure *f = list[i];
String s = f->TypeName();
s += " " + IntToStr(f->GetNum());
s += " " + IntToStr(f->GetX());
s += " " + IntToStr(f->GetY());
s += " " + IntToStr(f->GetW());
s += " " + IntToStr(f->GetH());
s += " " + ColorToText(f->GetFill());
s += " " + ColorToText(f->GetLine());
sl->Add(s);
}
sl->SaveToFile(fileName, TEncoding::UTF8);
}
__finally
{
delete sl;
}
}
// Загрузка. Сначала всё читается во временный список,
// и только если ошибок нет - заменяет фигуры на поле.
void TFigureManager::Load(String fileName)
{
std::vector<TFigure*> temp;
int maxNum = 0;
TStringList *lines = new TStringList();
TStringList *words = new TStringList();
words->Delimiter = ' ';
words->StrictDelimiter = true;
try
{
lines->LoadFromFile(fileName, TEncoding::UTF8);
bool headerFound = false;
for (int i = 0; i < lines->Count; i++)
{
String line = lines->Strings[i].Trim();
if (line.IsEmpty() || line[1] == '#')
continue; // пустая строка или комментарий
String pos = L"Строка " + IntToStr(i + 1) + L": ";
if (!headerFound)
{
if (line != FILE_HEADER)
throw Exception(pos + L"нет заголовка \"" + FILE_HEADER + L"\"");
headerFound = true;
continue;
}
words->DelimitedText = line;
if (words->Count != 8)
throw Exception(pos + L"должно быть 8 значений, а их " + IntToStr(words->Count));
int n[5]; // номер, X, Y, ширина, высота
for (int j = 0; j < 5; j++)
{
String w = words->Strings[j + 1];
if (!TryStrToInt(w, n[j]))
throw Exception(pos + L"\"" + w + L"\" — не целое число");
}
TColor fill, stroke;
if (!TextToColor(words->Strings[6], fill))
throw Exception(pos + L"\"" + words->Strings[6] + L"\" — неверный цвет (нужно #RRGGBB)");
if (!TextToColor(words->Strings[7], stroke))
throw Exception(pos + L"\"" + words->Strings[7] + L"\" — неверный цвет (нужно #RRGGBB)");
if (n[0] <= 0)
throw Exception(pos + L"номер фигуры должен быть больше 0");
for (unsigned k = 0; k < temp.size(); k++)
if (temp[k]->GetNum() == n[0])
throw Exception(pos + L"фигура с номером " + IntToStr(n[0]) + L" уже есть");
TFigure *f = MakeFigure(words->Strings[0], n[0]);
if (!f)
throw Exception(pos + L"неизвестный вид фигуры \"" + words->Strings[0] + L"\"");
f->SetBounds(n[1], n[2], n[3], n[4]);
f->SetFill(fill);
f->SetLine(stroke);
temp.push_back(f);
if (n[0] > maxNum)
maxNum = n[0];
}
if (!headerFound)
throw Exception(L"Это не файл фигур: нет заголовка \"" + FILE_HEADER + L"\"");
}
catch (...)
{
// ошибка - удаляем то, что успели прочитать, старые фигуры не трогаем
for (unsigned k = 0; k < temp.size(); k++)
delete temp[k];
delete lines;
delete words;
throw;
}
delete lines;
delete words;
FreeAll();
list = temp;
lastNum = maxNum;
}

32
FigureList.h Normal file
View file

@ -0,0 +1,32 @@
// Менеджер фигур: хранит все фигуры поля и работает с файлом
#ifndef FigureListH
#define FigureListH
#include <vector>
#include "BaseFigure.h"
class TFigureManager
{
private:
std::vector<TFigure*> list; // фигуры в порядке наложения (последняя - сверху)
int lastNum; // последний выданный номер
TFigure* MakeFigure(String type, int aNum);
void FreeAll();
public:
TFigureManager();
~TFigureManager();
TFigure* Add(String type, int ax, int ay, int aw, int ah, TColor fill, TColor line);
void Delete(TFigure *f);
void Clear();
int Count();
TFigure* FindAt(int px, int py);
bool ToTop(TFigure *f);
void PaintAll(TCanvas *c);
void Save(String fileName);
void Load(String fileName);
};
#endif

150
GameUnit.cpp Normal file
View file

@ -0,0 +1,150 @@
#include <vcl.h>
#pragma hdrstop
#include "GameUnit.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmGame *frmGame;
__fastcall TfrmGame::TfrmGame(TComponent* Owner) : TForm(Owner)
{
}
void __fastcall TfrmGame::FormShow(TObject *Sender)
{
Randomize();
StartGame();
}
void __fastcall TfrmGame::FormClose(TObject *Sender, TCloseAction &Action)
{
tmrClock->Enabled = false;
}
// расставить фишки по порядку и перемешать случайными ходами
// (так позиция всегда получается решаемой)
void TfrmGame::StartGame()
{
for (int i = 0; i < 15; i++)
sgBoard->Cells[i % 4][i / 4] = IntToStr(i + 1);
sgBoard->Cells[3][3] = "";
for (int k = 0; k < 1000; k++)
TryMove(Random(4), Random(4));
steps = 0;
secs = 0;
gameOver = false;
tmrClock->Enabled = false;
UpdateLabels();
}
// если рядом с клеткой (col, row) пусто - двигаем фишку туда
bool TfrmGame::TryMove(int col, int row)
{
int ec = -1;
int er = -1;
if (col > 0 && sgBoard->Cells[col - 1][row] == "") { ec = col - 1; er = row; }
if (col < 3 && sgBoard->Cells[col + 1][row] == "") { ec = col + 1; er = row; }
if (row > 0 && sgBoard->Cells[col][row - 1] == "") { ec = col; er = row - 1; }
if (row < 3 && sgBoard->Cells[col][row + 1] == "") { ec = col; er = row + 1; }
if (ec == -1)
return false;
sgBoard->Cells[ec][er] = sgBoard->Cells[col][row];
sgBoard->Cells[col][row] = "";
return true;
}
bool TfrmGame::CheckWin()
{
for (int i = 0; i < 15; i++)
if (sgBoard->Cells[i % 4][i / 4] != IntToStr(i + 1))
return false;
return true;
}
void TfrmGame::UpdateLabels()
{
lblSteps->Caption = L"Ходов: " + IntToStr(steps);
lblClock->Caption = L"Время: " + IntToStr(secs) + L" с";
}
void __fastcall TfrmGame::sgBoardMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int col, row;
sgBoard->MouseToCell(X, Y, col, row);
if (gameOver || col < 0 || row < 0)
return;
if (!TryMove(col, row))
return;
steps++;
tmrClock->Enabled = true; // время идёт с первого хода
UpdateLabels();
if (CheckWin())
{
tmrClock->Enabled = false;
gameOver = true;
String msg = L"Вы прошли за " + IntToStr(secs) + L" с, ходов: " + IntToStr(steps);
Application->MessageBox(msg.c_str(), L"Победа!", MB_OK | MB_ICONINFORMATION);
}
}
void __fastcall TfrmGame::tmrClockTimer(TObject *Sender)
{
secs++;
UpdateLabels();
}
void __fastcall TfrmGame::btnShuffleClick(TObject *Sender)
{
StartGame();
}
void __fastcall TfrmGame::btnRulesClick(TObject *Sender)
{
Application->MessageBox(
L"Нужно расставить фишки по порядку от 1 до 15,\n"
L"пустая клетка - в правом нижнем углу.\n\n"
L"Щёлкните по фишке рядом с пустой клеткой,\n"
L"чтобы передвинуть её.\n\n"
L"Время начинает идти после первого хода.",
L"Правила игры", MB_OK | MB_ICONINFORMATION);
}
// фишки - скруглённые плитки, пустая клетка - цвет фона
void __fastcall TfrmGame::sgBoardDrawCell(TObject *Sender, System::LongInt ACol,
System::LongInt ARow, const TRect &Rect, TGridDrawState State)
{
TCanvas *c = sgBoard->Canvas;
c->Brush->Color = sgBoard->FixedColor;
c->FillRect(Rect);
String s = sgBoard->Cells[ACol][ARow];
if (s == "")
return;
c->Brush->Color = sgBoard->Color;
c->Pen->Color = sgBoard->Color;
c->RoundRect(Rect.Left + 4, Rect.Top + 4, Rect.Right - 4, Rect.Bottom - 4, 16, 16);
c->Font->Assign(sgBoard->Font);
c->Brush->Style = bsClear;
int tx = Rect.Left + (Rect.Width() - c->TextWidth(s)) / 2;
int ty = Rect.Top + (Rect.Height() - c->TextHeight(s)) / 2;
c->TextOut(tx, ty, s);
c->Brush->Style = bsSolid;
}
// D или F2 - почти собрать поле (для показа), остаётся один ход
void __fastcall TfrmGame::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key != 'D' && Key != VK_F2)
return;
for (int i = 0; i < 15; i++)
sgBoard->Cells[i % 4][i / 4] = IntToStr(i + 1);
sgBoard->Cells[2][3] = "";
sgBoard->Cells[3][3] = "15";
steps = 100 + Random(100);
secs = 60 + Random(120);
gameOver = false;
tmrClock->Enabled = true;
UpdateLabels();
Key = 0;
}

110
GameUnit.dfm Normal file
View file

@ -0,0 +1,110 @@
object frmGame: TfrmGame
Left = 0
Top = 0
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = #1048#1075#1088#1072' '#171#1055#1103#1090#1085#1072#1096#1082#1080#187
ClientHeight = 452
ClientWidth = 344
Color = 16447477
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Tahoma'
Font.Style = []
KeyPreview = True
Position = poMainFormCenter
OnClose = FormClose
OnKeyDown = FormKeyDown
OnShow = FormShow
TextHeight = 18
object pnlInfo: TPanel
Left = 0
Top = 0
Width = 344
Height = 54
Align = alTop
BevelOuter = bvNone
Color = 5258796
ParentBackground = False
TabOrder = 0
object lblSteps: TLabel
Left = 20
Top = 15
Width = 90
Height = 23
Caption = #1061#1086#1076#1086#1074': 0'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -19
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object lblClock: TLabel
Left = 196
Top = 15
Width = 100
Height = 23
Caption = #1042#1088#1077#1084#1103': 0 '#1089
Font.Charset = DEFAULT_CHARSET
Font.Color = 6798079
Font.Height = -19
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
end
object sgBoard: TStringGrid
Left = 20
Top = 70
Width = 304
Height = 304
BorderStyle = bsNone
Color = 15855852
ColCount = 4
DefaultColWidth = 76
DefaultRowHeight = 76
DefaultDrawing = False
FixedColor = 6179124
FixedCols = 0
RowCount = 4
FixedRows = 0
Font.Charset = DEFAULT_CHARSET
Font.Color = 5258796
Font.Height = -30
Font.Name = 'Verdana'
Font.Style = [fsBold]
GridLineWidth = 0
Options = []
ParentFont = False
ScrollBars = ssNone
TabOrder = 1
OnDrawCell = sgBoardDrawCell
OnMouseDown = sgBoardMouseDown
end
object btnShuffle: TButton
Left = 20
Top = 392
Width = 148
Height = 40
Caption = #1055#1077#1088#1077#1084#1077#1096#1072#1090#1100
TabOrder = 2
OnClick = btnShuffleClick
end
object btnRules: TButton
Left = 176
Top = 392
Width = 148
Height = 40
Caption = #1055#1088#1072#1074#1080#1083#1072
TabOrder = 3
OnClick = btnRulesClick
end
object tmrClock: TTimer
Enabled = False
OnTimer = tmrClockTimer
Left = 296
Top = 8
end
end

46
GameUnit.h Normal file
View file

@ -0,0 +1,46 @@
// Игра "Пятнашки"
#ifndef GameUnitH
#define GameUnitH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Grids.hpp>
#include <Vcl.ExtCtrls.hpp>
class TfrmGame : public TForm
{
__published:
TPanel *pnlInfo;
TLabel *lblSteps;
TLabel *lblClock;
TStringGrid *sgBoard;
TButton *btnShuffle;
TButton *btnRules;
TTimer *tmrClock;
void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall sgBoardMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall sgBoardDrawCell(TObject *Sender, System::LongInt ACol,
System::LongInt ARow, const TRect &Rect, TGridDrawState State);
void __fastcall tmrClockTimer(TObject *Sender);
void __fastcall btnShuffleClick(TObject *Sender);
void __fastcall btnRulesClick(TObject *Sender);
private:
int steps; // сколько сделано ходов
int secs; // сколько прошло секунд
bool gameOver; // игра уже выиграна
void StartGame();
bool TryMove(int col, int row);
bool CheckWin();
void UpdateLabels();
public:
__fastcall TfrmGame(TComponent* Owner);
};
extern PACKAGE TfrmGame *frmGame;
#endif

266
LabWorks.cbproj Normal file
View file

@ -0,0 +1,266 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{A8F5E19E-5FBA-4F86-A736-8F67A2947C99}</ProjectGuid>
<ProjectVersion>20.3</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<AppType>Application</AppType>
<MainSource>LabWorks.cpp</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1048577</TargetedPlatforms>
<ProjectName Condition="'$(ProjectName)'==''">LabWorks</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
<Base_Win64>true</Base_Win64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64x' and '$(Base)'=='true') or '$(Base_Win64x)'!=''">
<Base_Win64x>true</Base_Win64x>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win32)'!=''">
<Cfg_1_Win32>true</Cfg_1_Win32>
<CfgParent>Cfg_1</CfgParent>
<Cfg_1>true</Cfg_1>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win64)'!=''">
<Cfg_1_Win64>true</Cfg_1_Win64>
<CfgParent>Cfg_1</CfgParent>
<Cfg_1>true</Cfg_1>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64x' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win64x)'!=''">
<Cfg_1_Win64x>true</Cfg_1_Win64x>
<CfgParent>Cfg_1</CfgParent>
<Cfg_1>true</Cfg_1>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win64)'!=''">
<Cfg_2_Win64>true</Cfg_2_Win64>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64x' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win64x)'!=''">
<Cfg_2_Win64x>true</Cfg_2_Win64x>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<ProjectType>CppVCLApplication</ProjectType>
<_TCHARMapping>wchar_t</_TCHARMapping>
<Icon_MainIcon>LabWorks_Icon.ico</Icon_MainIcon>
<Multithreaded>true</Multithreaded>
<SanitizedProjectName>LabWorks</SanitizedProjectName>
<AllPackageLibs>rtl.lib;vcl.lib</AllPackageLibs>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)</DCC_Namespace>
<DCC_CBuilderOutput>JPHNE</DCC_CBuilderOutput>
<DynamicRTL>false</DynamicRTL>
<UsePackages>false</UsePackages>
<IntermediateOutputDir>.\$(Platform)\$(Config)</IntermediateOutputDir>
<FinalOutputDir>.\$(Platform)\$(Config)</FinalOutputDir>
<BCC_wpar>false</BCC_wpar>
<BCC_OptimizeForSpeed>true</BCC_OptimizeForSpeed>
<BCC_ExtendedErrorInfo>true</BCC_ExtendedErrorInfo>
<ILINK_TranslatedLibraryPath>$(BDSLIB)\$(PLATFORM)\release\$(LANGDIR);$(ILINK_TranslatedLibraryPath)</ILINK_TranslatedLibraryPath>
<UWP_CppLogo44>$(BDS)\bin\Artwork\Windows\UWP\cppreg_UwpDefault_44.png</UWP_CppLogo44>
<UWP_CppLogo150>$(BDS)\bin\Artwork\Windows\UWP\cppreg_UwpDefault_150.png</UWP_CppLogo150>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<BCC_PCHName_Clang>LabWorksPCH.h</BCC_PCHName_Clang>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<IncludePath>$(BDSINCLUDE)\windows\vcl;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<BCC_PCHName_Clang>LabWorksPCH.h</BCC_PCHName_Clang>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64x)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<BCC_EnableBatchCompilation>true</BCC_EnableBatchCompilation>
<BCC_PCHName_Clang>LabWorksPCH.h</BCC_PCHName_Clang>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<BCC_OptimizeForSpeed>false</BCC_OptimizeForSpeed>
<BCC_DisableOptimizations>true</BCC_DisableOptimizations>
<DCC_Optimize>false</DCC_Optimize>
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
<Defines>_DEBUG;$(Defines)</Defines>
<BCC_InlineFunctionExpansion>false</BCC_InlineFunctionExpansion>
<BCC_UseRegisterVariables>None</BCC_UseRegisterVariables>
<DCC_Define>DEBUG</DCC_Define>
<BCC_DebugLineNumbers>true</BCC_DebugLineNumbers>
<TASM_DisplaySourceLines>true</TASM_DisplaySourceLines>
<BCC_StackFrames>true</BCC_StackFrames>
<ILINK_FullDebugInfo>true</ILINK_FullDebugInfo>
<TASM_Debugging>Full</TASM_Debugging>
<BCC_SourceDebuggingOn>true</BCC_SourceDebuggingOn>
<BCC_EnableCPPExceptions>true</BCC_EnableCPPExceptions>
<BCC_DisableFramePtrElimOpt>true</BCC_DisableFramePtrElimOpt>
<BCC_DisableSpellChecking>true</BCC_DisableSpellChecking>
<CLANG_UnwindTables>true</CLANG_UnwindTables>
<ILINK_LibraryPath>$(BDSLIB)\$(PLATFORM)\debug;$(ILINK_LibraryPath)</ILINK_LibraryPath>
<ILINK_TranslatedLibraryPath>$(BDSLIB)\$(PLATFORM)\debug\$(LANGDIR);$(ILINK_TranslatedLibraryPath)</ILINK_TranslatedLibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<ILINK_LibraryPath>$(BDSLIB)\$(PLATFORM)$(CC_SUFFIX)\debug;$(ILINK_LibraryPath)</ILINK_LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win64x)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
<LinkPackageStatics>rtl.lib;vcl.lib</LinkPackageStatics>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<Defines>NDEBUG;$(Defines)</Defines>
<TASM_Debugging>None</TASM_Debugging>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64x)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
</PropertyGroup>
<ItemGroup>
<CppCompile Include="LabWorks.cpp">
<BuildOrder>0</BuildOrder>
</CppCompile>
<PCHCompile Include="LabWorksPCH.h">
<BuildOrder>1</BuildOrder>
<PCH>true</PCH>
</PCHCompile>
<CppCompile Include="BaseFigure.cpp">
<DependentOn>BaseFigure.h</DependentOn>
<BuildOrder>2</BuildOrder>
</CppCompile>
<CppCompile Include="TriangleFigure.cpp">
<DependentOn>TriangleFigure.h</DependentOn>
<BuildOrder>3</BuildOrder>
</CppCompile>
<CppCompile Include="RectangleFigure.cpp">
<DependentOn>RectangleFigure.h</DependentOn>
<BuildOrder>4</BuildOrder>
</CppCompile>
<CppCompile Include="EllipseFigure.cpp">
<DependentOn>EllipseFigure.h</DependentOn>
<BuildOrder>5</BuildOrder>
</CppCompile>
<CppCompile Include="FigureList.cpp">
<DependentOn>FigureList.h</DependentOn>
<BuildOrder>6</BuildOrder>
</CppCompile>
<CppCompile Include="MenuUnit.cpp">
<Form>frmMenu</Form>
<FormType>dfm</FormType>
<DependentOn>MenuUnit.h</DependentOn>
<BuildOrder>7</BuildOrder>
</CppCompile>
<CppCompile Include="GameUnit.cpp">
<Form>frmGame</Form>
<FormType>dfm</FormType>
<DependentOn>GameUnit.h</DependentOn>
<BuildOrder>8</BuildOrder>
</CppCompile>
<CppCompile Include="ShapesUnit.cpp">
<Form>frmShapes</Form>
<FormType>dfm</FormType>
<DependentOn>ShapesUnit.h</DependentOn>
<BuildOrder>9</BuildOrder>
</CppCompile>
<CppCompile Include="BoundsUnit.cpp">
<Form>frmBounds</Form>
<FormType>dfm</FormType>
<DependentOn>BoundsUnit.h</DependentOn>
<BuildOrder>10</BuildOrder>
</CppCompile>
<FormResources Include="MenuUnit.dfm"/>
<FormResources Include="GameUnit.dfm"/>
<FormResources Include="ShapesUnit.dfm"/>
<FormResources Include="BoundsUnit.dfm"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Debug">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>CPlusPlusBuilder.Personality.12</Borland.Personality>
<Borland.ProjectType>CppVCLApplication</Borland.ProjectType>
<BorlandProject>
<CPlusPlusBuilder.Personality>
<ProjectProperties>
<ProjectProperties Name="AutoShowDeps">False</ProjectProperties>
<ProjectProperties Name="ManagePaths">True</ProjectProperties>
<ProjectProperties Name="VerifyPackages">True</ProjectProperties>
<ProjectProperties Name="IndexFiles">False</ProjectProperties>
</ProjectProperties>
<Source>
<Source Name="MainSource">LabWorks.cpp</Source>
</Source>
</CPlusPlusBuilder.Personality>
<Platforms>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
<Platform value="Win64x">True</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Cpp.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Cpp.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>

28
LabWorks.cpp Normal file
View file

@ -0,0 +1,28 @@
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
USEFORM("MenuUnit.cpp", frmMenu);
USEFORM("GameUnit.cpp", frmGame);
USEFORM("ShapesUnit.cpp", frmShapes);
USEFORM("BoundsUnit.cpp", frmBounds);
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
Application->Title = L"Лабораторные работы";
Application->CreateForm(__classid(TfrmMenu), &frmMenu);
Application->CreateForm(__classid(TfrmGame), &frmGame);
Application->CreateForm(__classid(TfrmShapes), &frmShapes);
Application->CreateForm(__classid(TfrmBounds), &frmBounds);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}

2
LabWorksPCH.h Normal file
View file

@ -0,0 +1,2 @@
#include <vcl.h>
#include <tchar.h>

BIN
LabWorks_Icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

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);
}

116
MenuUnit.dfm Normal file
View file

@ -0,0 +1,116 @@
object frmMenu: TfrmMenu
Left = 0
Top = 0
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = #1052#1077#1085#1102' '#1083#1072#1073#1086#1088#1072#1090#1086#1088#1085#1099#1093' '#1088#1072#1073#1086#1090
ClientHeight = 430
ClientWidth = 540
Color = 16447477
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -19
Font.Name = 'Tahoma'
Font.Style = []
Position = poScreenCenter
OnCreate = FormCreate
TextHeight = 23
object lblAuthor: TLabel
Left = 0
Top = 384
Width = 540
Height = 23
Alignment = taCenter
AutoSize = False
Caption = #1042#1099#1087#1086#1083#1085#1080#1083': '#1060#1072#1084#1080#1083#1080#1103' '#1048#1084#1103' '#1054#1090#1095#1077#1089#1090#1074#1086', '#1075#1088#1091#1087#1087#1072' ______'
Font.Charset = DEFAULT_CHARSET
Font.Color = clGrayText
Font.Height = -16
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
end
object pnlHeader: TPanel
Left = 0
Top = 0
Width = 540
Height = 105
Align = alTop
BevelOuter = bvNone
Color = 8096000
ParentBackground = False
TabOrder = 3
object lblCaption: TLabel
Left = 0
Top = 20
Width = 540
Height = 36
Alignment = taCenter
AutoSize = False
Caption = #1051#1072#1073#1086#1088#1072#1090#1086#1088#1085#1099#1077' '#1088#1072#1073#1086#1090#1099
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -29
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object lblSubject: TLabel
Left = 0
Top = 62
Width = 540
Height = 23
Alignment = taCenter
AutoSize = False
Caption = #1076#1080#1089#1094#1080#1087#1083#1080#1085#1072' '#171#1055#1088#1086#1075#1088#1072#1084#1084#1080#1088#1086#1074#1072#1085#1080#1077#187
Font.Charset = DEFAULT_CHARSET
Font.Color = 15132390
Font.Height = -17
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
end
end
object btnGame: TButton
Left = 110
Top = 135
Width = 320
Height = 64
Caption = #1048#1075#1088#1072' '#171#1055#1103#1090#1085#1072#1096#1082#1080#187
ImageIndex = 0
ImageMargins.Left = 16
Images = imgButtons
TabOrder = 0
OnClick = btnGameClick
end
object btnShapes: TButton
Left = 110
Top = 214
Width = 320
Height = 64
Caption = #1056#1077#1076#1072#1082#1090#1086#1088' '#171#1060#1080#1075#1091#1088#1099#187
ImageIndex = 1
ImageMargins.Left = 16
Images = imgButtons
TabOrder = 1
OnClick = btnShapesClick
end
object btnAbout: TButton
Left = 110
Top = 293
Width = 320
Height = 64
Caption = #1054' '#1087#1088#1086#1075#1088#1072#1084#1084#1077
ImageIndex = 2
ImageMargins.Left = 16
Images = imgButtons
TabOrder = 2
OnClick = btnAboutClick
end
object imgButtons: TImageList
Height = 32
Width = 32
Left = 480
Top = 130
end
end

36
MenuUnit.h Normal file
View file

@ -0,0 +1,36 @@
// Главное меню
#ifndef MenuUnitH
#define MenuUnitH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ImgList.hpp>
#include <System.ImageList.hpp>
class TfrmMenu : public TForm
{
__published:
TPanel *pnlHeader;
TLabel *lblCaption;
TLabel *lblSubject;
TButton *btnGame;
TButton *btnShapes;
TButton *btnAbout;
TLabel *lblAuthor;
TImageList *imgButtons;
void __fastcall FormCreate(TObject *Sender);
void __fastcall btnGameClick(TObject *Sender);
void __fastcall btnShapesClick(TObject *Sender);
void __fastcall btnAboutClick(TObject *Sender);
private:
void DrawIcons();
public:
__fastcall TfrmMenu(TComponent* Owner);
};
extern PACKAGE TfrmMenu *frmMenu;
#endif

Some files were not shown because too many files have changed in this diff Show more