Thema: Delphi Memory-Spiel: Ideen

Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#66

AW: Memory-Spiel: Ideen

  Alt 5. Feb 2016, 16:08
Hatte mit letztens auch ein paar Gedanken gemacht. Voraussetzung wäre aber daß ihr euch etwas mit Klassen beschäftigt (ist nicht sooooo schwer). Was nämlich ein schönes Schmankerl wäre, wenn man die Karten so anordnen könnte, wie man es beim Memoryspiel auch macht (kreuz und quer, auch schräg, Stichworte: tagXFORM, SetGraphicsMode und SetWorldTransform). Wäre aber etwas Programmieraufwand (Prüfen ob die Karten sich überlappen und auf welche Karte geklickt wurde). Zeichnen würde man das Ganze dann in eine Paintbox.

Mal so ins Blaue getippt:

Delphi-Quellcode:
type
  TMemoryCardStatus = (mcsNone, mcsOpen, mcsClosed, mcsPlayer1, mcsPlayer2, ..);

  TMemoryCard = class
  private
    FX: integer;
    FY: integer;
    FWidth: integer;
    FHeight: integer;
    FAlpha: integer;
    FFrontBitmap: TBitmap;
    FBackBitmap: TBitmap;
    FStatus: TMemoryCardStatus;
  public
    property X: integer read FX write FX;
    property Y: integer read FY write FY;
    property Width: integer read FWidth write FWidth;
    property Height: integer read FHeight write FHeight;
    property Alpha: integer read FAlpha write FAlpha;
    property FrontBitmap: TBitmap read FFrontBitmap;
    property BackBitmap: TBitmap read FBackBitmap;
    property Status: TMemoryCardStatus read FStatus write FStatus;
    function Intersect(Value: TMemoryCard): boolean;
    function PtIn(X, Y: integer): boolean;
    procedure Draw(Canvas: TCanvas);
    constructor Create;
    destructor Destroy; override;
  end;

  TMemoryCards = class(TObjectList)
  private
    function GetItems(Index: integer): TMemoryCard;
    function Intersect: boolean;
  public
    procedure Start(CanvasWidth, CanvasHeight: integer);
    procedure Draw(Canvas: TCanvas);
    function IndexOfPtIn(X, Y, CanvasWidth, CanvasHeight: integer): integer;
    property Items[Index: integer]: TMemoryCard read GetItems; default;
  end;
  Mit Zitat antworten Zitat