- Timestamp:
- Oct 4, 2019, 11:57:05 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r8 r11 20 20 Caption = 'Game' 21 21 object MenuItemNew: TMenuItem 22 Action = AGameNew 22 Action = Core.AGameNew 23 end 24 object MenuItem1: TMenuItem 25 Action = Core.ASettings 23 26 end 24 27 object MenuItemExit: TMenuItem 25 Action = AExit28 Action = Core.AExit 26 29 end 27 30 end … … 29 32 Caption = 'Help' 30 33 object MenuItemAbout: TMenuItem 31 Action = AAbout34 Action = Core.AAbout 32 35 end 33 36 end 34 37 end 35 object ActionList1: TActionList 36 left = 144 38 object TimerDraw: TTimer 39 Interval = 20 40 OnTimer = TimerDrawTimer 41 left = 138 37 42 top = 152 38 object AGameNew: TAction39 Caption = 'New...'40 OnExecute = AGameNewExecute41 end42 object AExit: TAction43 Caption = 'Exit'44 OnExecute = AExitExecute45 end46 object AAbout: TAction47 Caption = 'About'48 OnExecute = AAboutExecute49 end50 43 end 51 44 end -
trunk/Forms/UFormMain.lrj
r8 r11 2 2 {"hash":128377605,"name":"tformmain.caption","sourcebytes":[50,48,52,56,32,103,97,109,101],"value":"2048 game"}, 3 3 {"hash":317493,"name":"tformmain.menuitemgame.caption","sourcebytes":[71,97,109,101],"value":"Game"}, 4 {"hash":322608,"name":"tformmain.menuitemhelp.caption","sourcebytes":[72,101,108,112],"value":"Help"}, 5 {"hash":88908046,"name":"tformmain.agamenew.caption","sourcebytes":[78,101,119,46,46,46],"value":"New..."}, 6 {"hash":315140,"name":"tformmain.aexit.caption","sourcebytes":[69,120,105,116],"value":"Exit"}, 7 {"hash":4691652,"name":"tformmain.aabout.caption","sourcebytes":[65,98,111,117,116],"value":"About"} 4 {"hash":322608,"name":"tformmain.menuitemhelp.caption","sourcebytes":[72,101,108,112],"value":"Help"} 8 5 ]} -
trunk/Forms/UFormMain.pas
r10 r11 14 14 15 15 TFormMain = class(TForm) 16 AAbout: TAction;17 AExit: TAction;18 AGameNew: TAction;19 ActionList1: TActionList;20 16 MainMenu1: TMainMenu; 17 MenuItem1: TMenuItem; 21 18 MenuItemNew: TMenuItem; 22 19 MenuItemExit: TMenuItem; … … 24 21 MenuItemAbout: TMenuItem; 25 22 MenuItemGame: TMenuItem; 26 procedure AAboutExecute(Sender: TObject); 27 procedure AExitExecute(Sender: TObject); 28 procedure AGameNewExecute(Sender: TObject); 23 TimerDraw: TTimer; 29 24 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 30 25 procedure FormCreate(Sender: TObject); … … 33 28 procedure FormPaint(Sender: TObject); 34 29 procedure FormShow(Sender: TObject); 30 procedure TimerDrawTimer(Sender: TObject); 35 31 private 32 RedrawPending: Boolean; 36 33 public 34 procedure Redraw; 37 35 end; 38 36 … … 45 43 46 44 uses 47 UCore , UFormNew, UFormAbout;45 UCore; 48 46 49 47 { TFormMain } … … 53 51 MovedCount: Integer; 54 52 begin 55 if Core.Game.Running then begin53 if Core.Game.Running and not Core.Game.Moving then begin 56 54 MovedCount := 0; 57 55 case Key of … … 72 70 end; 73 71 74 procedure TFormMain.AGameNewExecute(Sender: TObject);75 begin76 FormNew := TFormNew.Create(nil);77 try78 FormNew.Load(Core.Game);79 if FormNew.ShowModal = mrOk then begin80 FormNew.Save(Core.Game);81 Core.Game.New;82 end;83 finally84 FreeAndNil(FormNew);85 end;86 end;87 88 72 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 89 73 begin 90 74 Core.PersistentForm1.Save(Self); 91 end;92 93 procedure TFormMain.AExitExecute(Sender: TObject);94 begin95 Close;96 end;97 98 procedure TFormMain.AAboutExecute(Sender: TObject);99 begin100 FormAbout := TFormAbout.Create(nil);101 try102 FormAbout.ApplicationInfo := Core.ApplicationInfo1;103 FormAbout.ShowModal;104 finally105 FreeAndNil(FormAbout);106 end;107 75 end; 108 76 … … 122 90 end; 123 91 92 procedure TFormMain.TimerDrawTimer(Sender: TObject); 93 begin 94 if RedrawPending then begin 95 RedrawPending := False; 96 Repaint; 97 end; 98 end; 99 100 procedure TFormMain.Redraw; 101 begin 102 RedrawPending := True; 103 end; 104 124 105 end. 125 106 -
trunk/Forms/UFormSettings.lfm
r8 r11 5 5 Width = 480 6 6 Caption = 'Settings' 7 ClientHeight = 360 8 ClientWidth = 480 7 9 DesignTimePPI = 144 10 OnShow = FormShow 8 11 LCLVersion = '2.0.2.0' 12 object Label1: TLabel 13 Left = 19 14 Height = 26 15 Top = 24 16 Width = 150 17 Caption = 'Animation speed:' 18 ParentColor = False 19 end 20 object TrackBar1: TTrackBar 21 Left = 208 22 Height = 58 23 Top = 16 24 Width = 240 25 Max = 100 26 Position = 0 27 Anchors = [akTop, akLeft, akRight] 28 TabOrder = 0 29 end 30 object ButtonOk: TButton 31 Left = 112 32 Height = 38 33 Top = 291 34 Width = 113 35 Anchors = [akLeft, akBottom] 36 Caption = 'OK' 37 OnClick = ButtonOkClick 38 TabOrder = 1 39 end 40 object ButtonCancel: TButton 41 Left = 256 42 Height = 38 43 Top = 288 44 Width = 113 45 Anchors = [akLeft, akBottom] 46 Caption = 'Cancel' 47 OnClick = ButtonCancelClick 48 TabOrder = 2 49 end 9 50 end -
trunk/Forms/UFormSettings.lrj
r8 r11 1 1 {"version":1,"strings":[ 2 {"hash":213582195,"name":"tformsettings.caption","sourcebytes":[83,101,116,116,105,110,103,115],"value":"Settings"} 2 {"hash":213582195,"name":"tformsettings.caption","sourcebytes":[83,101,116,116,105,110,103,115],"value":"Settings"}, 3 {"hash":69745274,"name":"tformsettings.label1.caption","sourcebytes":[65,110,105,109,97,116,105,111,110,32,115,112,101,101,100,58],"value":"Animation speed:"}, 4 {"hash":1339,"name":"tformsettings.buttonok.caption","sourcebytes":[79,75],"value":"OK"}, 5 {"hash":77089212,"name":"tformsettings.buttoncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"} 3 6 ]} -
trunk/Forms/UFormSettings.pas
r8 r11 6 6 7 7 uses 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs ;8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls; 9 9 10 10 type 11 12 { TFormSettings } 13 11 14 TFormSettings = class(TForm) 15 ButtonOk: TButton; 16 ButtonCancel: TButton; 17 Label1: TLabel; 18 TrackBar1: TTrackBar; 19 procedure ButtonCancelClick(Sender: TObject); 20 procedure ButtonOkClick(Sender: TObject); 21 procedure FormShow(Sender: TObject); 12 22 private 13 23 … … 23 33 {$R *.lfm} 24 34 35 uses 36 UCore; 37 38 { TFormSettings } 39 40 procedure TFormSettings.ButtonCancelClick(Sender: TObject); 41 begin 42 Close; 43 end; 44 45 procedure TFormSettings.ButtonOkClick(Sender: TObject); 46 begin 47 Core.Game.AnimationDuration := TrackBar1.Position; 48 Close; 49 end; 50 51 procedure TFormSettings.FormShow(Sender: TObject); 52 begin 53 TrackBar1.Position := Core.Game.AnimationDuration; 54 end; 55 25 56 end. 26 57 -
trunk/Languages/Game2048.cs.po
r8 r11 11 11 "Language: cs\n" 12 12 "X-Generator: Poedit 2.2.1\n" 13 14 #: tcore.aabout.caption 15 #, fuzzy 16 msgctxt "tcore.aabout.caption" 17 msgid "About" 18 msgstr "O aplikaci" 19 20 #: tcore.aexit.caption 21 #, fuzzy 22 msgctxt "tcore.aexit.caption" 23 msgid "Exit" 24 msgstr "Ukončít" 25 26 #: tcore.agamenew.caption 27 #, fuzzy 28 msgctxt "tcore.agamenew.caption" 29 msgid "New..." 30 msgstr "Nová..." 31 32 #: tcore.asettings.caption 33 #, fuzzy 34 msgctxt "tcore.asettings.caption" 35 msgid "Settings" 36 msgstr "Nastavení" 13 37 14 38 #: tformabout.buttonclose.caption … … 33 57 msgstr " " 34 58 35 #: tformmain.aabout.caption36 msgctxt "tformmain.aabout.caption"37 msgid "About"38 msgstr "O aplikaci"39 40 #: tformmain.aexit.caption41 msgid "Exit"42 msgstr "Ukončít"43 44 #: tformmain.agamenew.caption45 msgid "New..."46 msgstr "Nová..."47 48 59 #: tformmain.caption 49 60 msgid "2048 game" … … 59 70 60 71 #: tformnew.buttoncancel.caption 72 msgctxt "tformnew.buttoncancel.caption" 61 73 msgid "Cancel" 62 74 msgstr "Zrušit" 63 75 64 76 #: tformnew.buttonok.caption 77 msgctxt "tformnew.buttonok.caption" 65 78 msgid "OK" 66 79 msgstr "OK" … … 74 87 msgstr "Velikost desky:" 75 88 89 #: tformsettings.buttoncancel.caption 90 #, fuzzy 91 msgctxt "tformsettings.buttoncancel.caption" 92 msgid "Cancel" 93 msgstr "Zrušit" 94 95 #: tformsettings.buttonok.caption 96 #, fuzzy 97 msgctxt "tformsettings.buttonok.caption" 98 msgid "OK" 99 msgstr "OK" 100 76 101 #: tformsettings.caption 102 msgctxt "tformsettings.caption" 77 103 msgid "Settings" 78 104 msgstr "Nastavení" 105 106 #: tformsettings.label1.caption 107 msgid "Animation speed:" 108 msgstr "" 79 109 80 110 #: uformabout.slicense … … 93 123 msgid "Game over" 94 124 msgstr "Konec hry" 125 -
trunk/Languages/Game2048.po
r8 r11 1 1 msgid "" 2 2 msgstr "Content-Type: text/plain; charset=UTF-8" 3 4 #: tcore.aabout.caption 5 msgctxt "tcore.aabout.caption" 6 msgid "About" 7 msgstr "" 8 9 #: tcore.aexit.caption 10 msgctxt "tcore.aexit.caption" 11 msgid "Exit" 12 msgstr "" 13 14 #: tcore.agamenew.caption 15 msgctxt "tcore.agamenew.caption" 16 msgid "New..." 17 msgstr "" 18 19 #: tcore.asettings.caption 20 msgctxt "tcore.asettings.caption" 21 msgid "Settings" 22 msgstr "" 3 23 4 24 #: tformabout.buttonclose.caption … … 23 43 msgstr "" 24 44 25 #: tformmain.aabout.caption26 msgctxt "tformmain.aabout.caption"27 msgid "About"28 msgstr ""29 30 #: tformmain.aexit.caption31 msgid "Exit"32 msgstr ""33 34 #: tformmain.agamenew.caption35 msgid "New..."36 msgstr ""37 38 45 #: tformmain.caption 39 46 msgid "2048 game" … … 49 56 50 57 #: tformnew.buttoncancel.caption 58 msgctxt "tformnew.buttoncancel.caption" 51 59 msgid "Cancel" 52 60 msgstr "" 53 61 54 62 #: tformnew.buttonok.caption 63 msgctxt "tformnew.buttonok.caption" 55 64 msgid "OK" 56 65 msgstr "" … … 64 73 msgstr "" 65 74 75 #: tformsettings.buttoncancel.caption 76 msgctxt "tformsettings.buttoncancel.caption" 77 msgid "Cancel" 78 msgstr "" 79 80 #: tformsettings.buttonok.caption 81 msgctxt "tformsettings.buttonok.caption" 82 msgid "OK" 83 msgstr "" 84 66 85 #: tformsettings.caption 86 msgctxt "tformsettings.caption" 67 87 msgid "Settings" 88 msgstr "" 89 90 #: tformsettings.label1.caption 91 msgid "Animation speed:" 68 92 msgstr "" 69 93 -
trunk/UCore.lfm
r10 r11 40 40 top = 295 41 41 end 42 object ActionList1: TActionList 43 left = 420 44 top = 184 45 object AGameNew: TAction 46 Caption = 'New...' 47 OnExecute = AGameNewExecute 48 end 49 object AExit: TAction 50 Caption = 'Exit' 51 OnExecute = AExitExecute 52 end 53 object AAbout: TAction 54 Caption = 'About' 55 OnExecute = AAboutExecute 56 end 57 object ASettings: TAction 58 Caption = 'Settings' 59 OnExecute = ASettingsExecute 60 end 61 end 42 62 end -
trunk/UCore.pas
r10 r11 7 7 uses 8 8 Classes, SysUtils, UTheme, UPersistentForm, UApplicationInfo, UTranslator, 9 URegistry, UGame ;9 URegistry, UGame, ActnList, Forms, Controls; 10 10 11 11 type … … 14 14 15 15 TCore = class(TDataModule) 16 AAbout: TAction; 17 ASettings: TAction; 18 ActionList1: TActionList; 19 AExit: TAction; 20 AGameNew: TAction; 16 21 ApplicationInfo1: TApplicationInfo; 17 22 PersistentForm1: TPersistentForm; 18 23 ThemeManager1: TThemeManager; 19 24 Translator1: TTranslator; 25 procedure AAboutExecute(Sender: TObject); 26 procedure AExitExecute(Sender: TObject); 27 procedure AGameNewExecute(Sender: TObject); 28 procedure ASettingsExecute(Sender: TObject); 20 29 procedure DataModuleCreate(Sender: TObject); 21 30 procedure DataModuleDestroy(Sender: TObject); … … 36 45 37 46 uses 38 UFormMain ;47 UFormMain, UFormSettings, UFormAbout, UFormNew; 39 48 40 49 { TCore } … … 49 58 end; 50 59 60 procedure TCore.ASettingsExecute(Sender: TObject); 61 begin 62 FormSettings := TFormSettings.Create(nil); 63 try 64 FormSettings.ShowModal; 65 finally 66 FreeAndNil(FormSettings); 67 end; 68 end; 69 70 procedure TCore.AAboutExecute(Sender: TObject); 71 begin 72 FormAbout := TFormAbout.Create(nil); 73 try 74 FormAbout.ApplicationInfo := Core.ApplicationInfo1; 75 FormAbout.ShowModal; 76 finally 77 FreeAndNil(FormAbout); 78 end; 79 end; 80 81 procedure TCore.AExitExecute(Sender: TObject); 82 begin 83 FormMain.Close; 84 end; 85 86 procedure TCore.AGameNewExecute(Sender: TObject); 87 begin 88 FormNew := TFormNew.Create(nil); 89 try 90 FormNew.Load(Core.Game); 91 if FormNew.ShowModal = mrOk then begin 92 FormNew.Save(Core.Game); 93 Game.New; 94 end; 95 finally 96 FreeAndNil(FormNew); 97 end; 98 end; 99 51 100 procedure TCore.DataModuleDestroy(Sender: TObject); 52 101 begin … … 57 106 procedure TCore.GameChange(Sender: TObject); 58 107 begin 59 FormMain.Re paint;108 FormMain.Redraw; 60 109 end; 61 110 … … 67 116 68 117 Game.TopScore := ReadIntegerWithDefault('TopScore', 0); 118 Game.Size := Point(ReadIntegerWithDefault('SizeX', 4), ReadIntegerWithDefault('SizeY', 4)); 119 Game.AnimationDuration := ReadIntegerWithDefault('AnimationDuration', 30); 69 120 finally 70 121 Free; … … 79 130 80 131 WriteInteger('TopScore', Game.TopScore); 132 WriteInteger('SizeX', Game.Size.X); 133 WriteInteger('SizeY', Game.Size.Y); 134 WriteInteger('AnimationDuration', Game.AnimationDuration); 81 135 finally 82 136 Free; -
trunk/UGame.pas
r10 r11 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math ;8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math, DateUtils; 9 9 10 10 type … … 30 30 TGame = class 31 31 private 32 FMoving: Boolean; 32 33 FOnChange: TNotifyEvent; 33 34 FRunning: Boolean; … … 43 44 Cells: array of array of TCell; 44 45 TopScore: Integer; 46 AnimationDuration: Integer; 45 47 procedure GameOver; 46 48 function FillRandomCell: Integer; … … 60 62 property Running: Boolean read FRunning write FRunning; 61 63 property OnChange: TNotifyEvent read FOnChange write FOnChange; 64 property Moving: Boolean read FMoving; 62 65 end; 63 66 … … 318 321 MovedCount: Integer; 319 322 X, Y: Integer; 320 Step: Integer;321 323 I: Integer; 322 const 323 StepCount = 10; 324 AnimationDuration = 30; 325 begin 324 StartTime: TDateTime; 325 EndTime: TDateTime; 326 Time: TDateTime; 327 Part: Double; 328 begin 329 FMoving := True; 326 330 //Diff := DirectionDiff[Direction]; 327 331 case Direction of … … 397 401 Inc(PI.Y); 398 402 end; 399 for Step := 0 to StepCount - 2 do begin 403 404 // Animate cell move 405 StartTime := Now; 406 EndTime := StartTime + AnimationDuration / 300 * OneSecond / Size.X; 407 if AnimationDuration > 0 then 408 repeat 409 Time := Now; 410 Part := (Time - StartTime) / (EndTime - StartTime); 400 411 for Y := 0 to Size.Y - 1 do 401 412 for X := 0 to Size.X - 1 do begin 402 413 if Cells[Y, X].Moving then 403 Cells[Y, X].Shift := Point(Trunc( Step / StepCount * MoveDirection.X * 100),404 Trunc( Step / StepCount * MoveDirection.Y * 100));414 Cells[Y, X].Shift := Point(Trunc(Part * MoveDirection.X * 100), 415 Trunc(Part * MoveDirection.Y * 100)); 405 416 end; 406 417 DoChange; 407 418 Application.ProcessMessages; 408 Sleep(AnimationDuration div StepCount); 409 end; 419 Sleep(10); 420 until Time > EndTime; 421 422 // Set final cell values 410 423 for Y := 0 to Size.Y - 1 do 411 424 for X := 0 to Size.X - 1 do begin … … 416 429 end; 417 430 Result := MovedCount; 431 FMoving := False; 418 432 end; 419 433 … … 434 448 constructor TGame.Create; 435 449 begin 450 AnimationDuration := 30; 436 451 end; 437 452
Note:
See TracChangeset
for help on using the changeset viewer.