Changeset 20 for trunk/Forms


Ignore:
Timestamp:
Oct 5, 2019, 2:00:50 PM (5 years ago)
Author:
chronos
Message:
  • Added: Player can undo last move.
  • Modified: Optimized code of TGame.CanMove method.
Location:
trunk/Forms
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r11 r20  
    2020      Caption = 'Game'
    2121      object MenuItemNew: TMenuItem
    22         Action = Core.AGameNew
     22        Action = Core.ANew
     23      end
     24      object MenuItem2: TMenuItem
     25        Action = Core.AUndo
    2326      end
    2427      object MenuItem1: TMenuItem
  • trunk/Forms/UFormMain.pas

    r19 r20  
    1616    MainMenu1: TMainMenu;
    1717    MenuItem1: TMenuItem;
     18    MenuItem2: TMenuItem;
    1819    MenuItemNew: TMenuItem;
    1920    MenuItemExit: TMenuItem;
     
    4849
    4950procedure TFormMain.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    50 var
    51   MovedCount: Integer;
    5251begin
    5352  if Core.Game.Running and not Core.Game.Moving then begin
    54     MovedCount := 0;
    5553    case Key of
    56       37: MovedCount := Core.Game.MoveAll(drLeft);
    57       38: MovedCount := Core.Game.MoveAll(drUp);
    58       39: MovedCount := Core.Game.MoveAll(drRight);
    59       40: MovedCount := Core.Game.MoveAll(drDown);
     54      37: Core.Game.MoveAll(drLeft);
     55      38: Core.Game.MoveAll(drUp);
     56      39: Core.Game.MoveAll(drRight);
     57      40: Core.Game.MoveAll(drDown);
    6058    end;
    61     if MovedCount > 0 then Core.Game.FillRandomTile;
    62     if not Core.Game.CanMove and (Core.Game.Board.GetEmptyTilesCount = 0) then
    63       Core.Game.GameOver;
    64     if (not Core.Game.Won) and (Core.Game.Board.GetHighestTileValue >= 2048) then
    65       Core.Game.Win;
    6659  end;
    6760end;
  • trunk/Forms/UFormNew.lfm

    r15 r20  
    2525    ItemHeight = 0
    2626    Items.Strings = (
     27      '2 x 2'
    2728      '3 x 3'
    2829      '4 x 4'
  • trunk/Forms/UFormNew.pas

    r17 r20  
    4545procedure TFormNew.Load(Game: TGame);
    4646begin
    47   ComboBoxSize.ItemIndex := Game.Board.Size.X - 3;
     47  ComboBoxSize.ItemIndex := Game.Board.Size.X - 2;
    4848end;
    4949
    5050procedure TFormNew.Save(Game: TGame);
    5151begin
    52   Game.Board.Size := Point(3 + ComboBoxSize.ItemIndex, 3 + ComboBoxSize.ItemIndex);
     52  Game.Board.Size := Point(2 + ComboBoxSize.ItemIndex, 2 + ComboBoxSize.ItemIndex);
    5353end;
    5454
Note: See TracChangeset for help on using the changeset viewer.