unit Spel7;

interface

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

type
  TRobbie = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Robbie: TRobbie;

implementation
var
  scorecomp: integer;
  scoreplayer: integer;
  card: integer;
  win: boolean;
  loss: boolean;
{$R *.dfm}

procedure TRobbie.FormCreate(Sender: TObject);
begin
Image2.Visible := true;
Image3.Visible := false;
Image4.Visible := false;
Image5.Visible := false;
Image6.Visible := false;
scoreplayer := 0;
end;

procedure TRobbie.Button3Click(Sender: TObject);
begin
loss := false;
win := false;
if(Image6.Visible = true) then begin
Application.MessageBox('You have finished the game, enjoy the view or reset the game', 'Game if finished', mb_OK);
end
else if (scoreplayer = 0) then begin
Memo1.Lines.Clear;
Randomize;
    scorecomp:= Random(7);
    scorecomp:= scorecomp + 14;
    card:= Random(10);
    card:= card + 1;
    scoreplayer:= card;
    card:= Random(10);
    card:= card + 1;
    scoreplayer:= scoreplayer + card;
Memo1.Lines.Add('Your starting hand is ' + IntToStr(scoreplayer) + ', would you like take another card or stop?');
end
else begin
Application.MessageBox('Dont cheat, play with the cards you are dealt', 'Cheater', mb_OK);
end;
end;

procedure TRobbie.Button1Click(Sender: TObject);
begin
if (Image6.Visible = true) then begin
Application.MessageBox('You have finished the game, enjoy the view, or reset the game', 'Game finished', mb_OK);
end
else if (scoreplayer = 0) then begin
Application.MessageBox('Please hit "Deal" first', 'Error', mb_OK);
end
else begin
loss := false;
win := false;
Randomize;
  card:= random(10);
  card:= card + 1;
  scoreplayer := scoreplayer + card;
Memo1.Lines.Add('Your current hand is '+IntToStr(scoreplayer)+', would you like to take another card or stop?');
if (scoreplayer > 21) then begin
if (Image2.Visible = true) then begin
Application.MessageBox('You went over 21, and therefore, you lose, since Robbie was already fully clothed nothing will happen', 'Loss', mb_OK);
Memo1.Lines.Add('Robbies score was ' + IntToStr(scorecomp));
end
else begin
Application.MessageBox('You went over 21, and therefore, you lose, Robbie will put some more clothes on', 'Loss', mb_ok);
Memo1.Lines.Add('Robbies score was '+IntToStr(scorecomp));
end;
loss := true;
scoreplayer := 0;
end;
if (Image3.Visible = true) and (loss = true) then begin
Image2.Visible := true;
Image3.Visible := false;
end
else if (Image4.Visible = true) and (loss = true) then begin
Image3.Visible := true;
Image4.Visible := false;
end
else if (Image5.Visible = true) and (loss = true) then begin
Image4.Visible := true;
Image5.Visible := false;
end;
end;
end;

procedure TRobbie.Button2Click(Sender: TObject);
begin
if (Image6.Visible = true) then begin
Application.MessageBox('You have finished the game, enjoy the view, or reset the game', 'Game finished', mb_OK);
end
else if (scoreplayer = 0) then begin
Application.MessageBox('Please hit "Deal" first', 'Error', mb_OK);
end
else begin
loss := false;
win := false;
if (scoreplayer > scorecomp) then begin
Application.MessageBox('Congratulations, you beat Robbie, lets get ready to strip', 'Win', mb_OK);
Memo1.Lines.Add('Robbies score was ' + IntToStr(scorecomp));
win := true;
end
else if (scoreplayer < scorecomp) then begin
if (Image2.Visible = true) then begin
Application.MessageBox('Too bad, Robbie had a higher score than you, since he was already fully clothed nothing will happen', 'Loss', mb_OK);
Memo1.Lines.Add('Robbies score was '+IntToStr(scorecomp));
end
else begin
Application.MessageBox('Too bad, Robbie had a higher score than you, he will put on some more clothes', 'Loss', mb_OK);
Memo1.Lines.Add('Robbies score was ' + IntToStr(scorecomp));
loss := true;
end;
end
else if (scoreplayer = scorecomp) then begin
Application.MessageBox('You and Robbie had a draw, nothing happens', 'Draw', mb_OK);
Memo1.Lines.Add('Robbies score was ' + IntToStr(scorecomp));
end;
if ((Image2.Visible = true) and (win = true)) then begin
Image3.Visible := true;
Image2.Visible := false;
end
else if ((Image3.Visible = true) and (win = true)) then begin
Image4.Visible := true;
Image3.Visible := false;
end
else if ((Image3.Visible = true) and (loss = true)) then begin
Image2.Visible := true;
Image3.Visible := false;
end
else if ((Image4.Visible = true) and (win = true)) then begin
Image5.Visible := true;
Image4.Visible := false;
end
else if ((Image4.Visible = true) and (loss = true)) then begin
Image3.Visible := true;
Image4.Visible := false;
end
else if ((Image5.Visible = true) and (win = true)) then begin
Image6.Visible := true;
Image5.Visible := false;
Application.MessageBox('You have unlocked the last level of Robbie Williams, this game is finished', 'You is winner', mb_OK);
end
else if ((Image5.Visible = true) and (loss = true)) then begin
Image4.Visible := true;
Image5.Visible := false;
end
else if ((Image6.Visible = true) and (loss = true)) then begin
Image5.Visible := true;
Image6.Visible := false;
end;
scoreplayer := 0;
end;
end;

procedure TRobbie.Button4Click(Sender: TObject);
begin
if Application.MessageBox('Do you want to reset the game?', 'Reset', mb_YesNo) = IDYes then
  if Application.MessageBox('This means Robbie will put all his clothes back on. Are you really, really sure you want to reset?' , 'Really?', mb_YesNo) = IDYes then
    begin
    Image2.Visible:= true;
    Image3.Visible:= false;
    Image4.Visible:= false;
    Image5.Visible:= false;
    Image6.Visible:= false;
    scoreplayer := 0;
    end
   else begin
   end
else begin
end;
end;

end.
