Jakiś błąd w Unit'cie

0

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

0

Może to dlatego:

T:=TMove.Create(..)

Nigdzie tego nie zwalniasz, a tworzysz za każdym uruchomieniem Push. Wygląda na to, że kolejne obiekty T zajmują coraz więcej pamięci.

0

sądząc po takich warunkach

if
(ASR and ASL and ASB and AST)
or
((not ASL) and ASR2 and AST and ASB)
or
((not ASR) and AST and ASB and ASL2)
or
(ASL and ASR and (not AST) and ASB2)
or
(ASL and ASR and (not ASB) and AST2)
or
((not ASL) and ASB2 and (not AST) and ASR2)
or
(AST2 and (not ASB) and (not ASL) and ASR2)
or
((not AST) and ASL2 and (not ASR) and ASB2)
or
((not ASB) and AST2 and (not ASR) and ASL2)
then

algorytmika nie jest twoją najmocniejszą strona

0

Pochwalony!
Może i tak, ale TMove robi określony kod i się zwalnia (linijka FreeOnTerminate := True;).
PS. Algorytmika, nie, ale dany kawałek działa :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1