Pochwalony! Zacząłem dzisiaj pisać taką gównia... nienajlepszą :) gierkę pod względem graficznym (i nie tylko :P ) i wkradł podczas prób mi się jakiś błąd. Zdaje mi się że to chodzi o coś z wątkami ale nie potrafię tego zidentyfikować. Sorki, że podaję cały kod, ale cholerka mnie bierze kiedy o tym myślę :P (Są na formie 3 komponenty TShape (Jeden to ja, drugi to nasza kula, a trzeci - cel do trafienia :D))
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Timer1: TTimer;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
procedure Push;
{ Private declarations }
public
Rusza: Boolean;
Licznik: Integer;
{ Public declarations }
end;
type
TMove = class(TThread)
public
procedure Check;
protected
procedure Execute; override;
end;
type
TObjectMove = class(TThread)
private
Ahead: Boolean;
protected
procedure Execute; override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
vk_Left: Shape1.Left := Shape1.Left - 5;
vk_Right: Shape1.Left := Shape1.Left + 5;
vk_Return: Push;
end;
end;
procedure TForm1.Push;
var
T: TMove;
begin
if not(Rusza) then
begin
Rusza := True;
Shape2.Visible := True;
Shape2.Top := Shape1.Top - Shape2.Height;
Shape2.Left := Shape1.Left;
T := TMove.Create(False);
end;
end;
{ TMove }
procedure TMove.Check;
function ASL: Boolean;
begin
Result := (Form1.Shape2.Left > Form1.Shape3.Left);
end;
function ASB: Boolean;
begin
Result := (Form1.Shape2.Top + Form1.Shape2.Height Form1.Shape3.Left);
end;
function ASL2: Boolean;
begin
Result := (Form1.Shape2.Left = 20 do
begin
Form1.Shape2.Top := Form1.Shape2.Top - 20;
Sleep(40);
end;
Synchronize(Check);
Form1.Shape2.Visible := False;
Form1.Rusza := False;
end;
{ TObjectMove }
procedure TObjectMove.Execute;
begin
FreeOnTerminate := True;
while not(Application.Terminated) do
begin
case Ahead of
True:
begin
Form1.Shape3.Left := Form1.Shape3.Left + 2;
if Form1.Shape3.Left >= Form1.Width - 20 - Form1.Shape3.Width then
Ahead := False;
end;
False:
begin
Form1.Shape3.Left := Form1.Shape3.Left - 2;
if Form1.Shape3.Left