Ignore:
Timestamp:
Oct 4, 2019, 11:05:35 PM (5 years ago)
Author:
chronos
Message:
  • Added: Show Top score and remember it after application restart.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r8 r10  
    3535  private
    3636  public
    37     Game: TGame;
    38     procedure GameChange(Sender: TObject);
    3937  end;
    4038
     
    5553  MovedCount: Integer;
    5654begin
    57   if Game.Running then begin
     55  if Core.Game.Running then begin
    5856    MovedCount := 0;
    5957    case Key of
    60       37: MovedCount := Game.MoveAll(drLeft);
    61       38: MovedCount := Game.MoveAll(drUp);
    62       39: MovedCount := Game.MoveAll(drRight);
    63       40: MovedCount := Game.MoveAll(drDown);
     58      37: MovedCount := Core.Game.MoveAll(drLeft);
     59      38: MovedCount := Core.Game.MoveAll(drUp);
     60      39: MovedCount := Core.Game.MoveAll(drRight);
     61      40: MovedCount := Core.Game.MoveAll(drDown);
    6462    end;
    65     if MovedCount > 0 then Game.FillRandomCell;
    66     if not Game.CanMove and (Game.GetEmptyCellsCount = 0) then
    67       Game.GameOver;
     63    if MovedCount > 0 then Core.Game.FillRandomCell;
     64    if not Core.Game.CanMove and (Core.Game.GetEmptyCellsCount = 0) then
     65      Core.Game.GameOver;
    6866  end;
    6967end;
     
    7169procedure TFormMain.FormPaint(Sender: TObject);
    7270begin
    73   Game.Render(Canvas, Point(Width, Height - MainMenu1.Height));
     71  Core.Game.Render(Canvas, Point(Width, Height - MainMenu1.Height));
    7472end;
    7573
     
    7876  FormNew := TFormNew.Create(nil);
    7977  try
    80     FormNew.Load(Game);
     78    FormNew.Load(Core.Game);
    8179    if FormNew.ShowModal = mrOk then begin
    82       FormNew.Save(Game);
    83       Game.New;
     80      FormNew.Save(Core.Game);
     81      Core.Game.New;
    8482    end;
    8583  finally
     
    111109procedure TFormMain.FormCreate(Sender: TObject);
    112110begin
    113   Randomize;
    114   Game := TGame.Create;
    115   Game.Size := Point(4, 4);
    116   Game.OnChange := GameChange;
    117111end;
    118112
    119113procedure TFormMain.FormDestroy(Sender: TObject);
    120114begin
    121   Game.Free;
    122115end;
    123116
     
    126119  Core.PersistentForm1.RegistryContext := Core.ApplicationInfo1.GetRegistryContext;
    127120  Core.PersistentForm1.Load(Self);
    128   Game.New;
    129   {
    130   Game.Cells[0, 0].Value := 1;
    131   Game.Cells[0, 1].Value := 2;
    132   Game.Cells[0, 2].Value := 3;
    133   Game.Cells[1, 0].Value := 4;
    134   Game.Cells[1, 1].Value := 5;
    135   Game.Cells[1, 2].Value := 6;
    136   Game.Cells[2, 0].Value := 7;
    137   Game.Cells[2, 1].Value := 8;
    138   Game.Cells[2, 2].Value := 9;
    139   }
    140 end;
    141 
    142 procedure TFormMain.GameChange(Sender: TObject);
    143 begin
    144   Repaint;
     121  Core.Game.New;
    145122end;
    146123
Note: See TracChangeset for help on using the changeset viewer.