SKy Scripter
2008-01-27 01:24:37
Hey, Its Wizzy's first SCAR game XD
Wizzy your so zleet :p
Wizzy your so zleet :p
program new;
var
MainForm: TForm;
Button: TButton;
Cards: array [0..5] of array [0..5] of Integer;
Select: array [0..5] of array [0..5] of Boolean;
SelectCount: Integer;
MousePos: TPoint;
SelectPos: array [1..2] of TPoint;
Canvas: TCanvas;
Timer: TTIMER;
procedure LoadGame;
var
Numbers : array [0..17] of Integer;
i, x, y, xx, yy : Integer;
begin
for I := 0 to 17 do
Numbers[i] := RandomRange(I * 5, I * 10);
I := 0;
for x := 0 to 5 do
for y := 0 to 5 do
begin
I := i + 1;
Select[x][y] := False;
Cards[x][y] := Numbers[ I mod 18 ];
end;
SelectCount := 0;
for i:= 0 to 50 do
begin
x := random(6); y := random(6);
xx := random(6); yy := random(6);
Swap(Cards[x][y], Cards[xx][yy]);
end;
end;
procedure OnClick(Sender: TObject);
begin
LoadGame;
end;
procedure OnTimer(Sender: TObject);
var
x, y, dx, dy: Integer;
begin
Canvas.Brush.Color := 0;
Canvas.Rectangle(0, 0, 600, 500);
Canvas.Brush.Color := $80CC;
if (SelectCount = 3) then
begin
SelectCount := 0;
Timer.INTERVAL := 500;
if (Cards[SelectPos[1].x][SelectPos[1].y] = Cards[SelectPos[2].x][SelectPos[2].y]) then
begin
Cards[SelectPos[1].x][SelectPos[1].y] := -1;
Cards[SelectPos[2].x][SelectPos[2].y] := -1;
end;
Select[SelectPos[1].x][SelectPos[1].y] := False;
Select[SelectPos[2].x][SelectPos[2].y] := False;
end;
if (SelectCount = 2) then
begin
Timer.INTERVAL := 1000;
SelectCount := SelectCount + 1;
end;
for x := 0 to 5 do
for y := 0 to 5 do
if (Cards[x][y] >= 0) then
begin
dx := 40 + (x * 70);
dy := 30 + (y * 70);
Canvas.Pen.Color := clwhite;
Canvas.Pen.Width := 1;
if (Abs(MousePos.x - (dx + 20)) <= 20) and (Abs(MousePos.y - (dy + 25)) <= 25)
or (Select[x][y]) then
begin
Canvas.Pen.Color := 255;
Canvas.Pen.Width := 2;
end;
Canvas.RoundRect(dx, dy, dx + 40, dy + 50, 10, 10);
if (Select[x][y]) then
begin
Canvas.Pen.Color := 255;
Canvas.Pen.Width := 2;
Canvas.TextOut(dx + 5, dy + 5, inttostr(Cards[x][y]));
end;
end;
end;
procedure OnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
xx, yy, dx, dy: Integer;
begin
if (SelectCount >= 2) then Exit;
for xx := 0 to 5 do
for yy := 0 to 5 do
begin
dx := 40 + (xx * 70);
dy := 30 + (yy * 70);
if (Abs(x - (dx + 20)) <= 20) and
(Abs(y - (dy + 25)) <= 25) and
(not(Select[xx][yy])) then
begin
SelectCount := SelectCount + 1;
Select[xx][yy] := True;
SelectPos[SelectCount] := Point(xx, yy);
Exit;
end;
end;
end;
procedure OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
MousePos := Point(x, y);
end;
procedure LoadForm;
begin
MainForm := CreateForm;
MainForm.SetBounds(0, 0, 600, 500);
MainForm.Position := poDesktopCenter;
MainForm.Caption := 'Memory Game';
MainForm.OnMouseDown := @OnMouseDown;
MainForm.OnMouseMove := @OnMouseMove;
MainForm.Color := 0;
Button := TButton.Create(MainForm);
Button.Caption := 'Reset Game';
Button.SetBounds(480, 30, 80, 20);
Button.Parent := MainForm;
Button.OnClick := @OnClick;
Canvas := MainForm.Canvas;
Canvas.Font.Color := clWhite;
Canvas.Font.Size := 12;
Timer := TTIMER.Create(MainForm);
Timer.INTERVAL := 500;
Timer.ONTIMER := @OnTimer;
MainForm.ShowModal;
end;
procedure SafeLoadForm;
var
V: TVariantArray;
begin
V := [];
ThreadSafeCall('LoadForm', V);
end;
begin
try
LoadGame;
SafeLoadForm;
finally
FreeForm(MainForm);
except
Writeln('Error');
end;
end.