Changeset 5 for trunk/UGame.pas
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 1 Game2048 2 2 Game2048.lps 3 Game2048.dbg 3 4 lib 5 heaptrclog.trc
-
- Property svn:ignore
-
trunk/UGame.pas
r4 r5 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, fgl, Graphics ;8 Classes, SysUtils, Dialogs, fgl, Graphics, Types; 9 9 10 10 type … … 35 35 procedure DoChange; 36 36 procedure ClearMerged; 37 function GetScore: Integer; 37 38 public 38 39 Cells: array of array of TCell; … … 49 50 function IsValidPos(Pos: TPoint): Boolean; 50 51 constructor Create; 52 destructor Destroy; override; 53 property Score: Integer read GetScore; 51 54 property Size: TPoint read FSize write SetSize; 52 55 property Running: Boolean read FRunning write FRunning; … … 201 204 ValueStr: string; 202 205 Frame: TRect; 203 begin 204 CellSize := Point(Canvas.Width div Size.X, Canvas.Height div Size.Y); 206 TextSize: TSize; 207 const 208 TopBarHeight = 32; 209 begin 210 Canvas.Brush.Style := bsSolid; 211 Canvas.Brush.Color := clBlack; 212 Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height); 213 214 Canvas.Font.Color := clWhite; 215 Canvas.Font.Height := 20; 216 Canvas.TextOut(16, 4, 'Score: ' + IntToStr(Score)); 217 218 Frame := Rect(0, TopBarHeight, Canvas.Width, Canvas.Height); 219 CellSize := Point(Frame.Width div Size.X, Frame.Height div Size.Y); 205 220 if CellSize.X < CellSize.Y then CellSize.Y := CellSize.X; 206 221 if CellSize.Y < CellSize.X then CellSize.X := CellSize.Y; 207 Frame := Rect(Canvas.Width div 2 - (Size.X * CellSize.X) div 2, 208 Canvas.Height div 2 - (Size.Y * CellSize.Y) div 2, 209 Canvas.Width div 2 + (Size.X * CellSize.X) div 2, 210 Canvas.Height div 2 + (Size.Y * CellSize.Y) div 2); 211 212 Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height); 222 Frame := Rect(Frame.Width div 2 - (Size.X * CellSize.X) div 2, 223 Frame.Top + Frame.Height div 2 - (Size.Y * CellSize.Y) div 2, 224 Frame.Width div 2 + (Size.X * CellSize.X) div 2, 225 Frame.Top + Frame.Height div 2 + (Size.Y * CellSize.Y) div 2); 226 213 227 Canvas.Font.Color := clBlack; 214 Canvas.Font.Height := Trunc(CellSize.Y * 0.7);215 228 for Y := 0 to Size.Y - 1 do 216 229 for X := 0 to Size.X - 1 do begin … … 221 234 if Cells[Y, X].Value <> 0 then begin 222 235 ValueStr := IntToStr(Cells[Y, X].Value); 236 Canvas.Brush.Style := bsClear; 237 Canvas.Font.Height := Trunc(CellSize.Y * 0.7); // * (CellSize.X * 0.7) / Canvas.TextWidth(ValueStr)); 238 TextSize := Canvas.TextExtent(ValueStr); 239 if TextSize.Width > CellSize.X then 240 Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellSize.X); 241 TextSize := Canvas.TextExtent(ValueStr); 223 242 Canvas.TextOut(Frame.Left + X * CellSize.X + CellSize.X div 2 - 224 Canvas.TextWidth(ValueStr)div 2,225 Frame.Top + Y * CellSize.Y , ValueStr);243 TextSize.Width div 2, 244 Frame.Top + Y * CellSize.Y + CellSize.Y div 2 - TextSize.Height div 2, ValueStr); 226 245 end; 227 246 end; … … 323 342 end; 324 343 344 function TGame.GetScore: Integer; 345 var 346 X, Y: Integer; 347 begin 348 Result := 0; 349 for Y := 0 to Size.Y - 1 do 350 for X := 0 to Size.X - 1 do 351 Result := Result + Cells[Y, X].Value; 352 end; 353 325 354 constructor TGame.Create; 326 355 begin 356 end; 357 358 destructor TGame.Destroy; 359 begin 360 Size := Point(0, 0); 361 inherited; 327 362 end; 328 363
Note:
See TracChangeset
for help on using the changeset viewer.