Changeset 38


Ignore:
Timestamp:
Oct 13, 2019, 5:34:57 PM (5 years ago)
Author:
chronos
Message:
  • Added: In computer AI form allow to set delay of steps computation. Set to zero means fastest processing.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormComputer.lfm

    r32 r38  
    3232    TabOrder = 1
    3333  end
     34  object TrackBar1: TTrackBar
     35    Left = 24
     36    Height = 58
     37    Top = 104
     38    Width = 430
     39    Max = 1000
     40    Position = 0
     41    Anchors = [akTop, akLeft, akRight]
     42    TabOrder = 2
     43  end
     44  object Label1: TLabel
     45    Left = 21
     46    Height = 26
     47    Top = 76
     48    Width = 127
     49    Caption = 'Delay per step:'
     50    ParentColor = False
     51  end
    3452end
  • trunk/Forms/UFormComputer.lrj

    r32 r38  
    22{"hash":1113,"name":"tformcomputer.caption","sourcebytes":[65,73],"value":"AI"},
    33{"hash":5941396,"name":"tformcomputer.buttonstart.caption","sourcebytes":[83,116,97,114,116],"value":"Start"},
    4 {"hash":371552,"name":"tformcomputer.buttonstop.caption","sourcebytes":[83,116,111,112],"value":"Stop"}
     4{"hash":371552,"name":"tformcomputer.buttonstop.caption","sourcebytes":[83,116,111,112],"value":"Stop"},
     5{"hash":116494394,"name":"tformcomputer.label1.caption","sourcebytes":[68,101,108,97,121,32,112,101,114,32,115,116,101,112,58],"value":"Delay per step:"}
    56]}
  • trunk/Forms/UFormComputer.pas

    r32 r38  
    66
    77uses
    8   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, UGame, fgl;
     8  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
     9  UGame, fgl;
    910
    1011type
     
    3031    ButtonStart: TButton;
    3132    ButtonStop: TButton;
     33    Label1: TLabel;
     34    TrackBar1: TTrackBar;
    3235    procedure ButtonStartClick(Sender: TObject);
    3336    procedure ButtonStopClick(Sender: TObject);
     
    135138  );
    136139begin
     140  ButtonStopClick(Self);
    137141  Core.PersistentForm1.Save(Self);
    138142end;
     
    187191        S := S + '), ';
    188192      end;
    189       MoveAllAndUpdate(GameTries[0].Moves[0]);
     193      MoveAllAndUpdate(GameTries[0].Moves[0], False);
    190194{      if CanMergeDirection(drDown) then MoveAllAnimate(drDown)
    191195      else if CanMergeDirection(drRight) then MoveAllAnimate(drRight)
     
    198202      }
    199203      Application.ProcessMessages;
    200       Sleep(10);
     204      Sleep(TrackBar1.Position);
    201205    end;
    202206  end;
     
    243247      NewTry.Game.UndoEnabled := False;
    244248      NewTry.Game.AnimationDuration := 0;
    245       NewTry.Game.MoveAllAnimate(Direction);
     249      NewTry.Game.MoveAll(Direction, False);
    246250      SetLength(NewTry.Moves, Length(NewTry.Moves) + 1);
    247251      NewTry.Moves[Length(NewTry.Moves) - 1] := Direction;
  • trunk/Forms/UFormMain.pas

    r37 r38  
    5757  if Core.Game.Running and not Core.Game.Moving then begin
    5858    case Key of
    59       37: Core.Game.MoveAllAndUpdate(drLeft);
    60       38: Core.Game.MoveAllAndUpdate(drUp);
    61       39: Core.Game.MoveAllAndUpdate(drRight);
    62       40: Core.Game.MoveAllAndUpdate(drDown);
     59      37: Core.Game.MoveAllAndUpdate(drLeft, True);
     60      38: Core.Game.MoveAllAndUpdate(drUp, True);
     61      39: Core.Game.MoveAllAndUpdate(drRight, True);
     62      40: Core.Game.MoveAllAndUpdate(drDown, True);
    6363    end;
    6464  end;
  • trunk/Languages/Game2048.cs.po

    r36 r38  
    8585msgstr "AI"
    8686
     87#: tformcomputer.label1.caption
     88msgid "Delay per step:"
     89msgstr "Pauza každý krok:"
     90
    8791#: tformhelp.caption
    8892msgctxt "tformhelp.caption"
  • trunk/Languages/Game2048.po

    r36 r38  
    7575msgstr ""
    7676
     77#: tformcomputer.label1.caption
     78msgid "Delay per step:"
     79msgstr ""
     80
    7781#: tformhelp.caption
    7882msgctxt "tformhelp.caption"
  • trunk/UGame.pas

    r37 r38  
    111111    function FillRandomTile(Value4Change: Double = 0.1): TTile;
    112112    function GetMoveArea(Direction: TMoveDirection): TArea;
     113    procedure MoveAllAnimate(Direction: TMoveDirection);
    113114  public
    114115    Board: TBoard;
     
    126127    procedure New;
    127128    procedure Render(Canvas: TCanvas; CanvasSize: TPoint);
    128     procedure MoveAll(Direction: TMoveDirection);
    129     procedure MoveAllAnimate(Direction: TMoveDirection);
    130     procedure MoveAllAndUpdate(Direction: TMoveDirection);
     129    procedure MoveAll(Direction: TMoveDirection; Animation: Boolean);
     130    procedure MoveAllAndUpdate(Direction: TMoveDirection; Animation: Boolean);
    131131    procedure MoveTile(SourceTile, TargetTile: TTile);
    132132    function IsValidPos(Pos: TPoint): Boolean;
     
    226226  for I := 0 to Step - 1 do
    227227  with Moves[I] do begin
    228     GameStep.MoveAll(Direction);
     228    GameStep.MoveAll(Direction, False);
    229229    if GameStep.Board.Tiles[NewItemPos.Y, NewItemPos.X].Value = 0 then
    230230      GameStep.Board.Tiles[NewItemPos.Y, NewItemPos.X].Value := NewItemValue
     
    608608end;
    609609
    610 procedure TGame.MoveAll(Direction: TMoveDirection);
     610procedure TGame.MoveAll(Direction: TMoveDirection; Animation: Boolean);
    611611var
    612612  P: TPoint;
     
    615615  Area: TArea;
    616616begin
     617  if Animation then begin
     618    MoveAllAnimate(Direction);
     619    Exit;
     620  end;
    617621  if Direction = drNone then Exit;
    618622  if not CanMoveDirection(Direction) then Exit;
     
    856860end;
    857861
    858 procedure TGame.MoveAllAndUpdate(Direction: TMoveDirection);
     862procedure TGame.MoveAllAndUpdate(Direction: TMoveDirection; Animation: Boolean);
    859863var
    860864  HighestValue: Integer;
     
    864868  if CanMoveDirection(Direction) then begin
    865869    HighestValue := Board.GetHighestTileValue;
    866     MoveAllAnimate(Direction);
     870    MoveAll(Direction, Animation);
    867871
    868872    NewTile := FillRandomTile;
Note: See TracChangeset for help on using the changeset viewer.