unit Spel;

interface

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

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

var
  Carmella: TCarmella;

implementation
  var
  scorecomp: integer;
  scoreplayer: integer;
  card: integer;
  win: boolean;
  loss: boolean;
{$R *.dfm}
  procedure gamestart (scorecomp, scoreplayer, card: integer);
    begin
    Randomize;
    scorecomp:= Random(7);
    scorecomp:= scorecomp + 14;
    card:= Random(10);
    card:= card + 1;
    scoreplayer:= card;
    card:= Random(10);
    card:= card + 1;
    scoreplayer:= scoreplayer + card;
    end;
procedure TCarmella.Button3Click(Sender: TObject);
begin
loss:= false;
win:= false;
if (Image7.Visible = true) then begin
Application.Messagebox('The game is finished, enjoy the view or reset the game','Game is 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 TCarmella.FormCreate(Sender: TObject);
begin
Image2.Visible:= true;
Image3.Visible:= false;
Image4.Visible:= false;
Image5.Visible:= false;
Image6.Visible:= false;
Image7.Visible:= false;
scoreplayer := 0;
end;

procedure TCarmella.Button1Click(Sender: TObject);
begin
if (Image7.Visible = true) then begin
Application.MessageBox('You have finished the game, enjoy the view or reset the game', 'Game is finished', mb_OK);
end
else if (scoreplayer = 0) then begin
Application.MessageBox('Please press "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 take another card or stop?');
if (scoreplayer > 21) then begin
scoreplayer := 0;
if(Image2.Visible = true) then begin
Application.MessageBox('You went over 21, and therefore you lose, since Carmella is already fully clothed, nothing will happen', 'Loss', mb_OK);
end
else begin
Application.MessageBox('You went over 21, and therefore you lose, Carmella will put some clothes on', 'Loss', mb_OK);
Memo1.Lines.Add('Carmellas score was '+IntToStr(scorecomp));
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
else if ((Image6.Visible = true) and (loss = true)) then begin
Image5.Visible := true;
Image6.Visible := false;
end;
end;
end;
end;

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

procedure TCarmella.Button4Click(Sender: TObject);
begin
if Application.MessageBox('Do you want to reset the game?', 'Reset', mb_YesNo) = IDYes then
  if Application.MessageBox('This means Carmella will put all her 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;
    Image7.Visible:= false;
    scoreplayer := 0;
    end
   else begin
   end
else begin
end;
end;

end.
