Changeset 14
- Timestamp:
- Oct 5, 2019, 11:42:10 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Languages/Game2048.cs.po
r13 r14 134 134 msgstr "Konec hry!" 135 135 136 #: ugame.sscore 137 msgid "Score" 138 msgstr "Skóre" 139 140 #: ugame.stopscore 141 msgid "Top score" 142 msgstr "Nejvyšší skóre" 143 136 144 #: ugame.swincaption 137 145 msgid "Win" -
trunk/Languages/Game2048.po
r13 r14 124 124 msgstr "" 125 125 126 #: ugame.sscore 127 msgid "Score" 128 msgstr "" 129 130 #: ugame.stopscore 131 msgid "Top score" 132 msgstr "" 133 126 134 #: ugame.swincaption 127 135 msgid "Win" -
trunk/UGame.pas
r12 r14 42 42 procedure DoChange; 43 43 procedure ClearMerged; 44 procedure RenderCell(Canvas: TCanvas; Cell: TCell; CellRect: TRect); 44 45 public 45 46 Cells: array of array of TCell; … … 79 80 SWinCaption = 'Win'; 80 81 SWinMessage = 'You won! Do you want to continue to play?'; 81 82 SScore = 'Score'; 83 STopScore = 'Top score'; 82 84 83 85 implementation … … 248 250 Frame: TRect; 249 251 CellRect: TRect; 250 TextSize: TSize;251 252 TopBarHeight: Integer; 252 253 CellMargin: Integer; … … 258 259 Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height); 259 260 260 ValueStr := 'Score: ' + IntToStr(Score);261 ValueStr := SScore + ': ' + IntToStr(Score); 261 262 Canvas.Font.Color := clWhite; 262 263 Canvas.Font.Height := Trunc(TopBarHeight * 0.7); 263 264 Canvas.TextOut(ScaleY(16, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr); 264 265 265 ValueStr := 'Top score: ' + IntToStr(TopScore);266 ValueStr := STopScore + ': ' + IntToStr(TopScore); 266 267 Canvas.Font.Color := clWhite; 267 268 Canvas.Font.Height := Trunc(TopBarHeight * 0.7); … … 279 280 Frame.Top + Frame.Height div 2 + (Size.Y * CellSize.Y) div 2); 280 281 281 { for Y := 0 to Size.Y - 1 do begin282 Canvas.MoveTo(Frame.Left, Frame.Top + Y * CellSize.Y);283 Canvas.LineTo(Frame.Left + Size.X * CellSize.X, Frame.Top + Y * CellSize.Y);284 end;285 for X := 0 to Size.X - 1 do begin286 Canvas.MoveTo(Frame.Left + X * CellSize.X, Frame.Top);287 Canvas.LineTo(Frame.Left + X * CellSize.X, Frame.Top + Size.Y * CellSize.Y);288 end;289 }290 282 Canvas.Brush.Style := bsSolid; 291 283 Canvas.Brush.Color := clGray; … … 293 285 294 286 Canvas.Font.Color := clBlack; 287 295 288 // Draw static cells 296 289 for Y := 0 to Size.Y - 1 do … … 303 296 Frame.Top + Y * CellSize.Y + CellMargin, 304 297 CellSize.X - 2 * CellMargin, CellSize.Y - 2 * CellMargin); 305 Canvas.FillRect(CellRect); 306 if (Cells[Y, X].Value <> 0) and not Cells[Y, X].Moving then begin 307 ValueStr := IntToStr(Cells[Y, X].Value); 308 Canvas.Brush.Style := bsClear; 309 Canvas.Font.Height := Trunc(CellSize.Y * 0.7); // * (CellSize.X * 0.7) / Canvas.TextWidth(ValueStr)); 310 TextSize := Canvas.TextExtent(ValueStr); 311 if TextSize.Width > CellSize.X then 312 Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellSize.X); 313 TextSize := Canvas.TextExtent(ValueStr); 314 Canvas.TextOut(CellRect.Left + CellSize.X div 2 - 315 TextSize.Width div 2, 316 CellRect.Top + CellSize.Y div 2 - TextSize.Height div 2, ValueStr); 317 end; 298 RenderCell(Canvas, Cells[Y, X], CellRect); 318 299 end; 319 300 … … 328 309 Frame.Top + Y * CellSize.Y + Trunc(Cells[Y, X].Shift.Y / 100 * CellSize.Y + CellMargin), 329 310 CellSize.X - 2 * CellMargin, CellSize.Y - 2 * CellMargin); 330 Canvas.FillRect(CellRect); 331 if Cells[Y, X].Value <> 0 then begin 332 ValueStr := IntToStr(Cells[Y, X].Value); 333 Canvas.Brush.Style := bsClear; 334 Canvas.Font.Height := Trunc(CellSize.Y * 0.7); // * (CellSize.X * 0.7) / Canvas.TextWidth(ValueStr)); 335 TextSize := Canvas.TextExtent(ValueStr); 336 if TextSize.Width > CellRect.Width then 337 Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellSize.X); 338 TextSize := Canvas.TextExtent(ValueStr); 339 Canvas.TextOut(CellRect.Left + CellRect.Width div 2 - 340 TextSize.Width div 2, 341 CellRect.Top + CellRect.Height div 2 - TextSize.Height div 2, ValueStr); 342 end; 343 end; 344 end; 311 RenderCell(Canvas, Cells[Y, X], CellRect); 312 end; 313 end; 314 315 procedure TGame.RenderCell(Canvas: TCanvas; Cell: TCell; CellRect: TRect); 316 var 317 ValueStr: string; 318 TextSize: TSize; 319 begin 320 Canvas.FillRect(CellRect); 321 if Cell.Value <> 0 then begin 322 ValueStr := IntToStr(Cell.Value); 323 Canvas.Brush.Style := bsClear; 324 Canvas.Font.Height := Trunc(CellRect.Height * 0.7); 325 TextSize := Canvas.TextExtent(ValueStr); 326 if TextSize.Width > CellRect.Width then 327 Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellRect.Width); 328 TextSize := Canvas.TextExtent(ValueStr); 329 Canvas.TextOut(CellRect.Left + CellRect.Width div 2 - TextSize.Width div 2, 330 CellRect.Top + CellRect.Height div 2 - TextSize.Height div 2, ValueStr); 331 end; 332 end; 333 345 334 346 335 function TGame.MoveAll(Direction: TDirection): Integer;
Note:
See TracChangeset
for help on using the changeset viewer.