Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовик 8.02.doc
Скачиваний:
1
Добавлен:
01.03.2025
Размер:
441.86 Кб
Скачать

5 Блок-схема

Для створення програми за заданим завданням необхідною умовою є створення блок – схеми, яка допомагає більш добре уявити, які структурні частини повинна містити у собі створена програма.

Малюнок 1 – Блок-схема програми

6 Текст програми

unit kyrsov;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ExtCtrls, StdCtrls, Menus, ComCtrls, Buttons;

type

Pin = array of TPanel;

TForm1 = class(TForm)

Panel1: TPanel;

Panel2: TPanel;

Panel3: TPanel;

Panel4: TPanel;

Panel5: TPanel;

Panel6: TPanel;

Panel7: TPanel;

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

Edit5: TEdit;

Edit6: TEdit;

StatusBar1: TStatusBar;

Timer1: TTimer;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Edit7: TEdit;

UpDown1: TUpDown;

Button1: TButton;

Button2: TButton;

Label4: TLabel;

Timer2: TTimer;

procedure Game(Sen: TObject);

procedure PanelClick(Sender: TObject);

procedure Move(Pan1, Pan2: TPanel; Ed: TEdit);

procedure Hig(Pan: Pin; Tow: TPanel; Ed1, Ed2: TEdit);

procedure EndOfGame;

procedure Sel(Pan1: TObject; Pan: Pin; Ed1, Ed2, Ed3: TEdit);

procedure Pos(Panel: TPanel);

procedure FormCreate(Sender: TObject);

procedure Panel3Click(Sender: TObject);

procedure Panel4Click(Sender: TObject);

procedure Panel2Click(Sender: TObject);

procedure N2Click(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

procedure N4Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

i, j, t, n: integer;

f: boolean;

p: Pin;

m, s: string;

v: TPanel;

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

Panel2.Height := UpDown1.Position * 20 + 40;

Panel3.Height := UpDown1.Position * 20 + 40;

Panel4.Height := UpDown1.Position * 20 + 40;

Panel2.Top := Panel5.Top - UpDown1.Position * 20 - 30;

Panel3.Top := Panel5.Top - UpDown1.Position * 20 - 30;

Panel4.Top := Panel5.Top - UpDown1.Position * 20 - 30;

f := False;

Panel1.Enabled := False;

Timer1.Enabled := False;

Label1.Visible := False;

Label2.Visible := False;

t := 0;

StatusBar1.Panels.Items[1].Text := 'Кол-во шагов: ' + IntToStr(t);

m := '00';

s := '00';

StatusBar1.Panels.Items[0].Text := 'Время игры: ' + m + ':' + s;

Edit1.Text := IntToStr(UpDown1.Position);

Edit2.Text := IntToStr(0);

Edit3.Text := IntToStr(0);

Edit5.Text := '';

Edit6.Text := '';

end;

procedure TForm1.Panel2Click(Sender: TObject);

begin

Label2.Caption := '';

if (f = True) and (v.Color = clLime) and

((v.Caption <= Edit4.Text) or (Edit4.Text = '')) then

begin

t := t + 1;

StatusBar1.Panels.Items[1].Text := 'Кол-во шагов: ' + IntToStr(t);

Pos(v);

Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1);

Move(v, Panel5, Edit1);

Edit4.Text := v.Caption;

Hig(p, Panel3, Edit5, Edit2);

Hig(p, Panel4, Edit6, Edit3);

EndOfGame;

v.Color := clBlue;

Label2.Caption := 'Выберите диск для перемещения';

end

else

Label2.Caption := 'Неправильный ход';

end;

procedure TForm1.Panel3Click(Sender: TObject);

begin

Label2.Caption := '';

if (f = True) and (v.Color = clLime) and

((v.Caption <= Edit5.Text) or (Edit5.Text = '')) then

begin

t := t + 1;

StatusBar1.Panels.Items[1].Text := 'Кол-во шагов: ' + IntToStr(t);

Pos(v);

Edit2.Text := IntToStr(StrToInt(Edit2.Text) + 1);

Move(v, Panel7, Edit2);

Edit5.Text := v.Caption;

Hig(p, Panel2, Edit4, Edit1);

Hig(p, Panel4, Edit6, Edit3);

EndOfGame;

v.Color := clBlue;

Label2.Caption := 'Выберите диск для перемещения';

end

else

Label2.Caption := 'Ход не верный';

end;

procedure TForm1.Panel4Click(Sender: TObject);

begin

Label2.Caption := '';

if (f = True) and (v.Color = clLime) and

((v.Caption <= Edit6.Text) or (Edit6.Text = '')) then

begin

t := t + 1;

StatusBar1.Panels.Items[1].Text := 'Кол-во шагов: ' + IntToStr(t);

Pos(v);

Edit3.Text := IntToStr(StrToInt(Edit3.Text) + 1);

Move(v, Panel6, Edit3);

Edit6.Text := v.Caption;

Hig(p, Panel2, Edit4, Edit1);

Hig(p, Panel3, Edit5, Edit2);

EndOfGame;

v.Color := clBlue;

Label2.Caption := 'Выберите диск для перемещения';

end

else

Label2.Caption := 'Ход не верный';

end;

procedure TForm1.Pos(Panel: TPanel);

begin

if (Panel.Left = StrToInt(FloatToStr(90 - Panel.Width / 2))) then

Edit1.Text := IntToStr(StrToInt(Edit1.Text) - 1);

if (Panel.Left = StrToInt(FloatToStr(300 - Panel.Width / 2))) then

Edit2.Text := IntToStr(StrToInt(Edit2.Text) - 1);

if (Panel.Left = StrToInt(FloatToStr(510 - Panel.Width / 2))) then

Edit3.Text := IntToStr(StrToInt(Edit3.Text) - 1);

end;

procedure TForm1.Sel(Pan1: TObject; Pan: Pin; Ed1, Ed2, Ed3: TEdit);

begin

if ((Pan1 as TPanel).Caption = Ed1.Text) or

((Pan1 as TPanel).Caption = Ed2.Text) or

((Pan1 as TPanel).Caption = Ed3.Text) then

begin

for i := 1 to UpDown1.Position do

Pan[i].Color := clBlue; (Pan1 as TPanel)

.Color := clLime;

Label2.Caption := 'Переместите диск';

end;

end;

procedure TForm1.EndOfGame;

begin

if (Edit2.Text = IntToStr(UpDown1.Position)) or

(Edit3.Text = IntToStr(UpDown1.Position)) then

begin

Panel1.Enabled := False;

Label1.Visible := True;

Label2.Visible := False;

Timer1.Enabled := False;

end;

end;

procedure TForm1.Hig(Pan: Pin; Tow: TPanel; Ed1, Ed2: TEdit);

begin

if StrToInt(Ed2.Text) = 1 then

for i := 1 to UpDown1.Position do

if (Tow.Left = Pan[i].Left + Pan[i].Width / 2 - 5) then

Ed1.Text := Pan[i].Caption;

if StrToInt(Ed2.Text) > 1 then

for i := UpDown1.Position downto 2 do

for j := UpDown1.Position - 1 downto 1 do

if (Tow.Left = Pan[i].Left + Pan[i].Width / 2 - 5) and

(Tow.Left = Pan[j].Left + Pan[j].Width / 2 - 5) then

if (StrToInt(Pan[i].Caption) > StrToInt(Pan[j].Caption)) then

Ed1.Text := Pan[j].Caption;

if StrToInt(Ed2.Text) = 0 then

Ed1.Text := '';

end;

procedure TForm1.Move(Pan1, Pan2: TPanel; Ed: TEdit);

begin

Pan1.Left := StrToInt(FloatToStr(Pan2.Left + Pan2.Width / 2 - Pan1.Width / 2)

);

Pan1.Top := Pan2.Top - 20 * StrToInt(Ed.Text);

end;

procedure TForm1.N2Click(Sender: TObject);

begin

Game(Sender);

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin

s := IntToStr(StrToInt(s) + 1);

if (s = '60') then

begin

m := IntToStr(StrToInt(m) + 1);

s := '00';

end;

if Length(s) = 1 then

s := '0' + IntToStr(StrToInt(s));

if Length(m) = 1 then

m := '0' + IntToStr(StrToInt(m) + 1);

StatusBar1.Panels.Items[0].Text := 'Время игры: ' + m + ':' + s;

end;

procedure TForm1.PanelClick(Sender: TObject);

begin

if ((Sender as TPanel).Caption = Edit4.Text) or

((Sender as TPanel).Caption = Edit5.Text) or

((Sender as TPanel).Caption = Edit6.Text) then

begin

for i := 1 to UpDown1.Position do

p[i].Color := clBlue; (Sender as TPanel)

.Color := clLime;

v := (Sender as TPanel);

f := True;

Label2.Caption := 'Переместите диск';

end;

end;

procedure TForm1.Game(Sen: TObject);

begin

if MessageDlg('Вы уверены, что хотите закончить эту игру и начать новую?',

mtInformation, [mbOK, mbCancel], 0) = 1 then

begin

for i := 1 to n do

p[i].Destroy;

FormCreate(Sen);

Panel1.Enabled := True;

Timer1.Enabled := True;

Label2.Visible := True;

Label2.Caption := 'Выберите диск для перемещения';

n := UpDown1.Position;

SetLength(p, UpDown1.Position + 1);

for i := 1 to UpDown1.Position do

begin

Edit1.Text := IntToStr(i);

Edit4.Text := IntToStr(1);

p[i] := TPanel.Create(Self);

p[i].Height := 20;

p[i].Width := Panel5.Width - 16 * (UpDown1.Position - i + 1);

p[i].Left := (Panel2.Left + 5) - StrToInt(FloatToStr(p[i].Width / 2));

p[i].Top := Panel5.Top - p[i].Height * (UpDown1.Position - i + 1);

p[i].Color := clBlue;

p[i].Anchors := [akLeft, akBottom];

p[i].Font.Color := clYellow;

p[i].Font.Style := [fsBold];

p[i].Caption := IntToStr(i);

p[i].OnClick := PanelClick;

p[i].Parent := Panel1;

end;

end;

end;

procedure TForm1.N4Click(Sender: TObject);

begin

if MessageDlg('Закончить игру и выйти?', mtInformation, [mbOK, mbCancel], 0) = 1 then

Close;

end;

end.