Ignore:
Timestamp:
Jun 7, 2024, 12:47:11 PM (3 months ago)
Author:
chronos
Message:
  • Modified: Remove U prefix from unit names.
  • Modified: Used TFormEx for all forms for code simplification.
  • Fixed: Fullscreen mode switching error.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormComputer.pas

    r85 r86  
    1 unit UFormComputer;
    2 
    3 {$mode delphi}
     1unit FormComputer;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
    9   UGame, fgl;
     7  Game, Generics.Collections, Generics.Defaults, FormEx;
    108
    119type
     
    2321  end;
    2422
    25   TGameTries = class(TFPGObjectList<TGameTry>)
     23  TGameTries = class(TObjectList<TGameTry>)
     24  end;
     25
     26  { TGameTryComparer }
     27
     28  TGameTryComparer = class(TInterfacedObject, IComparer<TGameTry>)
     29    function Compare(constref Left, Right: TGameTry): Integer; overload;
    2630  end;
    2731
    2832  { TFormComputer }
    2933
    30   TFormComputer = class(TForm)
     34  TFormComputer = class(TFormEx)
    3135    ButtonStart: TButton;
    3236    ButtonStop: TButton;
     
    3842    procedure FormCreate(Sender: TObject);
    3943    procedure FormDestroy(Sender: TObject);
    40     procedure FormShow(Sender: TObject);
    4144  private
    4245    Stop: Boolean;
     
    4649    GameTries4: TGameTries;
    4750    procedure TryAllDirections(GameTries: TGameTries; GameTry: TGameTry);
    48   public
    49 
    50   end;
    51 
    52 var
    53   FormComputer: TFormComputer;
     51  end;
     52
    5453
    5554implementation
     
    5857
    5958uses
    60   UCore;
     59  Core;
    6160
    6261{ TGameTry }
     
    133132end;
    134133
     134{ TGameTryComparer }
     135
     136function TGameTryComparer.Compare(constref Left, Right: TGameTry): Integer;
     137var
     138  ScoreLeft: Double;
     139  ScoreRight: Double;
     140begin
     141  ScoreLeft := Left.GetFitness;
     142  ScoreRight := Right.GetFitness;
     143  if ScoreLeft > ScoreRight then Result := -1
     144  else if ScoreLeft < ScoreRight then Result := 1
     145  else Result := 0;
     146end;
     147
    135148{ TFormComputer }
    136149
     
    139152begin
    140153  ButtonStopClick(Self);
    141   Core.PersistentForm1.Save(Self);
    142154end;
    143155
     
    161173  J: Integer;
    162174  GameTries: TGameTries;
     175  GameTryComparer: TGameTryComparer;
    163176  Delay: Integer;
    164177begin
     
    166179  ButtonStop.Enabled := True;
    167180  Stop := False;
    168   with Core.Game do begin
     181  with Core.Core.Game do begin
    169182    while CanMove and not Stop do begin
    170183      NewTry := TGameTry.Create;
    171       NewTry.Game.Assign(Core.Game);
     184      NewTry.Game.Assign(Core.Core.Game);
    172185      GameTries1.Clear;
    173186      TryAllDirections(GameTries1, NewTry);
     
    184197
    185198      GameTries := GameTries4;
    186       GameTries.Sort(GameCompareScore);
     199      GameTryComparer := TGameTryComparer.Create;
     200      GameTries.Sort(GameTryComparer);
    187201      S := '';
    188202      for I := 0 to GameTries.Count - 1 do begin
     
    221235procedure TFormComputer.FormCreate(Sender: TObject);
    222236begin
    223   Core.Translator1.TranslateComponentRecursive(Self);
    224   Core.ThemeManager1.UseTheme(Self);
    225237  GameTries1 := TGameTries.Create;
    226238  GameTries2 := TGameTries.Create;
     
    235247  FreeAndNil(GameTries3);
    236248  FreeAndNil(GameTries4);
    237 end;
    238 
    239 procedure TFormComputer.FormShow(Sender: TObject);
    240 begin
    241   Core.PersistentForm1.Load(Self);
    242249end;
    243250
Note: See TracChangeset for help on using the changeset viewer.