Changeset 28


Ignore:
Timestamp:
Oct 5, 2019, 11:29:11 PM (5 years ago)
Author:
chronos
Message:
  • Added: Help windows with instructions how to play.
  • Added: With 10% chance create new random tile with value 4 instead of 2.
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r20 r28  
    44  Top = 307
    55  Width = 580
    6   Caption = '2048 game'
     6  Caption = '2048'
    77  DesignTimePPI = 144
    88  Menu = MainMenu1
     
    3434    object MenuItemHelp: TMenuItem
    3535      Caption = 'Help'
     36      object MenuItem3: TMenuItem
     37        Action = Core.AHelp
     38      end
    3639      object MenuItemAbout: TMenuItem
    3740        Action = Core.AAbout
  • trunk/Forms/UFormMain.lrj

    r11 r28  
    11{"version":1,"strings":[
    2 {"hash":128377605,"name":"tformmain.caption","sourcebytes":[50,48,52,56,32,103,97,109,101],"value":"2048 game"},
     2{"hash":217976,"name":"tformmain.caption","sourcebytes":[50,48,52,56],"value":"2048"},
    33{"hash":317493,"name":"tformmain.menuitemgame.caption","sourcebytes":[71,97,109,101],"value":"Game"},
    44{"hash":322608,"name":"tformmain.menuitemhelp.caption","sourcebytes":[72,101,108,112],"value":"Help"}
  • trunk/Forms/UFormMain.pas

    r20 r28  
    1717    MenuItem1: TMenuItem;
    1818    MenuItem2: TMenuItem;
     19    MenuItem3: TMenuItem;
    1920    MenuItemNew: TMenuItem;
    2021    MenuItemExit: TMenuItem;
  • trunk/Forms/UFormNew.lfm

    r20 r28  
    11object FormNew: TFormNew
    2   Left = 753
     2  Left = 703
    33  Height = 212
    4   Top = 825
     4  Top = 748
    55  Width = 487
    66  Caption = 'New game'
     
    6060    TabOrder = 2
    6161  end
     62  object CheckBoxUndoEnabled: TCheckBox
     63    Left = 16
     64    Height = 30
     65    Top = 56
     66    Width = 145
     67    Caption = 'Undo enabled'
     68    TabOrder = 3
     69  end
    6270end
  • trunk/Forms/UFormNew.lrj

    r8 r28  
    33{"hash":103901194,"name":"tformnew.label1.caption","sourcebytes":[66,111,97,114,100,32,115,105,122,101,58],"value":"Board size:"},
    44{"hash":77089212,"name":"tformnew.buttoncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"},
    5 {"hash":1339,"name":"tformnew.buttonok.caption","sourcebytes":[79,75],"value":"OK"}
     5{"hash":1339,"name":"tformnew.buttonok.caption","sourcebytes":[79,75],"value":"OK"},
     6{"hash":260260820,"name":"tformnew.checkboxundoenabled.caption","sourcebytes":[85,110,100,111,32,101,110,97,98,108,101,100],"value":"Undo enabled"}
    67]}
  • trunk/Forms/UFormNew.pas

    r20 r28  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxUndoEnabled: TCheckBox;
    1819    ComboBoxSize: TComboBox;
    1920    Label1: TLabel;
     
    4647begin
    4748  ComboBoxSize.ItemIndex := Game.Board.Size.X - 2;
     49  CheckBoxUndoEnabled.Checked := Game.UndoEnabled;
    4850end;
    4951
     
    5153begin
    5254  Game.Board.Size := Point(2 + ComboBoxSize.ItemIndex, 2 + ComboBoxSize.ItemIndex);
     55  Game.UndoEnabled := CheckBoxUndoEnabled.Checked;
    5356end;
    5457
  • trunk/Game2048.lpi

    r8 r28  
    8282      </Item2>
    8383    </RequiredPackages>
    84     <Units Count="7">
     84    <Units Count="8">
    8585      <Unit0>
    8686        <Filename Value="Game2048.lpr"/>
     
    126126        <ResourceBaseClass Value="DataModule"/>
    127127      </Unit6>
     128      <Unit7>
     129        <Filename Value="Forms/UFormHelp.pas"/>
     130        <IsPartOfProject Value="True"/>
     131        <ComponentName Value="FormHelp"/>
     132        <ResourceBaseClass Value="Form"/>
     133      </Unit7>
    128134    </Units>
    129135  </ProjectOptions>
  • trunk/Game2048.lpr

    r8 r28  
    88  {$ENDIF}
    99  Interfaces, SysUtils,// this includes the LCL widgetset
    10   Forms, UGame, Common, UFormSettings, UFormMain, UCore
     10  Forms, UGame, Common, UFormSettings, UFormMain, UCore, UFormHelp
    1111  { you can add units after this };
    1212
  • trunk/Languages/Game2048.cs.po

    r21 r28  
    2121msgid "Exit"
    2222msgstr "Ukončít"
     23
     24#: tcore.ahelp.caption
     25msgctxt "tcore.ahelp.caption"
     26msgid "Help"
     27msgstr "Nápověda"
    2328
    2429#: tcore.anew.caption
     
    5762msgstr "   "
    5863
     64#: tformhelp.caption
     65msgctxt "tformhelp.caption"
     66msgid "Help"
     67msgstr "Nápověda"
     68
    5969#: tformmain.caption
    60 msgid "2048 game"
     70msgid "2048"
    6171msgstr "2048"
    6272
     
    6676
    6777#: tformmain.menuitemhelp.caption
     78msgctxt "tformmain.menuitemhelp.caption"
    6879msgid "Help"
    6980msgstr "Nápověda"
     
    8293msgid "New game"
    8394msgstr "Nová hra"
     95
     96#: tformnew.checkboxundoenabled.caption
     97msgid "Undo enabled"
     98msgstr "Vrátit zpět povoleno"
    8499
    85100#: tformnew.label1.caption
     
    122137msgstr "Verze"
    123138
     139#: uformhelp.scontrols
     140msgid "Use arrow keys to slide blocks to one of board side."
     141msgstr "Použij klávesy šipek k posunutí bloků do jedné ze stran desky."
     142
     143#: uformhelp.severyturn
     144msgid "Every turn, a new tile will randomly appear in an empty spot on the board with a value of either 2 or 4."
     145msgstr "Každý tah se náhodně objeví nová dlaždice v prázdném místě desky s hodnotou 2 nebo 4."
     146
     147#: uformhelp.sparagraph1
     148msgid "2048 is a single-player block sliding puzzle game."
     149msgstr "2048 je jednouživatelská logická hra s posouváním bloků."
     150
     151#: uformhelp.sparagraph2
     152msgid "The game's objective is to slide numbered tiles on a grid to combine them to create a tile with the number 2048."
     153msgstr "Cílem hry je posouvat očíslované dlaždice na mřížce k jejich spojení a vytvoření dlaždice s číslem 2048."
     154
     155#: uformhelp.sundo
     156msgid "You can undo one move back, if undo action is enabled."
     157msgstr "Můžete vrátit zpět jeden pohyb, pokud je akce vrátit zpět povolena."
     158
    124159#: uformsettings.slanguagechangemessage
    125160msgid "Interface language was changed. It may require restart of application."
  • trunk/Languages/Game2048.po

    r21 r28  
    1010msgctxt "tcore.aexit.caption"
    1111msgid "Exit"
     12msgstr ""
     13
     14#: tcore.ahelp.caption
     15msgctxt "tcore.ahelp.caption"
     16msgid "Help"
    1217msgstr ""
    1318
     
    4752msgstr ""
    4853
     54#: tformhelp.caption
     55msgctxt "tformhelp.caption"
     56msgid "Help"
     57msgstr ""
     58
    4959#: tformmain.caption
    50 msgid "2048 game"
     60msgid "2048"
    5161msgstr ""
    5262
     
    5666
    5767#: tformmain.menuitemhelp.caption
     68msgctxt "tformmain.menuitemhelp.caption"
    5869msgid "Help"
    5970msgstr ""
     
    7182#: tformnew.caption
    7283msgid "New game"
     84msgstr ""
     85
     86#: tformnew.checkboxundoenabled.caption
     87msgid "Undo enabled"
    7388msgstr ""
    7489
     
    112127msgstr ""
    113128
     129#: uformhelp.scontrols
     130msgid "Use arrow keys to slide blocks to one of board side."
     131msgstr ""
     132
     133#: uformhelp.severyturn
     134msgid "Every turn, a new tile will randomly appear in an empty spot on the board with a value of either 2 or 4."
     135msgstr ""
     136
     137#: uformhelp.sparagraph1
     138msgid "2048 is a single-player block sliding puzzle game."
     139msgstr ""
     140
     141#: uformhelp.sparagraph2
     142msgid "The game's objective is to slide numbered tiles on a grid to combine them to create a tile with the number 2048."
     143msgstr ""
     144
     145#: uformhelp.sundo
     146msgid "You can undo one move back, if undo action is enabled."
     147msgstr ""
     148
    114149#: uformsettings.slanguagechangemessage
    115150msgid "Interface language was changed. It may require restart of application."
  • trunk/UCore.lfm

    r20 r28  
    2121    Identification = 1
    2222    VersionMajor = 1
    23     VersionMinor = 0
     23    VersionMinor = 1
    2424    VersionBugFix = 0
    2525    HomePage = 'https://app.zdechov.net/2048'
     
    2727    EmailContact = 'robie@centrum.cz'
    2828    AppName = '2048'
    29     Description = 'Classic 2048 puzzle game.'
    30     ReleaseDate = 43742
     29    Description = 'A single-player sliding block puzzle game.'
     30    ReleaseDate = 43743
    3131    RegistryKey = '\Software\Chronosoft\2048'
    3232    RegistryRoot = rrKeyCurrentUser
     
    4141  end
    4242  object ActionList1: TActionList
    43     left = 420
     43    left = 416
    4444    top = 184
    4545    object ANew: TAction
     
    6666      ShortCut = 114
    6767    end
     68    object AHelp: TAction
     69      Caption = 'Help'
     70      OnExecute = AHelpExecute
     71      ShortCut = 112
     72    end
    6873  end
    6974end
  • trunk/UCore.lrj

    r20 r28  
    44{"hash":4691652,"name":"tcore.aabout.caption","sourcebytes":[65,98,111,117,116],"value":"About"},
    55{"hash":213582195,"name":"tcore.asettings.caption","sourcebytes":[83,101,116,116,105,110,103,115],"value":"Settings"},
    6 {"hash":378031,"name":"tcore.aundo.caption","sourcebytes":[85,110,100,111],"value":"Undo"}
     6{"hash":378031,"name":"tcore.aundo.caption","sourcebytes":[85,110,100,111],"value":"Undo"},
     7{"hash":322608,"name":"tcore.ahelp.caption","sourcebytes":[72,101,108,112],"value":"Help"}
    78]}
  • trunk/UCore.pas

    r21 r28  
    1515  TCore = class(TDataModule)
    1616    AAbout: TAction;
     17    AHelp: TAction;
    1718    AUndo: TAction;
    1819    ASettings: TAction;
     
    2627    procedure AAboutExecute(Sender: TObject);
    2728    procedure AExitExecute(Sender: TObject);
     29    procedure AHelpExecute(Sender: TObject);
    2830    procedure ANewExecute(Sender: TObject);
    2931    procedure ASettingsExecute(Sender: TObject);
     
    4850
    4951uses
    50   UFormMain, UFormSettings, UFormAbout, UFormNew;
     52  UFormMain, UFormSettings, UFormAbout, UFormNew, UFormHelp;
    5153
    5254{ TCore }
     
    98100end;
    99101
     102procedure TCore.AHelpExecute(Sender: TObject);
     103begin
     104  FormHelp := TFormHelp.Create(nil);
     105  try
     106    FormHelp.ShowModal;
     107  finally
     108    FreeAndNil(FormHelp);
     109  end;
     110end;
     111
    100112procedure TCore.ANewExecute(Sender: TObject);
    101113begin
     
    126138procedure TCore.UpdateInterface;
    127139begin
    128   AUndo.Enabled := Game.CanUndo;;
     140  AUndo.Enabled := Game.CanUndo;
    129141end;
    130142
  • trunk/UGame.pas

    r27 r28  
    6464    procedure GameOver;
    6565    procedure Win;
    66     function FillRandomTile: Integer;
     66    function FillRandomTile(Value4Change: Double = 0.1): Integer;
    6767  public
    6868    Board: TBoard;
     
    7070    AnimationDuration: Integer;
    7171    WinScore: Integer;
     72    UndoEnabled: Boolean;
    7273    function CanUndo: Boolean;
    7374    procedure Undo;
     
    268269end;
    269270
    270 function TGame.FillRandomTile: Integer;
     271function TGame.FillRandomTile(Value4Change: Double = 0.1): Integer;
    271272var
    272273  EmptyTiles: TTiles;
     274  NewValue: Integer;
    273275begin
    274276  Result := 0;
     
    276278  Board.GetEmptyTiles(EmptyTiles);
    277279  if EmptyTiles.Count > 0 then begin
    278     EmptyTiles[Random(EmptyTiles.Count)].Value := 2;
     280    if Random < Value4Change then NewValue := 4 else NewValue := 2;
     281    EmptyTiles[Random(EmptyTiles.Count)].Value := NewValue;
    279282    Result := 1;
    280283  end;
     
    304307  Score := 0;
    305308  Running := True;
    306   for I := 0 to 1 do FillRandomTile;
     309  for I := 0 to 1 do FillRandomTile(0);
    307310  DoChange;
    308311end;
     
    399402function TGame.CanUndo: Boolean;
    400403begin
    401   Result := FCanUndo;
     404  Result := UndoEnabled and FCanUndo;
    402405end;
    403406
    404407procedure TGame.Undo;
    405408begin
    406   if CanUndo then begin
     409  if UndoEnabled and CanUndo then begin
    407410    Board.Assign(FBoardUndo);
    408411    FCanUndo := False;
     
    629632    WriteBool('GameRunning', FRunning);
    630633    WriteBool('CanUndo', FCanUndo);
     634    WriteBool('UndoEnabled', UndoEnabled);
    631635  finally
    632636    Free;
     
    646650    FRunning := ReadBoolWithDefault('GameRunning', False);
    647651    FCanUndo := ReadBoolWithDefault('CanUndo', False);
     652    UndoEnabled := ReadBoolWithDefault('UndoEnabled', True);
    648653  finally
    649654    Free;
Note: See TracChangeset for help on using the changeset viewer.