.


:




:

































 

 

 

 





procedure Ellipse(X1, Y1, X2, Y2: Integer);

Ellipse Pen. Brush. (X1, Y1) (X2, Y2) , .

 

procedure Rectangle(X1, Y1, X2, Y2: Integer);

Pen , (X1, Y1), - (X2, Y2). Brush.

 

 


 

 

-

 

 

-

 

:

 

 

 

. <>

..

< >:

..

 

:

1. →

2. :

3. : OnMouseDown

 

 

4.

Form1.Canvas.Ellipse(X+sizeObj, Y+sizeObj, X-sizeObj, Y-sizeObj);

sizeObj - : const sizeObj=20;

5. (F9) , .

, .

. .

.

6. , . : OnPaint.

, . , (Form1.Width).

 

procedure TForm1.FormPaint(Sender: TObject);

var i:integer;

begin

for i:=0 to Round(Form1.Width/sizeObj) do

Form1.canvas.Rectangle(sizeObj*i, 0, sizeObj*(i+1), sizeObj);

end;

7. . , . , sizeObj. : OnResize

 

:

Form1.Width:=sizeObj*round(Form1.Width/sizeObj);

 

8. .

:

, (Form1. Height/sizeObj).

FormPaint :

 

procedure TForm1.FormPaint(Sender: TObject);

var i:integer;

begin

for i:=0 to Round(Form1.Width/sizeObj) do {create Top Windows}

Form1.canvas.Rectangle(sizeObj*i, 0, sizeObj*(i+1), sizeObj);

 

for i:=0 to Round(Form1. Height/sizeObj) do {create Left Windows}

Form1.canvas.Rectangle(0,sizeObj*i, sizeObj, sizeObj*(i+1));

 

for i:=0 to Round(Form1. Height/sizeObj) do {create Right Windows}

Form1.canvas.Rectangle(Form1.Width,sizeObj*i,

Form1.Width- sizeObj, sizeObj*(i+1));

 

end;

9. , 7 , (Form1. Height)

 

10. , . : OnKeyDown:

 

.

, Key Word. , - . , : :

ShowMessage(IntToStr(Key));

. ← = 37, → =39. - Ord ('S').

, .. . - . coorXObj . Integer, coorXObj:integer=sizeObj;

 

11. .

Key=37 coorXObj , Key=39 coorXObj .

if Key=37 then coorXObj:=coorXObj-sizeObj;

if Key=39 then coorXObj:=coorXObj+sizeObj;

 

12. , FormPaint:

 

Form1.canvas.Rectangle(coorXObj, Form1.Height- sizeObj,

coorXObj+sizeObj, Form1.Height);

13. . , . , . , FormKeyDown .

FormPaint(Sender);

14. . , . ,

Form1.Repaint

15. . , . coorXObj .

sizeObj <=coorXObj and coorXObj <= (Form1.Width 2*sizeObj).

 

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

begin

 

if (Key=37) and not (sizeObj =coorXObj) then coorXObj:=coorXObj-sizeObj;

if (Key=39) and not (coorXObj = (Form1.Width - 2*sizeObj)) then

coorXObj:=coorXObj+sizeObj;

Form1.Repaint;

end;

16. , coorXObj .

 

17.

1. .

2. .

3. , .

 

18. - , . System

 

.

OnTimer

19. , , . , .

type TBall=class

X,Y, dx,dy:integer;

procedure SetDefault;

end;

 

procedure TBall.SetDefault;

begin

X:=sizeObj;

Y:=sizeObj;

dx:=1;

dy:=2;

end;

 

var

Ball:TBall;

, , .

:

If key = 116 then { - F5}

StartNewGame;

StartNewGame , TForm1.

 

:

procedure TForm1.StartNewGame;

begin

Ball:= TBall.Create; { }

Ball.SetDefault;

Timer1.Enabled:=True; { }

end;

 

20. Timer1Timer - .

Ball.X:= Ball.X+ Ball.dx;

Ball.Y:= Ball.Y+ Ball.dy;

100.

 

 

21. .

record

Type TMinMax=record

min,max:integer;

End;

Type TField=record

X,Y: TMinMax;

End;

 

Var

WorkField: TField;

 

22. procedure CalculationWorkField; TForm1;.

:

procedure TForm1.CalculationWorkField;

begin

WorkField.X.min:=sizeObj;

WorkField.Y.min:=sizeObj;

WorkField.X.max:=Form1.Width-sizeObj;

WorkField.Y.max:=Form1.Height-sizeObj;

end;

 

23. CalculationWorkField .. FormResize.

 

24. . FormKeyDown. .

if (Key=37) and not (coorXObj= sizeObj) then coorXObj:=coorXObj-sizeObj;

if (Key=39) and not (coorXObj = (Form1.Width - 4*sizeObj)) then

coorXObj:=coorXObj+sizeObj;

 

:

if (Key=37) and not (coorXObj = WorkField.X.min) then coorXObj:=coorXObj-sizeObj;

if (Key=39) and not (coorXObj = (WorkField.X. max - 3*sizeObj)) then

coorXObj:=coorXObj+sizeObj;

, , 3* sizeObj ( ).

FormPaint , :

-
Form1.Width/sizeObj WorkField.X.max/sizeObj
Form1.Height/sizeObj WorkField.Y.max/sizeObj

:

for i:=0 to Round(Form1.Height/sizeObj) do {create Right Windows}

Form1.canvas.Rectangle(Form1.Width,sizeObj*i,

Form1.Width- sizeObj, sizeObj*(i+1));

for i:=0 to 2 do

Form1.canvas.Rectangle(coorXObj+sizeObj*i, Form1.Height- sizeObj,

coorXObj+sizeObj*(i+1), Form1.Height);

 

:

for i:=0 to Round(WorkField.Y.max/sizeObj) do {create Right Windows}

Form1.canvas.Rectangle(WorkField.X.max,sizeObj*i,

WorkField.X.max+ sizeObj, sizeObj*(i+1));

for i:=0 to 2 do

Form1.canvas.Rectangle(coorXObj+sizeObj*i, WorkField.Y.max,

coorXObj+sizeObj*(i+1), WorkField.Y.max+ sizeObj);

 

25. Timer1Timer.

If (Ball.X= WorkField.X.min) or (Ball.X= WorkField.X.max- sizeObj) then

Ball.dx:= -1*Ball.dx;

Y, , .

 

If (Ball.Y= WorkField.Y.min) then Ball.dy:= -1*Ball.dy; { }

 

If (Ball.Y= WorkField.Y.max -sizeObj) then begin { }

if ((coorXObj<= Ball.X) and (coorXObj+3* sizeObj >= Ball.X)) then

Ball.dy:= -1*Ball.dy

Else begin

ShowMessage('Game over');

Timer1.Enabled:=false; { }

GameIsStart:=false;

Ball.Free;{ }

end;

end;

 

, , sizeObj

 

26. , Timer1Timer, (TBall) function Move():Boolean; . : BallInOutWorkField=true; {- }

 

function TBall.Move():Boolean;

begin

result:=not BallInOutWorkField;

X:= X+ dx;

Y:= Y+ dy;

 

If (X= WorkField.X.min) or (X= WorkField.X.max- sizeObj) then

dx:= -1*dx;

If (Y= WorkField.Y.min) then dy:= -1*dy;

 

If (Y= WorkField.Y.max- sizeObj) then begin { }

if ((coorXObj<= X) and

(coorXObj+3* sizeObj >= X)) then

dy:= -1*dy

Else result:=BallInOutWorkField;

 

end;

end;

 

27. Timer1Timer.

procedure TForm1.Timer1Timer(Sender: TObject);

begin

if Ball.Move()=BallInOutWorkField then begin

ShowMessage('Game over');

Timer1.Enabled:=false; { }

GameIsStart:=false;

Ball.Free;

end;

Form1.Repaint;

end;

 

28. . Draw()

procedure TBall.Draw();

begin

Form1.canvas.Ellipse(X, Y, X+sizeObj, Y+sizeObj);

end;

FormPaint.

Ball.Draw();

 

29. . , StartNewGame, , Ball.. Ball.Draw(), (GameIsStart) .

Var GameIsStart: Boolean=false;

StartNewGame GameIsStart:=true; { }

FormPaint

If GameIsStart then TBall.Draw();

30. . , . :

if ((coorXObj<= X+sizeObj/2) and

(coorXObj+3* sizeObj >= X+sizeObj/2)) then

31. . . .

32. :

.

. ( )

. .

.

33. , .

 

 

B

MySQL

1. MySQL. : libmysql.dll.

2. SQLbd

TMySQL50Connection ( )

TSQLTransaction

TSQLQuery ( , )

3. Data Access TDatasource.

4. ( , ).

MySQL50Connection1.Transaction SQLTransaction1
SQLTransaction1.Database MySQL50Connection1
SQLQuery1.Database MySQL50Connection1
SQLQuery1.Transaction SQLTransaction1
Datasource1.DataSet SQLQuery1

 

5. , MySQL50Connection1 :

DatabaseName=FileSystem

HostName=localhost

UserName=root

DatabaseName - ,

HostName - ,

UserName - ,

Password - ( )

6.

procedure TForm1.ConnectToBase();

begin

try

MySQL50Connection1.Connected:=true;

except

ShowMessage(' '+

MySQL50Connection1.DatabaseName);

exit;

end;

try

SQLQuery1.Active:=false;

SQLQuery1.SQL.Clear;

SQLQuery1.sql.add(

'SET character_set_client='+#39+'utf8'+#39+

', character_set_connection='+#39+'utf8'+#39+

',character_set_results='+

#39+'utf8'+#39+';');

SQLQuery1.ExecSQL;

SQLQuery1.SQL.Clear;

except

ShowMessage(' .');

end;

end;

, MySQL , , SQLQuery1 SQL , .

 

SET character_set_results='utf8'; /* */

SET character_set_client='utf8'; /* */

SET character_set_connection='utf8' /* , , .*/

 

7. , . ( D.S., users usersDS)

procedure TForm1.CreateAllTable();

begin

if SQLQuery1.Active then SQLQuery1.Close;

SQLQuery1.SQL.Clear;

 

SQLQuery1.SQL.Add(

'create table '+

'if not exists usersDS' +

'('+

' id INTEGER PRIMARY KEY '+

' AUTO_INCREMENT NOT NULL'+

', username varchar(255)'+

', rating INTEGER UNSIGNED'+

', color_ball varchar(20)'+

', color_racket varchar(20)'+

', color_walls varchar(20)'+

', color_background varchar(20)'+

');');

SQLQuery1.ExecSQL;

end;

8. .

 

SQLQuery1.SQL.Clear;

SQLQuery1.SQL.Add('Select * from usersDS;');

SQLQuery1.Open;

SQLQuery1.DataSet.First;

If Datasource1.DataSet.IsEmpty then

ShowMessage(' ');

else begin

with Datasource1.DataSet do begin

username:=FieldByName('username').AsWideString;

rating:=FieldByName('rating').AsInteger;

// username

// TComboBox TListBox

end;

end;

9. . .

 

procedure TForm1.DisConnect();

begin

SQLQuery1.Active:=false;

SQLTransaction1.Commit;

MySQL50Connection1.Connected:=false;

end;

10.

 

try

SQLQuery1.Close;

SQLQuery1.SQL.Clear;

SQLQuery1.sql.add('UPDATE usersDS SET rating=100;');

SQLQuery1.ExecSQL;

except

ShowMessage(' SQL .');

exit;

end;

 

 





:


: 2016-11-20; !; : 297 |


:

:

, .
==> ...

1524 - | 1317 -


© 2015-2024 lektsii.org - -

: 0.147 .