Changeset 12 for trunk/UGame.pas
- Timestamp:
- Oct 5, 2019, 12:48:02 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.