Changeset 10 for trunk/UGame.pas
- Timestamp:
- Oct 4, 2019, 11:05:35 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r9 r10 32 32 FOnChange: TNotifyEvent; 33 33 FRunning: Boolean; 34 FScore: Integer; 34 35 FSize: TPoint; 35 36 function GetCellColor(Value: Integer): TColor; 37 procedure SetScore(AValue: Integer); 36 38 procedure SetSize(AValue: TPoint); 37 39 procedure GetEmptyCells(EmptyCells: TCells); 38 40 procedure DoChange; 39 41 procedure ClearMerged; 40 function GetScore: Integer;41 42 public 42 43 Cells: array of array of TCell; 44 TopScore: Integer; 43 45 procedure GameOver; 44 46 function FillRandomCell: Integer; … … 54 56 constructor Create; 55 57 destructor Destroy; override; 56 property Score: Integer read GetScore;58 property Score: Integer read FScore write SetScore; 57 59 property Size: TPoint read FSize write SetSize; 58 60 property Running: Boolean read FRunning write FRunning; … … 187 189 begin 188 190 Clear; 191 Score := 0; 189 192 Running := True; 190 193 for I := 0 to 1 do FillRandomCell; … … 222 225 Canvas.Font.Height := Trunc(TopBarHeight * 0.7); 223 226 Canvas.TextOut(ScaleY(16, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr); 227 228 ValueStr := 'Top score: ' + IntToStr(TopScore); 229 Canvas.Font.Color := clWhite; 230 Canvas.Font.Height := Trunc(TopBarHeight * 0.7); 231 Canvas.TextOut(ScaleY(106, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr); 224 232 225 233 // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows. … … 377 385 Cells[P.Y, P.X].Merged := False; 378 386 Inc(MovedCount); 387 Score := Score + Cells[PNew.Y, PNew.X].NewValue; 379 388 end; 380 389 end; … … 421 430 Result := (Pos.X >= 0) and (Pos.X < FSize.X) and 422 431 (Pos.Y >= 0) and (Pos.Y < FSize.Y); 423 end;424 425 function TGame.GetScore: Integer;426 var427 X, Y: Integer;428 begin429 Result := 0;430 for Y := 0 to Size.Y - 1 do431 for X := 0 to Size.X - 1 do432 Result := Result + Cells[Y, X].Value;433 432 end; 434 433 … … 462 461 end; 463 462 463 procedure TGame.SetScore(AValue: Integer); 464 begin 465 if FScore = AValue then Exit; 466 FScore := AValue; 467 if FScore > TopScore then TopScore := FScore; 468 end; 469 464 470 end. 465 471
Note:
See TracChangeset
for help on using the changeset viewer.