Changeset 12
- Timestamp:
- Oct 5, 2019, 12:48:02 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r11 r12 62 62 if not Core.Game.CanMove and (Core.Game.GetEmptyCellsCount = 0) then 63 63 Core.Game.GameOver; 64 if (not Core.Game.Won) and (Core.Game.GetHighestCellValue >= 2048) then 65 Core.Game.Win; 64 66 end; 65 67 end; -
trunk/Languages/Game2048.cs.po
r11 r12 120 120 msgstr "Verze" 121 121 122 #: ugame.sgameover 123 msgid " Game over"124 msgstr " Konec hry"122 #: ugame.sgameovercaption 123 msgid "Lost" 124 msgstr "" 125 125 126 #: ugame.sgameovermessage 127 msgid "Game over!" 128 msgstr "" 129 130 #: ugame.swincaption 131 msgid "Win" 132 msgstr "" 133 134 #: ugame.swinmessage 135 msgid "You won! Do you want to continue to play?" 136 msgstr "" 137 -
trunk/Languages/Game2048.po
r11 r12 104 104 msgstr "" 105 105 106 #: ugame.sgameover 107 msgid " Game over"106 #: ugame.sgameovercaption 107 msgid "Lost" 108 108 msgstr "" 109 109 110 #: ugame.sgameovermessage 111 msgid "Game over!" 112 msgstr "" 113 114 #: ugame.swincaption 115 msgid "Win" 116 msgstr "" 117 118 #: ugame.swinmessage 119 msgid "You won! Do you want to continue to play?" 120 msgstr "" 121 -
trunk/UCore.lfm
r11 r12 28 28 AppName = '2048' 29 29 Description = 'Classic 2048 game.' 30 ReleaseDate = 437 3330 ReleaseDate = 43742 31 31 RegistryKey = '\Software\Chronosoft\2048' 32 32 RegistryRoot = rrKeyCurrentUser -
trunk/UGame.pas
r11 r12 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math, DateUtils; 8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math, DateUtils, 9 Controls; 9 10 10 11 type … … 45 46 TopScore: Integer; 46 47 AnimationDuration: Integer; 48 Won: Boolean; 47 49 procedure GameOver; 50 procedure Win; 48 51 function FillRandomCell: Integer; 49 52 function CanMove: Boolean; 50 53 function GetEmptyCellsCount: Integer; 54 function GetHighestCellValue: Integer; 51 55 procedure Assign(Source: TGame); 52 56 procedure New; … … 71 75 72 76 resourcestring 73 SGameOver = 'Game over'; 77 SGameOverCaption = 'Lost'; 78 SGameOverMessage = 'Game over!'; 79 SWinCaption = 'Win'; 80 SWinMessage = 'You won! Do you want to continue to play?'; 74 81 75 82 … … 128 135 procedure TGame.GameOver; 129 136 begin 137 if Running then MessageDlg(SGameOverCaption, SGameOverMessage, mtInformation, [mbOK], 0); 130 138 Running := False; 131 ShowMessage(SGameOver); 139 end; 140 141 procedure TGame.Win; 142 begin 143 if not Won then begin 144 Won := True; 145 if MessageDlg(SWinCaption, SWinMessage, mtConfirmation, 146 mbYesNo, 0) = mrNo then begin 147 Running := False; 148 end; 149 end; 132 150 end; 133 151 … … 154 172 try 155 173 TempGame.Assign(Self); 174 TempGame.AnimationDuration := 0; 156 175 Result := TempGame.MoveAll(drDown) > 0; 157 176 if Result then Exit; … … 177 196 end; 178 197 198 function TGame.GetHighestCellValue: Integer; 199 var 200 X, Y: Integer; 201 begin 202 Result := 0; 203 for Y := 0 to Size.Y - 1 do 204 for X := 0 to Size.X - 1 do 205 if Result < Cells[Y, X].Value then Result := Cells[Y, X].Value; 206 end; 207 179 208 procedure TGame.Assign(Source: TGame); 180 209 var 181 210 X, Y: Integer; 182 211 begin 212 FScore := Source.FScore; 213 TopScore := Source.TopScore; 214 AnimationDuration := Source.AnimationDuration; 215 Won := Source.Won; 183 216 Size := Source.Size; 184 217 for Y := 0 to Size.Y - 1 do … … 193 226 Clear; 194 227 Score := 0; 228 Won := False; 195 229 Running := True; 196 230 for I := 0 to 1 do FillRandomCell; … … 232 266 Canvas.Font.Color := clWhite; 233 267 Canvas.Font.Height := Trunc(TopBarHeight * 0.7); 234 Canvas.TextOut(ScaleY(1 06, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr);268 Canvas.TextOut(ScaleY(136, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr); 235 269 236 270 // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows. … … 409 443 Time := Now; 410 444 Part := (Time - StartTime) / (EndTime - StartTime); 445 if Part > 1 then Part := 1; 411 446 for Y := 0 to Size.Y - 1 do 412 447 for X := 0 to Size.X - 1 do begin … … 417 452 DoChange; 418 453 Application.ProcessMessages; 419 Sleep(1 0);454 Sleep(1); 420 455 until Time > EndTime; 421 456 … … 423 458 for Y := 0 to Size.Y - 1 do 424 459 for X := 0 to Size.X - 1 do begin 460 Cells[Y, X].Shift := Point(0, 0); 461 Cells[Y, X].Moving := False; 425 462 Cells[Y, X].Value := Cells[Y, X].NewValue; 426 Cells[Y, X].Shift := Point(0, 0);427 463 end; 428 464 DoChange;
Note:
See TracChangeset
for help on using the changeset viewer.