unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ImgList;
const
MIN = 1;
// kleinste Spielfeldposition
MAX = 40;
// größte Spielfeldposition
IMG_NAME = '
Image';
// Namenspräfix der Images
type
TPosition =
record
CardID: Integer;
// Kartennummer (ist auch der ImageIndex
Image: TImage;
// zugehöriges Image
end;
TPlayGround =
Array[MIN..MAX]
of TPosition;
TForm1 =
class(TForm)
Image2: TImage;
BtnStart: TBitBtn;
BtnExit: TBitBtn;
CardImage: TImageList;
Image11: TImage;
Image12: TImage;
Image13: TImage;
Image14: TImage;
Image15: TImage;
Image16: TImage;
Image17: TImage;
Image18: TImage;
Image19: TImage;
Image20: TImage;
Image1: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Image10: TImage;
Image21: TImage;
Image22: TImage;
Image23: TImage;
Image24: TImage;
Image25: TImage;
Image26: TImage;
Image27: TImage;
Image28: TImage;
Image29: TImage;
Image30: TImage;
Image31: TImage;
Image32: TImage;
Image33: TImage;
Image34: TImage;
Image35: TImage;
Image36: TImage;
Image37: TImage;
Image38: TImage;
Image39: TImage;
Image40: TImage;
procedure FormCreate(Sender: TObject);
procedure BtnStartClick(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
private
public
Cards: TPlayGround;
// unser Spielfeld (im Speicher!)
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Randomize;
// wirklich zufällige Zahlen
// Komponentenreferenzen ermitteln und eintragen
for i := MIN
to MAX
do begin
Cards[i].Image := TImage(Form1.FindComponent(IMG_NAME+IntToStr(i)));
Cards[i].CardID := (i -MIN)
div 2;
// Karten-ID vorbelegen
end;
// jeder Programmstart ist auch ein Spielstart
BtnStartClick(Self);
end;
procedure TForm1.BtnStartClick(Sender: TObject);
var
i, j, tmp: Integer;
begin
// Karten mischen
for i := MIN
to MAX
do begin
j := Random(MAX -MIN +1) +MIN;
tmp := Cards[i].CardID;
Cards[i].CardID := Cards[j].CardID;
Cards[j].CardID := tmp;
end;
// Karten "umdrehen" und Vorderseiten passend raussuchen
for i := MIN
to MAX
do begin
CardImage.GetBitmap(Cards[i].CardID,Cards[i].Image.Picture.Bitmap);
end;
end;
procedure TForm1.BtnExitClick(Sender: TObject);
begin
close;
end;
end.