kromě funkce porovnávaní znaku mam hotovo.
Určitě znáte lepší řešení ale na začátečníka si myslím, že je to dobré.
Současně se zeptám jak udělat aby label (LVCastka) v proceduře (BtnHratClick) rotoval.
Vysvětlení: Měl by se cca po 1 sekundě měnit, třeba 7x pak by se zastavil a ta částka by se teprve akceptovala.
Zkoušel jsem to takto se sleep jenže ten to zaseká a efekt nenastane.
Kód: Vybrat vše
procedure TForm1.BtnHratClick(Sender: TObject);
var
i, c: integer; // c jako castka
begin
for i := 0 to 7 do
begin
Sleep(1000);
Randomize;
c := Random(11); // Nahodne cislo od 0 do 10
if (c = 0) then Castka := 100;
if (c = 1) then Castka := 100;
if (c = 2) then Castka := 100;
if (c = 3) then Castka := 100;
if (c = 4) then Castka := 200;
if (c = 5) then Castka := 200;
if (c = 6) then Castka := 200;
if (c = 7) then Castka := 500;
if (c = 8) then Castka := 500;
if (c = 9) then Castka := 1000;
if (c = 10) then Castka := 0;
if Castka > 0 then
LVCastka.Caption := ((IntToStr(Castka)) + ',- Kč')
else
LVCastka.Caption := ('BANKROT!!!');
Pocet := 0;
end;
if Castka > 0 then
Hadat
else
Hrat;
Vyhra := (Castka * Pocet) + Vyhra;
if LVCastka.Caption = 'BANKROT!!!' then
Ztrata
else
Vyhra := (Castka * Pocet) + Vyhra;
end;
Co se týče Timer tak tuto komponentu neznám a ani netuším jak bych jí implementoval do tohoto kódu.
Kdyby byl někdo tak moc hodný a pomohl mi byl bych rád.
Přikládám celý funkční kód.
Kód: Vybrat vše
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
BtnEnd: TButton;
BtnHrat: TButton;
LVCastka: TLabel;
LHFraze: TLabel;
BtnHledej: TButton;
Edit1: TEdit;
LCelkem: TLabel;
LFraze: TLabel;
Label1: TLabel;
Label2: TLabel;
LKonec: TLabel;
procedure BtnEndClick(Sender: TObject);
procedure BtnHratClick(Sender: TObject);
procedure BtnHledejClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Hadat;
procedure Hrat;
procedure HledanaFraze;
procedure Ztrata;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Castka: Integer;
Fraz: string;
Pocet: Integer;
Vyhra: Integer;
Skryte: string;
implementation
{$R *.dfm}
//=============================
// Vyber fraze (pranostiky)
//=============================
procedure Fraze;
var
f: Integer; // f jako Fraze
begin
Randomize;
f := Random(11); // Nahodne cislo od 0 do 10
if f = 0 then Fraz := 'na svatého jeronýma stěhuje se k nám už zima.';
if f = 1 then Fraz := 'jak na nový rok, tak po celý rok.';
if f = 2 then Fraz := 'na tři krále mrzne stále.';
if f = 3 then Fraz := 'únor bílý, pole sílí.';
if f = 4 then Fraz := 'na hromnice o hodinu více.';
if f = 5 then Fraz := 'svatý matěj ledy láme, nemá-li je, nadělá je.';
if f = 6 then Fraz := 'březen, za kamna vlezem. duben, ještě tam budem.';
if f = 7 then Fraz := 'kdo se v máji ožení, přivodí si soužení.';
if f = 8 then Fraz := 'o petru-li prší, po třicet dní déšť se vrší.';
if f = 9 then Fraz := 'svatá markyta hodila srp do žita.';
if f = 10 then Fraz := 'do svatého vavřince nechval pšenice.';
end;
//=============================
// Tlacitko Hrat
//=============================
procedure TForm1.BtnHratClick(Sender: TObject);
var
c: integer; // c jako castka
begin
Randomize;
c := Random(11); // Nahodne cislo od 0 do 10
if (c = 0) then Castka := 100;
if (c = 1) then Castka := 100;
if (c = 2) then Castka := 100;
if (c = 3) then Castka := 100;
if (c = 4) then Castka := 200;
if (c = 5) then Castka := 200;
if (c = 6) then Castka := 200;
if (c = 7) then Castka := 500;
if (c = 8) then Castka := 500;
if (c = 9) then Castka := 1000;
if (c = 10) then Castka := 0;
if Castka > 0 then
LVCastka.Caption := ((IntToStr(Castka)) + ',- Kč')
else
LVCastka.Caption := ('BANKROT!!!');
Pocet := 0;
if Castka > 0 then
Hadat
else
Hrat;
Vyhra := (Castka * Pocet) + Vyhra;
if LVCastka.Caption = 'BANKROT!!!' then
Ztrata
else
Vyhra := (Castka * Pocet) + Vyhra;
end;
//=============================
// Aktivace a deaktivace tlacitek pri bankrotu
//=============================
procedure TForm1.Hadat; // vylosovana castka
begin
BtnHrat.Enabled := False;
Edit1.Clear;
BtnHledej.Enabled := True;
end;
procedure TForm1.Hrat; // vylosovany bankrot
begin
BtnHrat.Enabled := True;
BtnHledej.Enabled := False;
end;
procedure TForm1.HledanaFraze; // zobrazeni hledane fraze
begin
LHFraze.Visible := True;
LHFraze.Caption := Fraz;
end;
procedure TForm1.Ztrata; // zobrazeni hledane fraze
begin
Vyhra := 0;
LCelkem.Caption := IntToStr(0) + ',- Kč';
end;
//=============================
// Tlacitko hledej
//=============================
procedure TForm1.BtnHledejClick(Sender: TObject);
var
i: Integer;
Pismeno: string;
begin
Pocet := 0;
Pismeno := Edit1.Text;
for i := 1 to length(Fraz) do // string indexujeme od 1
begin
if Pismeno = Fraz[i] then
begin
Skryte[i] := Fraz[i];
Pocet := Pocet + 1;
end;
end;
if Fraz = Skryte then LKonec.Caption := 'Vyhraná částka je ';
LFraze.Caption := Skryte;
Vyhra := (Castka * Pocet) + Vyhra;
LCelkem.Caption := IntToStr(Vyhra) + ',- Kč';
Hrat; // vylosovana castka
end;
//=============================
// Vytvoreni formulare
//=============================
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Fraze;
HledanaFraze; // zakomentujte "//" pro skryti hledane fraze
Hrat; // nastavení tlacitek na hru (vylosovany bankrot)
Vyhra := 0;
Skryte := '';
for i := 1 to Length(Fraz) do // string indexujeme od 1
begin
if Fraz[i] = '.' then
Skryte := Skryte + '.'
else
if Fraz[i] = ',' then
Skryte := Skryte + ','
else
if Fraz[i] = ' ' then
Skryte := Skryte + ' '
else
if Fraz[i] = '-' then
Skryte := Skryte + '-'
else
Skryte := Skryte + '*';
LFraze.Caption := Skryte;
end;
end;
//=============================
// Tlacitko Konec
//=============================
procedure TForm1.BtnEndClick(Sender: TObject);
begin
Close;
end;
end.
a zde odkaz ke stažení https://drive.google.com/open?id=11wRPBNuwfvkv55vBcGbhqFpx1zdswzXo