Changeset 22 for trunk


Ignore:
Timestamp:
Mar 1, 2014, 5:56:14 PM (11 years ago)
Author:
chronos
Message:
  • Added: New Core unit which is responsible for non-visual functionality. FormMain will handle main form related stuff.
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Languages/xtactics.po

    r21 r22  
    22msgstr "Content-Type: text/plain; charset=UTF-8"
    33
    4 #: tformmain.aexit.caption
     4#: tcore.aexit.caption
     5msgctxt "TCORE.AEXIT.CAPTION"
    56msgid "Exit"
    67msgstr ""
    78
    8 #: tformmain.agameend.caption
     9#: tcore.agameend.caption
     10msgctxt "TCORE.AGAMEEND.CAPTION"
    911msgid "End"
    1012msgstr ""
    1113
    12 #: tformmain.agameendturn.caption
     14#: tcore.agameendturn.caption
     15msgctxt "TCORE.AGAMEENDTURN.CAPTION"
    1316msgid "End turn"
    1417msgstr ""
    1518
    16 #: tformmain.agamenew.caption
     19#: tcore.agamenew.caption
     20msgctxt "TCORE.AGAMENEW.CAPTION"
    1721msgid "New"
    1822msgstr ""
    1923
    20 #: tformmain.agamerestart.caption
     24#: tcore.agamerestart.caption
     25msgctxt "TCORE.AGAMERESTART.CAPTION"
    2126msgid "Restart"
    2227msgstr ""
     
    3439msgstr ""
    3540
    36 #: uformmain.splayerwins
     41#: ucore.splayerwins
     42msgctxt "ucore.splayerwins"
    3743msgid "Player %s wins"
    3844msgstr ""
    3945
     46#: uformmain.splayerwins
     47msgctxt "uformmain.splayerwins"
     48msgid "Player %s wins"
     49msgstr ""
     50
     51#: ugame.sminimumplayers
     52msgid "You need at least two players"
     53msgstr ""
     54
  • trunk/UFormMain.lfm

    r20 r22  
    88  ClientWidth = 775
    99  Menu = MainMenu1
     10  OnActivate = FormActivate
    1011  OnCreate = FormCreate
    1112  OnDestroy = FormDestroy
     
    3435      Caption = 'Game'
    3536      object MenuItem2: TMenuItem
    36         Action = AGameNew
     37        Action = Core.AGameNew
    3738      end
    3839      object MenuItem3: TMenuItem
    39         Action = AGameEnd
     40        Action = Core.AGameEnd
    4041      end
    4142      object MenuItem7: TMenuItem
    42         Action = AGameRestart
     43        Action = Core.AGameRestart
    4344      end
    4445      object MenuItem4: TMenuItem
    45         Action = AGameEndTurn
     46        Action = Core.AGameEndTurn
    4647      end
    4748      object MenuItem5: TMenuItem
     
    4950      end
    5051      object MenuItem6: TMenuItem
    51         Action = AExit
     52        Action = Core.AExit
    5253      end
    53     end
    54   end
    55   object ActionList1: TActionList
    56     left = 224
    57     top = 49
    58     object AGameNew: TAction
    59       Caption = 'New'
    60       OnExecute = AGameNewExecute
    61       ShortCut = 16462
    62     end
    63     object AExit: TAction
    64       Caption = 'Exit'
    65       OnExecute = AExitExecute
    66       ShortCut = 32883
    67     end
    68     object AGameEnd: TAction
    69       Caption = 'End'
    70       OnExecute = AGameEndExecute
    71       ShortCut = 16454
    72     end
    73     object AGameEndTurn: TAction
    74       Caption = 'End turn'
    75       OnExecute = AGameEndTurnExecute
    76       ShortCut = 16468
    77     end
    78     object AGameRestart: TAction
    79       Caption = 'Restart'
    80       OnExecute = AGameRestartExecute
    81       ShortCut = 16466
    8254    end
    8355  end
  • trunk/UFormMain.lrt

    r20 r22  
    22TFORMMAIN.MENUITEM1.CAPTION=Game
    33TFORMMAIN.MENUITEM5.CAPTION=-
    4 TFORMMAIN.AGAMENEW.CAPTION=New
    5 TFORMMAIN.AEXIT.CAPTION=Exit
    6 TFORMMAIN.AGAMEEND.CAPTION=End
    7 TFORMMAIN.AGAMEENDTURN.CAPTION=End turn
    8 TFORMMAIN.AGAMERESTART.CAPTION=Restart
  • trunk/UFormMain.pas

    r21 r22  
    1717
    1818  TFormMain = class(TForm)
    19     AGameRestart: TAction;
    20     AGameEndTurn: TAction;
    21     AGameEnd: TAction;
    22     AExit: TAction;
    23     AGameNew: TAction;
    24     ActionList1: TActionList;
    2519    MainMenu1: TMainMenu;
    2620    MenuItem1: TMenuItem;
     
    3327    PaintBox1: TPaintBox;
    3428    Timer1: TTimer;
    35     procedure AExitExecute(Sender: TObject);
    36     procedure AGameEndExecute(Sender: TObject);
    37     procedure AGameEndTurnExecute(Sender: TObject);
    38     procedure AGameNewExecute(Sender: TObject);
    39     procedure AGameRestartExecute(Sender: TObject);
     29    procedure FormActivate(Sender: TObject);
    4030    procedure FormCreate(Sender: TObject);
    4131    procedure FormDestroy(Sender: TObject);
     
    6151    MoveActive: Boolean;
    6252    RedrawPending: Boolean;
    63     procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer);
    64     procedure DoOnWin(Player: TPlayer);
    6553  public
    66     Game: TGame;
    6754    procedure Redraw;
    6855  end;
     
    7461
    7562uses
    76   UFormNew, UFormMove;
    77 
    78 resourcestring
    79   SPlayerWins = 'Player %s wins';
     63  UFormNew, UFormMove, UCore;
    8064
    8165{$R *.lfm}
     
    8569procedure TFormMain.PaintBox1Paint(Sender: TObject);
    8670begin
    87   if Game.Running then
    88   with Game.CurrentPlayer do begin
     71  if Core.Game.Running then
     72  with Core.Game.CurrentPlayer do begin
    8973    ViewSize := Point(PaintBox1.Width, PaintBox1.Height);
    9074    Paint(PaintBox1);
     
    9882procedure TFormMain.PaintBox1Resize(Sender: TObject);
    9983begin
    100   if Assigned(Game.CurrentPlayer) then
    101   with Game.CurrentPlayer do
     84  if Assigned(Core.Game.CurrentPlayer) then
     85  with Core.Game.CurrentPlayer do
    10286    ViewSize := Point(PaintBox1.Width, PaintBox1.Height);
    10387  Redraw;
     
    11397
    11498    NewCaption := 'xTactics';
    115     if Assigned(Game.CurrentPlayer) then
    116       NewCaption := Game.CurrentPlayer.Name + ' - turn ' + IntToStr(Game.TurnCounter) + ' - ' + NewCaption;
     99    if Assigned(Core.Game.CurrentPlayer) then
     100      NewCaption := Core.Game.CurrentPlayer.Name + ' - turn ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption;
    117101    Caption := NewCaption;
    118102  end;
    119 end;
    120 
    121 procedure TFormMain.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
    122   CountRepeat: Integer);
    123 begin
    124   FormMove.SpinEditOnce.Value := CountOnce;
    125   FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower;
    126   FormMove.SpinEditRepeat.Value := CountRepeat;
    127   FormMove.SpinEditRepeat.MaxValue := Game.Map.MaxPower;
    128   if FormMove.ShowModal = mrOk then begin
    129     CountOnce := FormMove.SpinEditOnce.Value;
    130     CountRepeat := FormMove.SpinEditRepeat.Value;
    131   end;
    132 end;
    133 
    134 procedure TFormMain.DoOnWin(Player: TPlayer);
    135 begin
    136   ShowMessage(Format(SPlayerWins, [Player.Name]));
    137103end;
    138104
     
    144110procedure TFormMain.FormCreate(Sender: TObject);
    145111begin
    146   Game := TGame.Create;
    147   Game.OnMove := DoOnMove;
    148   Game.OnWin := DoOnWin;
    149112end;
    150113
    151 procedure TFormMain.AExitExecute(Sender: TObject);
     114procedure TFormMain.FormActivate(Sender: TObject);
    152115begin
    153   Application.Terminate;
    154 end;
    155 
    156 procedure TFormMain.AGameEndExecute(Sender: TObject);
    157 begin
    158   Game.Running := False;
    159   Redraw;
    160 end;
    161 
    162 procedure TFormMain.AGameEndTurnExecute(Sender: TObject);
    163 begin
    164   Game.NextTurn;
    165   Redraw;
    166   while Game.Running and (Game.CurrentPlayer.Mode <> pmHuman) do begin
    167     Game.NextTurn;
    168     Redraw;
     116  if not Core.Initialized then begin
     117    Core.Init;
    169118  end;
    170 end;
    171 
    172 procedure TFormMain.AGameNewExecute(Sender: TObject);
    173 begin
    174   FormNew.Load(Game);
    175   if FormNew.ShowModal = mrOk then begin
    176     FormNew.Save(Game);
    177     Game.New;
    178     Game.Running := True;
    179     Redraw;
    180   end;
    181 end;
    182 
    183 procedure TFormMain.AGameRestartExecute(Sender: TObject);
    184 begin
    185   Game.New;
    186   Game.Running := True;
    187   Redraw;
    188119end;
    189120
    190121procedure TFormMain.FormDestroy(Sender: TObject);
    191122begin
    192   FreeAndNil(Game);
    193123end;
    194124
    195125procedure TFormMain.FormShow(Sender: TObject);
    196 var
    197   I: Integer;
    198126begin
    199   for I := 0 to Game.Players.Count - 1 do
    200     TPlayer(Game.Players[I]).ViewSize := Point(PaintBox1.Canvas.Width, PaintBox1.Canvas.Height);
    201   Game.New;
    202   Game.Running := True;
    203127  Redraw;
    204128end;
     
    208132begin
    209133  if Button = mbLeft then begin
    210     if Game.CurrentPlayer.Mode = pmHuman then begin
     134    if Core.Game.CurrentPlayer.Mode = pmHuman then begin
    211135      StartMousePoint := Point(X, Y);
    212       StartViewPoint := Game.CurrentPlayer.CellPos;
     136      StartViewPoint := Core.Game.CurrentPlayer.CellPos;
    213137      MoveActive := True;
    214138    end;
     
    225149begin
    226150  if MoveActive then begin
    227     if Game.CurrentPlayer.Mode = pmHuman then begin
    228       Game.CurrentPlayer.CellPos := Point(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / Game.CurrentPlayer.ViewZoom),
    229         Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / Game.CurrentPlayer.ViewZoom));
     151    if Core.Game.CurrentPlayer.Mode = pmHuman then begin
     152      Core.Game.CurrentPlayer.CellPos := Point(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / Core.Game.CurrentPlayer.ViewZoom),
     153        Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / Core.Game.CurrentPlayer.ViewZoom));
    230154      Redraw;
    231155    end;
     
    237161begin
    238162  if (Abs(StartMousePoint.X - X) < 5) and (Abs(StartMousePoint.Y - Y) < 5) then begin
    239     if Game.Running and (Game.CurrentPlayer.Mode = pmHuman) then begin
    240       Game.CurrentPlayer.SelectCell(Point(X, Y));
     163    if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) then begin
     164      Core.Game.CurrentPlayer.SelectCell(Point(X, Y));
    241165      Redraw;
    242166    end;
     
    250174  D: TPoint;
    251175begin
    252   with Game.CurrentPlayer do begin
     176  with Core.Game.CurrentPlayer do begin
    253177    //D := Point(Trunc(MousePos.X - View.Left / ViewZoom),
    254178    //  Trunc(MousePos.Y - View.Top / ViewZoom));
     
    265189  MousePos: TPoint; var Handled: Boolean);
    266190begin
    267   with Game.CurrentPlayer do
     191  with Core.Game.CurrentPlayer do
    268192    ViewZoom := ViewZoom * ZoomFactor;
    269193  Redraw;
  • trunk/UGame.pas

    r21 r22  
    144144implementation
    145145
     146resourcestring
     147  SMinimumPlayers = 'You need at least two players';
     148
    146149function FloatPoint(AX, AY: Double): TFloatPoint;
    147150begin
     
    379382  if FRunning = AValue then Exit;
    380383  if AValue then begin
    381     if Players.Count < 2 then raise Exception.Create('You need at least two players');
     384    if Players.Count < 2 then raise Exception.Create(SMinimumPlayers);
    382385    FRunning := AValue;
    383386  end else FRunning := AValue;
  • trunk/xtactics.lpi

    r20 r22  
    7777      </Item1>
    7878    </RequiredPackages>
    79     <Units Count="5">
     79    <Units Count="6">
    8080      <Unit0>
    8181        <Filename Value="xtactics.lpr"/>
     
    112112        <UnitName Value="UFormMove"/>
    113113      </Unit4>
     114      <Unit5>
     115        <Filename Value="UCore.pas"/>
     116        <IsPartOfProject Value="True"/>
     117        <ComponentName Value="Core"/>
     118        <HasResources Value="True"/>
     119        <ResourceBaseClass Value="DataModule"/>
     120        <UnitName Value="UCore"/>
     121      </Unit5>
    114122    </Units>
    115123  </ProjectOptions>
     
    136144        <StackChecks Value="True"/>
    137145      </Checks>
    138       <VerifyObjMethodCallValidity Value="True"/>
    139146    </CodeGeneration>
    140147    <Linking>
  • trunk/xtactics.lpr

    r12 r22  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UGame, UFormNew, UFormMove
     10  Forms, UFormMain, UGame, UFormNew, UFormMove, UCore
    1111  { you can add units after this };
    1212
     
    1616  RequireDerivedFormResource := True;
    1717  Application.Initialize;
     18  Application.CreateForm(TCore, Core);
    1819  Application.CreateForm(TFormMain, FormMain);
    1920  Application.CreateForm(TFormNew, FormNew);
Note: See TracChangeset for help on using the changeset viewer.