Changeset 29 for trunk/UCore.pas


Ignore:
Timestamp:
Oct 6, 2019, 9:53:39 PM (5 years ago)
Author:
chronos
Message:
  • Added: Computer player accessible from Tools menu in Debug mode. It is not able to win game yet.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r28 r29  
    77uses
    88  Classes, SysUtils, UTheme, UPersistentForm, UApplicationInfo, UTranslator,
    9   URegistry, UGame, ActnList, Forms, Controls;
     9  URegistry, UGame, ActnList, Forms, Controls, Dialogs;
    1010
    1111type
     
    1515  TCore = class(TDataModule)
    1616    AAbout: TAction;
     17    AComputer: TAction;
    1718    AHelp: TAction;
    1819    AUndo: TAction;
     
    2627    Translator1: TTranslator;
    2728    procedure AAboutExecute(Sender: TObject);
     29    procedure AComputerExecute(Sender: TObject);
    2830    procedure AExitExecute(Sender: TObject);
    2931    procedure AHelpExecute(Sender: TObject);
     
    3537  private
    3638    procedure GameChange(Sender: TObject);
     39    procedure GameWin(Sender: TObject);
     40    procedure GameOver(Sender: TObject);
    3741  public
    3842    Game: TGame;
     
    5054
    5155uses
    52   UFormMain, UFormSettings, UFormAbout, UFormNew, UFormHelp;
     56  UFormMain, UFormSettings, UFormAbout, UFormNew, UFormHelp, UFormComputer;
     57
     58resourcestring
     59  SGameOverCaption = 'Lost';
     60  SGameOverMessage = 'Game over!';
     61  SWinCaption = 'Win';
     62  SWinMessage = 'You reached %d and won! You can continue to play to get higher score.';
    5363
    5464{ TCore }
     
    6676  Game.Board.Size := Point(4, 4);
    6777  Game.OnChange := GameChange;
     78  Game.OnWin := GameWin;
    6879  LoadConfig;
    6980end;
     
    92103  finally
    93104    FreeAndNil(FormAbout);
     105  end;
     106end;
     107
     108procedure TCore.AComputerExecute(Sender: TObject);
     109begin
     110  FormComputer := TFormComputer.Create(nil);
     111  try
     112    FormComputer.ShowModal;
     113  finally
     114    FreeAndNil(FormComputer);
    94115  end;
    95116end;
     
    136157end;
    137158
     159procedure TCore.GameWin(Sender: TObject);
     160begin
     161  MessageDlg(SWinCaption, Format(SWinMessage, [Game.WinScore]), mtInformation, [mbOk], 0);
     162end;
     163
     164procedure TCore.GameOver(Sender: TObject);
     165begin
     166  MessageDlg(SGameOverCaption, SGameOverMessage, mtInformation, [mbOK], 0);
     167end;
     168
    138169procedure TCore.UpdateInterface;
    139170begin
    140171  AUndo.Enabled := Game.CanUndo;
     172  {$IFDEF DEBUG}
     173  AComputer.Enabled := True;
     174  {$ELSE}
     175  AComputer.Enabled := False;
     176  {$ENDIF}
    141177end;
    142178
Note: See TracChangeset for help on using the changeset viewer.