SRL Archive - Other Scripts

Wizzy's first Game :)


SKy Scripter

2008-01-27 01:24:37

Hey, Its Wizzy's first SCAR game XD


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.

king vash

2008-01-27 01:44:47

fun game it should include a counter for how many times you tried

bullzeye95

2008-01-27 01:47:15

I think it should use only an OnMouseMove event to make it less laggy. I don't know if there's anything special behind the timer though (too lazy to look :p).

I won btw! I'm 1337.

Rikje

2008-01-27 01:48:00

lol . Memmory :)

But why did you post it? :p

the smith400

2008-01-27 01:54:42

yeah why did you post it?
looks fun and the script is quite short, cant wait to try it. thanks Sky Scripter for posting and thanks Wizzy for making

SKy Scripter

2008-01-27 13:54:02

i posted it because i never saw him post it. :p

Negaal

2008-01-27 14:06:24

Hehe, Why does it blinks?

Usually these games are with pictures:D

BenLand could do max score here:p

Harry

2008-01-27 14:19:53

OMG, nice! This game Wizzup's? Why does the title say Wizzy's first game? :confused:

Anyhoo, good job.

gamer 5

2008-01-27 17:25:13

Pretty Nice, I wonder what he can do now if that was his first!

Wizzup?

2008-01-27 17:25:37

This isn't mine, I made something alike though.. :confused:
It was actually my first attempt with forms, but it definately differed from this one.
I might post the .exe later. It's better than the scar one, with source for Yakman.

Freddy1990

2008-01-27 18:06:36

If someone can take care of the flickering I'd be happy to put this in with SCAR

SKy Scripter

2008-01-27 19:00:35

From: Wizzup?
This isn't mine, I made something alike though.. :confused:
It was actually my first attempt with forms, but it definately differed from this one.
I might post the .exe later. It's better than the scar one, with source for Yakman.


Lol, i was hoping you were going to pretend as if you really made it…. :p

SKy Scripter

2008-01-27 19:15:43

From: Freddy1990
If someone can take care of the flickering I'd be happy to put this in with SCAR


I sorta Fixed it, It only flickers once you select the 2 cards….
because it has to redraw everything… so it's better..


program new;
// By SKy Scripter, Inspired by Wizzup?


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

if (SelectCount = 3) then
begin
SelectCount := 0;
Timer.INTERVAL := 500;

Canvas.Brush.Color := 0;
Canvas.Pen.Color := 0;
Canvas.Rectangle(35, 25, 435, 435);

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;

Canvas.Brush.Color := $80CC;

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.

Swift

2008-01-27 19:21:31

Haha, awesome Wiz :D.

ZaSz

2008-01-27 23:26:11

This is cool I have done 1 so far

osmm

2008-01-29 23:32:13

tbh not that fun (I guess that's just me), but it is good for first game, really.

bullzeye95

2008-01-29 23:36:39

From: SKy Scripter
Lol, i was hoping you were going to pretend as if you really made it…. :p


Read people?

coo too

2008-01-30 11:21:54

first couple of games are good but after that its gets just a bit boring, like most games I think.

SKy Scripter

2008-01-30 13:14:58

Lol, Just thought i would let you guys know, i made this game.

it took me like 20 minutes, i was bored… lol

very simple game to make though……

Smartzkid

2008-02-02 03:22:57

Why redraw them all? Just redraw the two that need it, and you're good.

EDIT: Hmm, not sure how easy that'd be with how you've got it set up, Too tired to do it now anyways. Night all :p