unit U_ROB;

interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, jpeg, MPlayer,ShellApi;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Timer2: TTimer;
    Bordenbelow: TShape;
    Borderright: TShape;
    Zvierkant1: TShape;
    zvierkant2: TShape;
    zvierkant3: TShape;
    zvierkant4: TShape;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    MediaPlayer1: TMediaPlayer;
    Timer3: TTimer;
    Rvierkant1: TShape;
    rvierkant2: TShape;
    rvierkant3: TShape;
    rvierkant4: TShape;
    MenuRechts: TImage;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Timer4: TTimer;
    Timer5: TTimer;
    BONUSgehaald: TLabel;
    NOBONUS: TLabel;
    zround1: TShape;
    MediaPlayer2: TMediaPlayer;
    MediaPlayer3: TMediaPlayer;
    MediaPlayer4: TMediaPlayer;
    MediaPlayer5: TMediaPlayer;
    Livesbar: TImage;
    Memo1: TMemo;
    Button1: TButton;
    Image5: TImage;
    FINALSCORE: TLabel;
    Label1: TLabel;
    Label7: TLabel;
    BONUSgray: TShape;
    BONUS1: TImage;
    Bonus2: TImage;
    Bonus3: TImage;
    Bonus4: TImage;
    Bonus5: TImage;
    Label8: TLabel;
    Edit1: TEdit;
    Lives: TLabel;
    witeinde: TShape;
    geenlevens: TLabel;
    geentijd: TLabel;
    tryagain: TButton;
    closeall: TButton;
    MediaPlayer6: TMediaPlayer;
    eindscore: TLabel;
    Scoreseind: TMemo;
    MC: TImage;
    Timer6: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Zvierkant1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure zvierkant2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure zvierkant3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure zvierkant4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Rvierkant1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure rvierkant2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure rvierkant3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure rvierkant4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure zround1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label2MouseEnter(Sender: TObject);
    procedure Label2MouseLeave(Sender: TObject);
    procedure Label3MouseEnter(Sender: TObject);
    procedure Label3MouseLeave(Sender: TObject);
    procedure Label4MouseLeave(Sender: TObject);
    procedure Label4MouseEnter(Sender: TObject);
    procedure Label5MouseEnter(Sender: TObject);
    procedure Label5MouseLeave(Sender: TObject);
    procedure Label6MouseEnter(Sender: TObject);
    procedure Label6MouseLeave(Sender: TObject);
    procedure Label6Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Label4Click(Sender: TObject);
    procedure Timer5Timer(Sender: TObject);
    procedure MediaPlayer1Notify(Sender: TObject);
    procedure MediaPlayer2Notify(Sender: TObject);
    procedure BONUS1Click(Sender: TObject);
    procedure Bonus2Click(Sender: TObject);
    procedure Bonus3Click(Sender: TObject);
    procedure Bonus4Click(Sender: TObject);
    procedure Bonus5Click(Sender: TObject);
    procedure MediaPlayer4Notify(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure closeallClick(Sender: TObject);
    procedure tryagainClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
breedte = 14;
hoogte = 8;


Type
Tshapearray = array [1..28] of tshape;
Tgridarray = array [1..16] of Tshapearray;
scoredeel1 = array [1..10] of integer;
scoredeel2 = string;
tmyarray = array [1..10] of integer;

var
BG: Tgridarray;
score,score2,FINALSCORE1,mediaspeler,tijd,tijdset,tijdset2: integer;
BONUSTIJD,bonusLEVEL: integer;
Loop,loop2 : Boolean;
levens: integer;


procedure omwisselen (var een,twee: integer);
var
  temp: integer;
begin
  temp := een;
  een := twee;
  twee := temp;
end;

procedure sorteren (var Getallen: Tmyarray);
var
  i,j: integer;
begin
  for i:= 1 to 10 do
    for j:= 10 downto (i+1) do
      if getallen[j] > Getallen[j-1] then
        omwisselen(getallen[j-1],getallen[j]);
end;


{procedure voor achtergrond random te veranderen at start}
procedure backgroundstart;
var
teller3,teller4,kleur : integer;

begin
for teller3:=1 to breedte do
for teller4:=1 to hoogte do
  begin
  randomize;
  kleur:= random(15);
  if kleur = 1
  then BG[teller4,teller3].brush.color := clsilver
  else BG[teller4,teller3].brush.color := clgray;
end;
end;

{procedure voor achtergrond random donkerder}

procedure backgroundchange;
var
teller3,teller4,teller1,teller2,teller5,teller6,teller7,teller8,kleur : integer;

begin
if score2 < 100 then
begin
for teller3:=1 to breedte do
for teller4:=1 to hoogte do
  begin
  if BG[teller4,teller3].brush.color = clgray
  then begin
  randomize;
  kleur:= random(25);
  if kleur = 1
  then BG[teller4,teller3].brush.color := clsilver
  else BG[teller4,teller3].brush.color := clgray;
  end
  else BG[teller4,teller3].brush.color := clwhite;
  end;
  end;

if (score2 > 100) and (score2 < 200)
then begin
for teller1:=1 to breedte do
for teller2:=1 to hoogte do
  begin
  if BG[teller2,teller1].brush.color = clwhite
  then begin
  randomize;
  kleur:= random(25);
  if kleur = 1
  then BG[teller2,teller1].brush.color := clgreen
  else BG[teller2,teller1].brush.color := clwhite;
  end
  else BG[teller2,teller1].brush.color := clgray;
  end;
end;

if (score2 > 200)  and (score2 < 300)
then begin
for teller5:=1 to breedte do
for teller6:=1 to hoogte do
  begin
  if BG[teller6,teller5].brush.color = clgray
  then begin
  randomize;
  kleur:= random(25);
  if kleur = 1
  then BG[teller6,teller5].brush.color := clblue
  else BG[teller6,teller5].brush.color := clgray;
  end
  else BG[teller6,teller5].brush.color := clsilver;
  end;
end;

if (score2 > 300)  and (score2 < 400)
then begin
for teller5:=1 to breedte do
for teller6:=1 to hoogte do
  begin
  if BG[teller6,teller5].brush.color = clsilver
  then begin
  randomize;
  kleur:= random(25);
  if kleur = 1
  then BG[teller6,teller5].brush.color := clolive
  else BG[teller6,teller5].brush.color := clsilver;
  end
  else BG[teller6,teller5].brush.color := clgray;
  end;
end;

if (score2 > 400) and (score2 < 550)
then begin
for teller7:=1 to breedte do
for teller8:=1 to hoogte do
  begin
  if BG[teller8,teller7].brush.color = clgray
  then begin
  randomize;
  kleur:= random(30);
  if kleur = 1
  then BG[teller8,teller7].brush.color := clfuchsia
  else BG[teller8,teller7].brush.color := clgray;
  end
  else BG[teller8,teller7].visible := false;
  end;
end;


if (score2 > 550)
then begin
for teller7:=1 to breedte do
for teller8:=1 to hoogte do
  begin
  if BG[teller8,teller7].visible = false
  then begin
  randomize;
  kleur:= random(25);
  if kleur = 1
  then
  begin
  BG[teller8,teller7].brush.color := clblue;
  BG[teller8,teller7].visible := true;
  end
  else BG[teller8,teller7].visible:= false;
  end
  else BG[teller8,teller7].brush.color := clwhite
  end;
end;
end;


procedure AppRestart;
var AppName : PChar;
begin
  AppName := PChar(Application.ExeName) ;
  ShellExecute(Application.Handle,'open', AppName, nil, nil, SW_SHOWNORMAL) ;
  Application.Terminate;
end;


procedure TForm1.Bonus5Click(Sender: TObject);
begin
if BONUS4.Visible = false then begin
BONUS5.Visible := false;
mediaplayer5.play;
FINALSCORE1:= FINALSCORE1 + 1000;
bonusgehaald.Visible:= true;
BONUSgray.visible := false;

timer1.enabled:= true;
timer2.Enabled:= true;
timer3.enabled:= true;
timer4.enabled:= true;
BONUS1.visible := false;
BONUS2.visible := false;
BONUS3.visible := false;
BONUS4.visible := false;
BONUS5.Visible := false;
BONUSgray.visible := false;
label8.Visible := false;

loop2:= false;
MediaPlayer4.stop;
MediaPlayer4.Notify := true;

Loop := true;
MediaPlayer2.Play;
MediaPlayer2.Notify := true;
end;
end;

procedure TForm1.Timer5Timer(Sender: TObject);
begin
BONUSTIJD:= BONUSTIJD -14;

label8.caption:= inttostr(BONUSTIJD);

Bonus1.height :=  Bonus1.height -1;
Bonus1.width := Bonus1.width - 1;

Bonus2.height :=  Bonus2.height -1;
Bonus2.width := Bonus2.width - 1;

Bonus3.height :=  Bonus3.height -1;
Bonus3.width := Bonus3.width - 1;

Bonus4.height :=  Bonus4.height -1;
Bonus4.width := Bonus4.width - 1;

Bonus5.height :=  Bonus5.height -1;
Bonus5.width := Bonus5.width - 1;

if bonustijd < 0 then
begin
timer1.enabled:= true;
timer2.Enabled:= true;
timer3.enabled:= true;
timer4.enabled:= true;
BONUS1.visible := false;
BONUS2.visible := false;
BONUS3.visible := false;
BONUS4.visible := false;
BONUS5.Visible := false;
BONUSgray.visible := false;
label8.Visible := false;

Loop2 := false;
MediaPlayer4.Stop;
MediaPlayer4.Notify := true;

Loop := true;
MediaPlayer2.Play;
MediaPlayer2.Notify := true;

if bonusgehaald.visible = false
then
NOBONUS.Visible:= true;
end;

if Bonustijd < -100 then
begin
  nobonus.Visible:= false;
  bonusgehaald.Visible:= false;
  bonustijd := 300;
  timer5.Enabled:= false;
end;


end;

procedure TForm1.FormCreate(Sender: TObject);
var
teller7,teller8,teller:integer;
introtekst: array [1..30] of string;
infile: textfile;



begin
Form1.DoubleBuffered := true;
score:= 0;
score2 := 0;
mediaspeler:=1;
tijd:= 60;
tijdset2 := -10;
BONUSTIJD := 300;
bonusLEVEL := 0;
FINALSCORE1 := 0;
levens := 3;


Loop := true;
MediaPlayer1.Play;
MediaPlayer1.Notify := true;


label2.Visible := false;
label3.Visible := false;
label4.Visible := false;
label5.Visible := false;

rvierkant1.visible := false;
rvierkant2.visible := false;
rvierkant3.visible := false;
rvierkant4.visible := false;
zvierkant1.visible := false;
zvierkant2.visible := false;
zvierkant3.visible := false;
zround1.Visible := false;


timer1.enabled:= false;
timer2.Enabled:= false;
timer3.enabled:= false;
timer4.enabled:= false;

// lezen uit intro bestand bij startup
teller := 1;
assignfile(infile,'./intro.txt');
reset(infile);
while not eof(infile) do
begin
readln(infile,introtekst[teller]);
memo1.lines.add(introtekst[teller]);
teller:= teller +1;
end;


for teller7:=1 to breedte do
for teller8:=1 to hoogte do
  begin
  BG[teller8][teller7] := Tshape.Create(Form1);
  BG[teller8][teller7].Left := 65*(teller7-1);
  BG[teller8][teller7].Top := 65*(teller8-1);
  BG[teller8][teller7].Width := 65;
  BG[teller8][teller7].Height := 65;
  BG[teller8][teller7].Shape := strectangle;
  BG[teller8][teller7].Parent := Form1;
  BG[teller8][teller7].SendToBack;

  end;

backgroundstart;
MC.SendToBack;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
FINALSCORE.Caption := 'Score: '+ inttostr(finalscore1);
lives.caption := 'Lives: ' + inttostr(levens);

zvierkant1.Left := zvierkant1.Left + 4 +random(8);
if zvierkant1.left > 900
then
begin
randomize;
zvierkant1.left := -80;
zvierkant1.Top := 100 + random(350);
zvierkant1.Height := 25 + random(50);
zvierkant1.Width := zvierkant1.Height;
end;

begin
zvierkant2.Top := zvierkant2.top + 4 + random(5);
if zvierkant2.Top > 600
then
begin
randomize;
zvierkant2.top := -80;
zvierkant2.left := 100 + random(750);
zvierkant2.Height := 25 + random(50);
zvierkant2.Width := zvierkant2.Height;
end;
end;

begin
zvierkant3.Top := zvierkant3.top - 4 - random(5);
if zvierkant3.Top < -80
then
begin
randomize;
zvierkant3.top := 700;
zvierkant3.left := 100 + random(750);
zvierkant3.Height := 25 + random(50);
zvierkant3.Width := zvierkant3.Height;
end;
end;

begin
zvierkant4.Left := zvierkant4.Left - 4 - random(4);
if zvierkant4.left < -50
then
begin
randomize;
zvierkant4.left := 900;
zvierkant4.Top := 100 + random(350);
zvierkant4.Height := 25 + random(50);
zvierkant4.Width := zvierkant4.Height;
end;
end;


// rood

begin
rvierkant1.Left := rvierkant1.Left - 4 - random(4);
if rvierkant1.left < -50
then
begin
randomize;
rvierkant1.left := 900;
rvierkant1.Top := 100 + random(350);
rvierkant1.Height := 25 + random(50);
rvierkant1.Width := rvierkant1.Height;
end;
end;

begin
rvierkant2.Left := rvierkant2.Left + 4 +random(8);
if rvierkant2.left > 900
then
begin
randomize;
rvierkant2.left := -80;
rvierkant2.Top := 100 + random(350);
rvierkant2.Height := 25 + random(50);
rvierkant2.Width := rvierkant2.Height;
end;
end;

begin
rvierkant3.Top := rvierkant3.top + 4 + random(5);
if rvierkant3.Top > 600
then
begin
randomize;
rvierkant3.top := -80;
rvierkant3.left := 100 + random(750);
rvierkant3.Height := 25 + random(50);
rvierkant3.Width := rvierkant3.Height;
end;
end;

begin
rvierkant4.Top := rvierkant4.top - 4 - random(5);
if rvierkant4.Top < -80
then
begin
randomize;
rvierkant4.top := 700;
rvierkant4.left := 100 + random(750);
rvierkant4.Height := 25 + random(50);
rvierkant4.Width := rvierkant4.Height;
end;
end;

// BONUS zround/rround

begin
zround1.Top := zround1.top + 7 + random(5);
if zround1.Top > 600
then
begin
randomize;
zround1.top := -1500;
zround1.left := 100 + random(750);
zround1.Height := 25 + random(10);
zround1.Width := zround1.Height;
end;
end;


//score

label1.caption := 'Money: '+ inttostr(score) + ' $';

end;

// mouseover Z-vierkant 1-2-3-4
procedure TForm1.Zvierkant1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
zvierkant1.left := -80;
zvierkant1.Top := 100 + random(350);
zvierkant1.Height := 25 + random(50);
zvierkant1.Width := zvierkant1.Height;
score:= score +1;
score2:= score2 +1;
FINALSCORE1 := FINALSCORE1 + 11;
mediaplayer3.play;
backgroundchange;
end;

procedure TForm1.zvierkant2MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
begin
zvierkant2.top := -80;
zvierkant2.left := 100 + random(750);
zvierkant2.Height := 25 + random(50);
zvierkant2.Width := zvierkant2.Height;
score:= score +1;
score2:= score2 +1;
FINALSCORE1 := FINALSCORE1 + 17;
mediaplayer3.play;
backgroundchange;
end;
end;

procedure TForm1.zvierkant3MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
begin
zvierkant3.top := 700;
zvierkant3.left := 100 + random(750);
zvierkant3.Height := 25 + random(50);
zvierkant3.Width := zvierkant3.Height;
score:= score +1;
score2:= score2 +1;
FINALSCORE1 := FINALSCORE1 + 12;
mediaplayer3.play;
backgroundchange;
end;
end;

procedure TForm1.zvierkant4MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
begin
zvierkant4.left := 900;
zvierkant4.Top := 100 + random(350);
zvierkant4.Height := 25 + random(50);
zvierkant4.Width := zvierkant4.Height;
score:= score +1;
score2:= score2 +1;
FINALSCORE1 := FINALSCORE1 + 9;
mediaplayer3.play;
backgroundchange;
end;
end;

//mouseover rvierkant1-2-3-4
procedure TForm1.Rvierkant1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
levens:= levens -1;
mediaplayer6.play;
randomize;
rvierkant1.left := 900;
rvierkant1.Top := 100 + random(350);
rvierkant1.Height := 25 + random(50);
rvierkant1.Width := rvierkant1.Height;
end;

procedure TForm1.rvierkant2MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
levens:= levens -1;
mediaplayer6.play;
randomize;
rvierkant2.left := -80;
rvierkant2.Top := 100 + random(350);
rvierkant2.Height := 25 + random(50);
rvierkant2.Width := rvierkant2.Height;
end;

procedure TForm1.rvierkant3MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
levens:= levens -1;
mediaplayer6.play;
randomize;
rvierkant3.top := -80;
rvierkant3.left := 100 + random(750);
rvierkant3.Height := 25 + random(50);
rvierkant3.Width := rvierkant3.Height;
end;

procedure TForm1.rvierkant4MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
levens:= levens -1;
mediaplayer6.play;
randomize;
rvierkant4.top := 700;
rvierkant4.left := 100 + random(750);
rvierkant4.Height := 25 + random(50);
rvierkant4.Width := rvierkant4.Height;
end;

//bonus zround1
procedure TForm1.zround1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
randomize;
zround1.top := -5050;
zround1.left := 100 + random(750);
zround1.Height := 25 + random(10);
zround1.Width := zround1.Height;
score:= score + 5;
FINALSCORE1 := FINALSCORE1 + 43;
mediaplayer3.play;
end;

procedure TForm1.Label2MouseEnter(Sender: TObject);
begin
label2.font.Color := clsilver;
end;

procedure TForm1.Label2MouseLeave(Sender: TObject);
begin
label2.font.Color := clwhite;
end;

procedure TForm1.Label3MouseEnter(Sender: TObject);
begin
label3.font.Color := clsilver;
end;

procedure TForm1.Label3MouseLeave(Sender: TObject);
begin
label3.font.Color := clwhite;
end;

procedure TForm1.Label4MouseLeave(Sender: TObject);
begin
label4.font.Color := clwhite;
end;

procedure TForm1.Label4MouseEnter(Sender: TObject);
begin
label4.font.Color := clsilver;
end;

procedure TForm1.Label5MouseEnter(Sender: TObject);
begin
label5.font.Color := clsilver;
end;

procedure TForm1.Label5MouseLeave(Sender: TObject);
begin
label5.font.Color := clwhite;
end;

procedure TForm1.Label6MouseEnter(Sender: TObject);
begin
label6.font.Color := clsilver;
end;

procedure TForm1.Label6MouseLeave(Sender: TObject);
begin
label6.font.Color := clwhite;
end;

procedure TForm1.Label6Click(Sender: TObject);
begin
if mediaspeler = 1
then
begin
mediaplayer1.Play;
mediaspeler:= 0;
end;

if mediaspeler = 0
then
begin
mediaplayer1.stop;
mediaspeler:=1;
end;

end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.caption := 'Time:  '+ inttostr(tijd)+ ' s';
tijd:= tijd -1;
FINALSCORE1:= FINALSCORE1 +1;


if tijdset < 9
then begin
tijdset := tijdset + 1;
end;

if  tijdset = 8
then begin
rvierkant1.visible := true;
rvierkant2.visible := true;
rvierkant3.visible := true;
rvierkant4.visible := true;
end;
end;
procedure TForm1.Label2Click(Sender: TObject);
begin
tijd:= tijd + 30;
score:= score - 30;
mediaplayer3.play;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var
eind: textfile;
teller0,teller3,i,j,index,temp2,l:integer;
eindtekst: tmyarray;
eindtekst2: array [1..10] of scoredeel2;
tempstr,temp3:string;

begin
{if tijd < 0
then
  begin
  timer1.enabled:= false;
  timer2.enabled:= false;
  timer3.enabled:= false;
  timer4.enabled:= false;
  timer5.enabled:= false;

  label1.Visible := false;
  label2.Visible := false;
  label3.visible := false;
  label4.visible := false;
  label5.visible := false;

  mediaplayer1.play;
  mediaplayer2.Stop;
  mediaplayer3.stop;
  mediaplayer4.stop;
  mediaplayer5.stop;

  witeinde.visible := true;
  geentijd.visible := true;
  eindscore.visible := true;
  eindscore.caption := 'Final score:  ' + inttostr(finalscore1) + ' points';
  tryagain.visible := true;
  closeall.visible := true;

  teller0:= 1;
  assignfile(eind,'./scores.txt');
  reset(eind);
while not eof(eind) do
begin
readln(eind,eindtekst[teller0],eindtekst2[teller0]);
//scoreseind.lines.add(inttostr(eindtekst[teller0])+eindtekst2[teller0]);
teller0:= teller0 +1;
end;

  closefile(eind);
  index := 0;
  for i:= 1 to 10 do
  begin
    if finalscore1 > eindtekst[i] then
    begin
      index := i;
      break;
    end;
  end;
  if index = 10 then
    begin
    eindtekst[10] := finalscore1;
    eindtekst2[10] := label6.caption;
    end
  else

  begin
  if index > 0 then
  begin
    for j:= index+1 to 9 do
    begin
        temp2 := eindtekst[j];
        temp3 := eindtekst2[j];
        eindtekst[j] := eindtekst[j+1];
        eindtekst2[j] := eindtekst2[j+1];
        eindtekst[j+1] := temp2;
        eindtekst2[j+1] := temp3;
  end;


  end;

  for j:= 1 to 10 do  begin
  scoreseind.Lines.add(inttoStr(eindtekst[j])+  ' '+ eindtekst2[j]);
  end;


  assignfile(eind,'./scores.txt');
  rewrite(eind);
for l := 1 to 10 do
begin
tempStr := inttostr(eindtekst[l])+' '+eindtekst2[l];
writeln(eind,tempStr);
end;
  closefile(eind);





  scoreseind.visible := true;
  end;
  end; }



if levens < 0
then
  begin
  timer1.enabled:= false;
  timer2.enabled:= false;
  timer3.enabled:= false;
  timer4.enabled:= false;
  timer5.enabled:= false;

  label1.Visible := false;
  label2.Visible := false;
  label3.visible := false;
  label4.visible := false;
  label5.visible := false;


  mediaplayer1.play;
  mediaplayer2.Stop;
  mediaplayer3.stop;
  mediaplayer4.stop;
  mediaplayer5.stop;

  teller0:= 1;
  assignfile(eind,'./scores.txt');
  reset(eind);
while not eof(eind) do
begin
readln(eind,eindtekst[teller0],eindtekst2[teller0]);
//scoreseind.lines.add(inttostr(eindtekst[teller0])+eindtekst2[teller0]);
teller0:= teller0 +1;
end;

closefile(eind);

 index := 0;
  for i:= 1 to 10 do
  begin
    if finalscore1 > eindtekst[i] then
    begin
      index := i;
      break;
    end;
  end;
  if index = 10 then
    begin
    eindtekst[10] := finalscore1;
    eindtekst2[10] := '      '+ label6.caption;
    end
  else

  begin
  if index > 0 then
  begin
    for j:= index+1 to 9 do
    begin
        temp2 := eindtekst[j];
        temp3 := eindtekst2[j];
        eindtekst[j] := eindtekst[j+1];
        eindtekst2[j] := eindtekst2[j+1];
        eindtekst[j+1] := temp2;
        eindtekst2[j+1] := temp3;
        eindtekst[index] := finalscore1;
        eindtekst2[index] := '      '+ label6.caption;
  end;


  end;




sorteren(eindtekst);
scoreseind.clear;


for teller3 := 1 to 10 do
  begin
  scoreseind.Lines.add(inttostr(eindtekst[teller3])+'  ' + eindtekst2[teller3]);
  end;



  assignfile(eind,'./scores.txt');
  rewrite(eind);
for l := 1 to 10 do
begin
tempStr := inttostr(eindtekst[l])+eindtekst2[l];
writeln(eind,tempStr);
end;

  closefile(eind);

  scoreseind.visible := true;
  witeinde.visible := true;
  geenlevens.visible := true;
  eindscore.visible := true;
  eindscore.caption := 'Final score:  ' + inttostr(finalscore1) + ' points';
  tryagain.visible := true;
  closeall.visible := true;
  timer1.enabled:= false;
  timer2.enabled:= false;
  timer3.enabled:= false;
  timer4.enabled:= false;
  timer5.enabled:= false;

  label1.Visible := false;
  label2.Visible := false;
  label3.visible := false;
  label4.visible := false;
  label5.visible := false;


  mediaplayer1.play;
  mediaplayer2.Stop;
  mediaplayer3.stop;
  mediaplayer4.stop;
  mediaplayer5.stop;
  end;
  end;

  if tijd < 0 then
  begin
  timer1.enabled:= false;
  timer2.enabled:= false;
  timer3.enabled:= false;
  timer4.enabled:= false;
  timer5.enabled:= false;

  label1.Visible := false;
  label2.Visible := false;
  label3.visible := false;
  label4.visible := false;
  label5.visible := false;


  mediaplayer1.play;
  mediaplayer2.Stop;
  mediaplayer3.stop;
  mediaplayer4.stop;
  mediaplayer5.stop;

  teller0:= 1;
  assignfile(eind,'./scores.txt');
  reset(eind);
while not eof(eind) do
begin
readln(eind,eindtekst[teller0],eindtekst2[teller0]);
//scoreseind.lines.add(inttostr(eindtekst[teller0])+eindtekst2[teller0]);
teller0:= teller0 +1;
end;

closefile(eind);

 index := 0;
  for i:= 1 to 10 do
  begin
    if finalscore1 > eindtekst[i] then
    begin
      index := i;
      break;
    end;
  end;
  if index = 10 then
    begin
    eindtekst[10] := finalscore1;
    eindtekst2[10] := '      '+ label6.caption;
    end
  else

  begin
  if index > 0 then
  begin
    for j:= index+1 to 9 do
    begin
        temp2 := eindtekst[j];
        temp3 := eindtekst2[j];
        eindtekst[j] := eindtekst[j+1];
        eindtekst2[j] := eindtekst2[j+1];
        eindtekst[j+1] := temp2;
        eindtekst2[j+1] := temp3;
        eindtekst[index] := finalscore1;
        eindtekst2[index] := '      '+ label6.caption;
  end;


  end;




sorteren(eindtekst);
scoreseind.clear;


for teller3 := 1 to 10 do
  begin
  scoreseind.Lines.add(inttostr(eindtekst[teller3])+'  ' + eindtekst2[teller3]);
  end;



  assignfile(eind,'./scores.txt');
  rewrite(eind);
for l := 1 to 10 do
begin
tempStr := inttostr(eindtekst[l])+eindtekst2[l];
writeln(eind,tempStr);
end;

  closefile(eind);

  scoreseind.visible := true;
  witeinde.visible := true;
  geentijd.visible := true;
  eindscore.visible := true;
  eindscore.caption := 'Final score:  ' + inttostr(finalscore1) + ' points';
  tryagain.visible := true;
  closeall.visible := true;
  timer1.enabled:= false;
  timer2.enabled:= false;
  timer3.enabled:= false;
  timer4.enabled:= false;
  timer5.enabled:= false;

  label1.Visible := false;
  label2.Visible := false;
  label3.visible := false;
  label4.visible := false;
  label5.visible := false;


  mediaplayer1.play;
  mediaplayer2.Stop;
  mediaplayer3.stop;
  mediaplayer4.stop;
  mediaplayer5.stop;
  end;
  end;



if (score2 > 5) AND (score2 < 10)
then begin
rvierkant1.visible := true;
rvierkant2.visible := false;
rvierkant3.visible := false;
rvierkant4.visible := false;
zvierkant1.visible := true;
zvierkant2.visible := false;
zvierkant3.visible := false;
zround1.Visible := false;
end;

if (score2 > 10) and (score2 < 15)
then begin
rvierkant1.visible := true;
rvierkant2.visible := true;
rvierkant3.visible := false;
rvierkant4.visible := false;
zvierkant1.visible := true;
zvierkant2.visible := true;
zvierkant3.visible := false;
zround1.Visible := false;
end;

if (score2 > 15) and (score2 <20)
then begin
rvierkant1.visible := true;
rvierkant2.visible := true;
rvierkant3.visible := true;
rvierkant4.visible := true;
zvierkant1.visible := true;
zvierkant2.visible := true;
zvierkant3.visible := true;
zround1.Visible := true;
end;




end;
procedure TForm1.Label3Click(Sender: TObject);
begin
mediaplayer3.play;
score:= score - 20;
rvierkant1.visible := false;
rvierkant2.visible := false;
rvierkant3.visible := false;
rvierkant4.visible := false;
tijdset:= 0;
end;

procedure TForm1.Timer4Timer(Sender: TObject);
begin

if score > 30
then
begin
label2.Visible := true;
end
else
label2.Visible := false;

if score > 20
then
begin
label3.Visible := true;
end
else
label3.Visible := false;

if score > 50
then
begin
label4.Visible := true;
end
else
label4.Visible := false;

if score > 80
then
begin
label5.Visible := true;
end
else
label5.Visible := false;


end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Loop := false;
MediaPlayer1.Stop;
MediaPlayer1.Notify := true;
mediaplayer2.Play;
button1.visible := false;
memo1.visible := false;
edit1.visible := false;

lives.caption := 'Lives: ' + inttostr(levens);
label6.caption := edit1.text;

timer1.enabled:= true;
timer2.Enabled:= true;
timer3.enabled:= true;
timer4.enabled:= true;

end;

procedure TForm1.Label4Click(Sender: TObject);
begin
mediaplayer3.play;
label8.Visible := true;
score:= score - 50;

Bonus1.height :=  145;
Bonus1.width := 145;

Bonus2.height :=  113;
Bonus2.width := 113;

Bonus3.height :=  105;
Bonus3.width := 105;

Bonus4.height :=  89;
Bonus4.width := 89;

Bonus5.height :=  65;
Bonus5.width := 65;



loop:= false;
MediaPlayer2.stop;
MediaPlayer2.Notify := true;

loop2 := true;
mediaplayer4.play;
MediaPlayer4.Notify := true;

Bonus1.Left :=  random(750);
Bonus1.Top := random(350);

Bonus2.Left :=  random(750);
Bonus2.Top := random(350);

Bonus3.Left :=  random(750);
Bonus3.Top := random(350);

Bonus4.Left :=  random(750);
Bonus4.Top := random(350);

Bonus5.Left :=  random(750);
Bonus5.Top := random(350);




if bonusLEVEL = 0
then
  begin
timer1.enabled:= false;
timer2.Enabled:= false;
timer3.enabled:= false;
timer4.enabled:= false;
timer5.enabled:= true;
BONUS1.visible := true;
BONUS2.visible := true;
BONUS3.visible := true;
BONUS4.Visible := true;
BONUS5.visible := true;
BONUSgray.visible := true;
end;


end;

procedure TForm1.Bonus3Click(Sender: TObject);
begin
if BONUS2.Visible = false then begin
BONUS3.Visible := false;
mediaplayer5.play;


end;
end;



procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if (MediaPlayer1.NotifyValue = nvSuccessful) and (Loop=true) then
begin
    MediaPlayer1.Play;
    MediaPlayer1.Notify := true;
end;
end;

procedure TForm1.MediaPlayer2Notify(Sender: TObject);
begin
if (MediaPlayer2.NotifyValue = nvSuccessful) and (Loop=true) then
begin
    MediaPlayer2.Play;
    MediaPlayer2.Notify := true;
end;
end;

procedure TForm1.BONUS1Click(Sender: TObject);
begin
BONUS1.Visible := false;
mediaplayer5.play;
end;

procedure TForm1.Bonus2Click(Sender: TObject);
begin
if BONUS1.Visible = false then begin
BONUS2.Visible := false;
mediaplayer5.play;
end;
end;
procedure TForm1.Bonus4Click(Sender: TObject);
begin
if BONUS3.Visible = false then begin
BONUS4.Visible := false;
mediaplayer5.play;
end;
end;
procedure TForm1.MediaPlayer4Notify(Sender: TObject);
begin
if (MediaPlayer4.NotifyValue = nvSuccessful) and (Loop2=true) then
begin
    MediaPlayer4.Play;
    MediaPlayer4.Notify := true;
end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
button1.enabled := true;
end;

procedure TForm1.Label5Click(Sender: TObject);
begin
mediaplayer3.play;
levens:= levens + 1;
score:= score - 80;
end;

procedure TForm1.closeallClick(Sender: TObject);
begin
close;
end;

procedure TForm1.tryagainClick(Sender: TObject);
begin
apprestart;
end;

end.
