AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Minesweeper

Ein Thema von saii · begonnen am 21. Mär 2015 · letzter Beitrag vom 29. Mär 2015
 
Popov
(Gast)

n/a Beiträge
 
#24

AW: Minesweeper

  Alt 25. Mär 2015, 11:49
Was wäre denn besser geeignet?
Eine Bitmap, bzw. eine Image oder Paint oder Formular. Einfach ein normales Feld in das man zeichnen kann.

Mal auf die Schnelle. Du benötigst eine Image Komponente. In OnMouseDown fragst du ab welches Feld geklickt wurde.

Delphi-Quellcode:
const
  MaxX = 20;
  MaxY = 20;
  CellWidth = 15;
  CellHeigth = 15;
  LineWidth = 1;

procedure TForm1.FormCreate(Sender: TObject);
var
  x, y: Integer;
begin
  with Image1.Picture do
  begin
    Bitmap.Width := (MaxX * (CellWidth + LineWidth)) + LineWidth;
    Bitmap.Height := (MaxY * (CellHeigth + LineWidth)) + LineWidth;

    for x := 0 to MaxX do
    begin
      Bitmap.Canvas.MoveTo(x * (CellWidth + LineWidth ), 0);
      Bitmap.Canvas.LineTo(x * (CellWidth + LineWidth ), Bitmap.Height);
    end;
    for y := 0 to MaxY do
    begin
      Bitmap.Canvas.MoveTo(0, y * (CellHeigth + LineWidth ));
      Bitmap.Canvas.LineTo(Bitmap.Width , y * (CellHeigth + LineWidth ));
    end;
  end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  c, r: Integer;
begin
  c := X div (CellWidth + LineWidth );
  r := Y div (CellHeigth + LineWidth );

  //Falls über das MaxX oder MaxY geklickt: -1
  if c > (MaxX - 1) then
    c := -1;
  if r > (MaxY - 1) then
    r := -1;

  Caption := Format('Feld geklickt: x = %d; y = %d', [c, r]);
end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:43 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz