Смекни!
smekni.com

Разработка программы- тренажера Управление электросетями (стр. 6 из 6)

private

{ Private declarations }

public

{ Public declarations }

end;

TStringList1 = class (TStringList);

TMyZap=class(TObject)

FNo:Integer;

FImage:ShortString;

FState:Integer;

FComment:ShortString;

constructor Create(No:Integer;Image:ShortString;State:Integer;Comment:ShortString);

end;

var

Form1: TForm1;

TaskNumber:Integer;

WorkMode:Integer;

List1:TStringList1;

ActList:TList;

Prot:TStringList;

Zap:TMyZap;

Switch:TImage;

TaskName:string;

Error:integer;

Help:integer;

Count:Integer;

F: array [0..24] of boolean;

E: array [0..24] of boolean;

implementation

uses Results;

{$R *.DFM}

constructor TMyZap.Create(No:Integer;Image:ShortString;State:Integer;Comment:ShortString);

begin

inherited Create;

FNo:=No;

FImage:=Image;

FState:=State;

FComment:=Comment;

end;

procedure SWState(AOwner:TImage;i:integer);

begin

if F[i]=false then begin

with AOwner.Canvas do begin

Pen.Color:=clWhite;

MoveTo(6,1);

LineTo(6,17);

Pen.Width:=2;

Pen.Color:=clBlack;

Rectangle(1,1,17,17);

MoveTo(6,17);

LineTo(15,1);

end;

F[i]:=true;

end

else begin

with AOwner.Canvas do begin

Pen.Color:=clWhite;

MoveTo(6,17);

LineTo(15,1);

Pen.Width:=2;

Pen.Color:=clBlack;

Rectangle(1,1,17,17);

MoveTo(6,1);

LineTo(6,17);

end;

F[i]:=false;

end;

end;

procedure ABRState(AOwner:TImage;i:integer);

begin

if F[i]=False then begin

with AOwner.Canvas do begin

Brush.Color:=clWhite;

FloodFill(8,8,clBlack,fsSurface);

Pen.Width:=2;

Pen.Color:=clBlack;

MoveTo(1,15);

LineTo(8,1);

MoveTo(8,1);

LineTo(17,15);

MoveTo(17,15);

LineTo(1,15);

end;

F[i]:=True;

end

else begin

with AOwner.Canvas do begin

FloodFill(8,8,clWhite,fsSurface);

Pen.Width:=2;

Pen.Color:=clBlack;

MoveTo(1,15);

LineTo(8,1);

MoveTo(8,1);

LineTo(17,15);

MoveTo(17,15);

LineTo(1,15);

Brush.Color:=clBlack;

FloodFill(8,8,clBlack,fsBorder);

end;

F[i]:=False;

end;

end;

procedure MVState(AOwner:TImage;i:integer);

begin

if F[i]=false then begin

with AOwner.Canvas do begin

Pen.Color:=clWhite;

MoveTo(9,6);

LineTo(9,11);

Pen.Width:=2;

Pen.Color:=clBlack;

Rectangle(1,1,17,17);

MoveTo(6,8);

LineTo(11,8);

end;

F[i]:=true;

end

else begin

with AOwner.Canvas do begin

Pen.Color:=clWhite;

MoveTo(6,8);

LineTo(11,8);

Pen.Width:=2;

Pen.Color:=clBlack;

Rectangle(1,1,17,17);

MoveTo(9,6);

LineTo(9,11);

end;

F[i]:=false;

end;

end;

function Analyze(AOwner:TComponent):boolean;

begin

Zap:=ActList.First;

if WorkMode=0 then

if (Zap.FImage=AOwner.Name)

then begin

if Zap.FImage<>'0' then ActList.Delete(ActList.IndexOf(ActList.First));

Result:=true;

Form1.Label1.Caption:='';

Prot.Append(Zap.FComment);

end

else begin

Form1.Label1.Caption:=' Ошибка';

Prot.Append('Ошибка, '+Zap.FComment);

Error:=Error+1;

Result:=false;

end

else Count:=Count+1;

Form1.ResultBtn.Visible:=True;

end;

{Считывание информации дла решения задач}

procedure Read;

var Fil:textfile;

s:string;

j:integer;

begin

for j:=1 to 10 do begin

s:='Info&bsol;'+IntToStr(j)+'.str';

assign(fil,s);

reset(fil);

readln(fil,s);

Form1.TaskList.Items.Insert(j-1,s);

end;

end;

procedure ReadInfo(Num:integer);

var Fil:textfile;

s,s1:string;

i,j:integer;

begin

ActList:=TList.Create;

s:='Info&bsol;'+IntToStr(Num)+'.str';

assign(fil,s);

reset(fil);

readln(fil,s);

readln(fil,s);

for i:=0 to 24 do

if s[i+1]='1' then F[i]:=true

else F[i]:=false;

readln(fil,s);

for i:=0 to 24 do

if s[i+1]='1' then E[i]:=true

else E[i]:=false;

for i:=1 to 15 do begin

readln(fil,s);

s1:=s;

for j:=1 to 7 do s1[j]:=' ';

ActList.Add(TMyZap.Create(StrToInt(s[1]+s[2]),s[3]+s[4]+s[5]+s[6],StrToInt(s[7]),s1));

end;

closefile(fil);

end;

procedure TForm1.FormActivate(Sender: TObject);

begin

Form1.ResultBtn.Visible:=False;

Form1.HelpBtn.Visible:=False;

Form1.Label2.Visible:=false;

Image1.Visible:=False;

Image2.Visible:=False;

StaticText1.Visible:=False;

Label2.Visible:=False;

StatusBar1.Panels[2].Text:='Выберите режим работы и задачу.';

StatusBar1.Panels[3].Text:='Режимработы: ';

TaskList.ItemIndex:=0;

TaskNumber:=0;

Read;

User1.User.ShowModal;

end;

procedure TForm1.ExtBtnClick(Sender: TObject);

begin

if Prot<>nil then Prot.Clear;

if ActList<>nil then ActList.Clear;

if Prot<>nil then Prot.Clear;

Application.Terminate;

end;

procedure TForm1.TaskListMouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

var Point:TPoint;

begin

Point.X:=Y;Point.Y:=Y;

TaskNumber:=TaskList.ItemAtPos(Point,true);

StatusBar1.Panels[2].Text:=Form1.TaskList.Items.Strings[TaskNumber];

StatusBar1.Panels[1].Text:='№'+IntToStr(1+TaskList.ItemAtPos(Point,true));

end;

procedure TForm1.RunBtnClick(Sender: TObject);

var s:string;

begin

TaskList.Visible:=False;

if WorkMode=0 then begin

StatusBar1.Panels[3].Text:='Режимработы: Тренировка';

Form1.HelpBtn.Visible:=true;

Form1.Label1.Visible:=true;

Form1.Label2.Visible:=true;

ResultBtn.Caption:='Результаты';

end;

Image1.Visible:=true;

Image2.Visible:=true;

StaticText1.Visible:=true;

ReadInfo(TaskNumber+1);

Error:=0;

Help:=0;

Form1.Caption:=TaskList.Items[TaskNumber];

{Начальные условия}

SWState(ODT2,0);

SWState(ODT1,1);

SWState(ODT3,3);

MVState(MBB1,10);

MVState(MBB2,7);

MVState(MBB3,19);

MVState(MBB4,17);

MVState(CMB1,8);

MVState(CMB2,18);

MVState(PBB2,4);

MVState(BB50,2);

SWState(TRZ1,6);

SWState(TRZ2,5);

SWState(TRZ3,16);

SWState(TRZ4,15);

SWState(SRZ1,14);

SWState(SRZ2,11);

SWState(SRZ3,24);

SWState(SRZ4,20);

SWState(SRZ9,12);

SWState(SR10,13);

SWState(SR20,23);

SWState(SR37,21);

ABRState(ABR1,9);

ABRState(ABR2,22);

Prot:=TStringList.Create;

if WorkMode=0 then s:=(' тренировки')

else s:=(' экзамена');

Prot.Append(' Протокол'+s);

Prot.Append(' ---------------------------');

Prot.Append('Фамилия: '+User1.N1);

Prot.Append('Имя: '+User1.N2);

Prot.Append('Отчество: '+User1.N3);

Prot.Append(' ЗАДАЧА: '+TaskList.Items[TaskNumber]);

Prot.Append(' --------------------------------------------');

if WorkMode=0 then s:=(' прохождения тренировки: ')

else s:=(' сдачи экзамена: ');

Prot.Append('Дата '+s+DateToStr(Date));

end;

procedure TForm1.Menu41Click(Sender: TObject);

begin

User.ShowModal;

end;

procedure TForm1.MBB1Click(Sender: TObject);

begin

if Analyze(MBB1)=True then MVState(MBB1,10)

else MVState(MBB1,10);

if F[10]=true then

end;

procedure TForm1.MBB2Click(Sender: TObject);

begin

if Analyze(MBB2)=True then MVState(MBB2,7)

else MVState(MBB2,7);

end;

procedure TForm1.MBB3Click(Sender: TObject);

begin

if Analyze(MBB3)=True then MVState(MBB3,19)

else MVState(MBB3,19);

end;

procedure TForm1.MBB4Click(Sender: TObject);

begin

if Analyze(MBB4)=True then MVState(MBB4,17)

else MVState(MBB4,17);

end;

procedure TForm1.CMB1Click(Sender: TObject);

begin

if Analyze(CMB1)=True then MVState(CMB1,8)

else MVState(CMB1,8);

end;

procedure TForm1.CMB2Click(Sender: TObject);

begin

if Analyze(CMB2)=True then MVState(CMB2,18)

else MVState(CMB2,18);

end;

procedure TForm1.BB50Click(Sender: TObject);

begin

if Analyze(BB50)=True then MVState(BB50,2)

else MVState(BB50,2);

end;

procedure TForm1.PBB2Click(Sender: TObject);

begin

if Analyze(PBB2)=True then MVState(PBB2,4)

else MVState(PBB2,4);

end;

procedure TForm1.TRZ1Click(Sender: TObject);

begin

if Analyze(TRZ1)=True then SWState(TRZ1,6)

else SWState(TRZ1,6);

end;

procedure TForm1.TRZ2Click(Sender: TObject);

begin

if Analyze(TRZ2)=True then SWState(TRZ2,5)

else SWState(TRZ2,5);

end;

procedure TForm1.TRZ3Click(Sender: TObject);

begin

if Analyze(TRZ3)=True then SWState(TRZ3,16)

else SWState(TRZ3,16);

end;

procedure TForm1.TRZ4Click(Sender: TObject);

begin

if Analyze(TRZ4)=True then SWState(TRZ4,15)

else SWState(TRZ4,15);

end;

procedure TForm1.SRZ1Click(Sender: TObject);

begin

if Analyze(SRZ1)=True then SWState(SRZ1,14)

else SWState(SRZ1,14);

end;

procedure TForm1.SRZ2Click(Sender: TObject);

begin

if Analyze(SRZ2)=True then SWState(SRZ2,11)

else SWState(SRZ2,11);

end;

procedure TForm1.SRZ3Click(Sender: TObject);

begin

if Analyze(SRZ3)=True then SWState(SRZ3,24)

else SWState(SRZ3,24);

end;

procedure TForm1.SRZ4Click(Sender: TObject);

begin

if Analyze(SRZ4)=True then SWState(SRZ4,20)

else SWState(SRZ4,20);

end;

procedure TForm1.SRZ9Click(Sender: TObject);

begin

if Analyze(SRZ9)=True then SWState(SRZ9,12)

else SWState(SRZ9,12);

end;

procedure TForm1.SR10Click(Sender: TObject);

begin

if Analyze(SR10)=True then SWState(SR10,13)

else SWState(SR10,13);

end;

procedure TForm1.SR20Click(Sender: TObject);

begin

if Analyze(SR20)=True then SWState(SR20,23)

else SWState(SR20,23);

end;

procedure TForm1.SR37Click(Sender: TObject);

begin

if Analyze(SR37)=True then SWState(SR37,21)

else SWState(SR37,21);

end;

procedure TForm1.ODT1Click(Sender: TObject);

begin

if Analyze(ODT1)=True then SWState(ODT1,1)

else SWState(ODT1,1);

end;

procedure TForm1.ODT2Click(Sender: TObject);

begin

if Analyze(ODT2)=True then SWState(ODT2,0)

else SWState(ODT2,0);

end;

procedure TForm1.ODT3Click(Sender: TObject);

begin

if Analyze(ODT3)=True then SWState(ODT3,3)

else SWState(ODT3,3);

end;

procedure TForm1.ABR1Click(Sender: TObject);

begin

if Analyze(ABR1)=True then ABRState(ABR1,9)

else ABRState(ABR1,9);

end;

procedure TForm1.ABR2Click(Sender: TObject);

begin

if Analyze(ABR2)=True then ABRState(ABR2,22)

else ABRState(ABR2,22);

end;

procedure TForm1.ResultBtnClick(Sender: TObject);

var i:integer;

s:string;

begin

Error:=0;

Count:=0;

if WorkMode=1 then begin

for i:=0 to 24 do if E[i]=F[i] then Error:=Error+1;

if Error=0 then s:='Хорошо';

if Error=1 then s:='Удовлетворительно';

if Error>2 then s:='Неудовлетворительно';

Results.Result.Label1.Caption:='Оценка: '+s;

Prot.Append('Оценка: '+s);

Results.Result.ShowModal;

TaskList.Visible:=True;

end;

if (WorkMode=0)and(Zap.FNo=0)and(Zap.FImage='0000')and(Zap.FState=0) then begin

Prot.Append('Количествоошибок: '+IntToStr(Error));

Prot.Append('Количество обращений к подсказке: '+IntToStr(Help));

Results.Result.Label1.Caption:='Количествоошибок: '+IntToStr(Error);

Results.Result.Label2.Caption:='Количествообращенийкподсказке: '+IntToStr(Help);

Results.Result.ShowModal;

Actlist.Clear;

TaskList.Visible:=True;

end;

end;

procedure TForm1.HelpBtnClick(Sender: TObject);

begin

if StatusBar1.Panels[1].Text='№'

then

Label1.Caption:=' Выберитезадачу'

else

begin

Zap:=ActList.First;

Label1.Caption:=Zap.FComment;

Help:=Help+1;

end;

end;

procedure TForm1.NewClick(Sender: TObject);

begin

FormScene.Position:=poScreenCenter;

FormScene.ShowModal;

end;

procedure TForm1.Menu52Click(Sender: TObject);

var s:string;

i:integer;

begin

Report.ReportForm.ProtList.Clear;

if Prot<>nil then begin

for i:=0 to Prot.Count-1 do

Report.ReportForm.ProtList.Items.Append(Prot.Strings[i]);

s:=TimeToStr(Now);

if FileExists('Info&bsol;Report.txt') then Prot.SaveToFile('Info&bsol;Report'+s[7]+'.txt')

else Prot.SaveToFile('Info&bsol;Report.txt');

ReportForm.ShowModal;

end;

end;

procedure TForm1.Menu21Click(Sender: TObject);

begin

WorkMode:=0;

StatusBar1.Panels[3].Text:='Режимработы: Тренировка';

Form1.HelpBtn.Visible:=true;

Form1.Label1.Visible:=true;

Form1.Label2.Visible:=true;

ResultBtn.Caption:='Результаты';

end;

procedure TForm1.Menu22Click(Sender: TObject);

begin

WorkMode:=1;

StatusBar1.Panels[3].Text:='Режимработы: Экзамен';

Form1.HelpBtn.Visible:=false;

Form1.Label1.Visible:=false;

Form1.Label2.Visible:=false;

ResultBtn.Caption:='Готово';

end;

end.