////
//Created on 06.02.11 by Mike_
////
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 =
class(TForm)
Button1: TButton;
Label1: TLabel;
Label_Level: TLabel;
Panel1: TPanel;
Panel_Col0: TPanel;
Panel_Col1: TPanel;
Panel_Col2: TPanel;
Panel_Col3: TPanel;
procedure FormCreate(Sender: TObject);
procedure mixColors();
procedure NextColor();
procedure NextLevel ();
procedure FirstStart();
procedure ShowColorSqeuence();
procedure CheckAnswer(ColorOfButton: TColor);
procedure Button1Click(Sender: TObject);
procedure Panel2Clck(Sender: TObject);
procedure Panel_Col2Click(Sender: TObject);
procedure Panel_Col1Click(Sender: TObject);
procedure Panel_Col3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations}
end;
var
Form2: TForm2;
FarbListe: TStringList;
Level, DerzeitigesFarbLevel: Integer;
implementation
{$R *.dfm}
procedure Delay(time:Integer);
var
i: integer;
begin
for i := 0
to time
do
begin
Sleep(10);
Application.ProcessMessages;
end;
end;
procedure TForm2.ShowColorSqeuence();
var i : Integer;
begin
for I := 1
to FarbListe.Count - 1
do begin
case ColorToRGB(StringToColor(FarbListe.ValueFromIndex[I]))
of
32768: RandSeed:=0;
// RGB of clGreen
255: RandSeed:=1;
// RGB of clRed
65535: RandSeed:=2;
// RGB of clYellow
16711680: RandSeed:=3;
// RGB of clBlue
end;
TPanel(FindComponent('
Panel_Col'+IntToStr(RandSeed))).Color := StringToColor(FarbListe.ValueFromIndex[I]);
Delay(75);
TPanel(FindComponent('
Panel_Col'+IntToStr(RandSeed))).Color := clBtnFace;
Delay(25);
end;
end;
procedure TForm2.mixColors();
begin
Randomize;
RandSeed := Random(4);
//ShowMessage(IntToStr(RandSeed));
case RandSeed
of
0: FarbListe.Add('
cclGreen');
1: FarbListe.Add('
cclRed');
2: FarbListe.Add('
cclYellow');
3: FarbListe.Add('
cclBlue');
end;
end;
//Next Level
procedure TForm2.NextLevel ();
begin
mixColors();
Level := Level +1;
Label_Level.Caption := IntToStr(Level);
DerzeitigesFarbLevel := 1;
ShowColorSqeuence();
end;
//Next Color in same level
procedure TForm2.NextColor();
begin
DerzeitigesFarbLevel := DerzeitigesFarbLevel + 1;
end;
procedure TForm2.CheckAnswer(ColorOfButton: TColor);
begin
//RIGHT ANSWER
if FarbListe.ValueFromIndex[DerzeitigesFarbLevel] = ColorToString(ColorOfButton)
then begin
if DerzeitigesFarbLevel = Level
then begin
ShowMessage('
Das war korrekt, herzlich willkommen im Level '+IntToStr(Level+1)+'
!');
NextLevel();
end
else
//RIGHT BUT NO NEW LEVEL
begin
//ShowMessage('Ihre Antwort ist korrekt!');
NextColor();
end;
end
//FALSE ANSWER
else begin
ShowMessage('
Dies war leider verkehrt, das Spiel wird neu gestartet !');
Button1.Click;
end;
end;
//First start of game
procedure TForm2.FirstStart();
begin
FarbListe.Clear;
(*
Da TStirngList bei 0 anfängt zu zählen
wir aber der Übersicht halber bei Level 1 anfangen
*)
FarbListe.Insert(0, '
');
mixColors();
DerzeitigesFarbLevel := 1;
Level := 1;
Label_Level.Caption := IntToStr(Level);
ShowColorSqeuence();
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
FirstStart();
end;
procedure TForm2.Panel2Clck(Sender: TObject);
begin
CheckAnswer(clGreen);
end;
procedure TForm2.Panel_Col1Click(Sender: TObject);
begin
CheckAnswer(clRed);
end;
procedure TForm2.Panel_Col2Click(Sender: TObject);
begin
CheckAnswer(clYellow);
end;
procedure TForm2.Panel_Col3Click(Sender: TObject);
begin
CheckAnswer(clBlue);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
FarbListe := TStringList.Create;
Label_Level.Caption := '
';
//ShowMessage(IntToStr(ColorToRGB(clGreen))+' '+IntToStr(ColorToRGB(clRed))+' '+IntToStr(ColorToRGB(clYellow))+' '+IntToStr(ColorToRGB(clBlue)));
end;
end.