unit mHangman;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, Menus;
type
THangman =
class(TForm)
imHangman: TImage;
paWort: TPanel;
laFehler: TLabel;
edFehler: TEdit;
edBuchstabe: TEdit;
laBuchstabe: TLabel;
mmMenue: TMainMenu;
Start1: TMenuItem;
Kategorie1: TMenuItem;
Sport1: TMenuItem;
Schule1: TMenuItem;
Natur1: TMenuItem;
Geografie1: TMenuItem;
Fernsehen1: TMenuItem;
Prominente1: TMenuItem;
Bearbeiten1: TMenuItem;
Loeschen1: TMenuItem;
N1: TMenuItem;
Ende1: TMenuItem;
N2: TMenuItem;
ber1: TMenuItem;
Hilfe1: TMenuItem;
N3: TMenuItem;
Neue_Runde1: TMenuItem;
Label1: TLabel;
Label2: TLabel;
edRichtig: TEdit;
edFalsch: TEdit;
Statistiken1: TMenuItem;
N4: TMenuItem;
tiEnabled: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject;
var Key: Char);
procedure Sport1Click(Sender: TObject);
procedure Schule1Click(Sender: TObject);
procedure Natur1Click(Sender: TObject);
procedure Geografie1Click(Sender: TObject);
procedure Fernsehen1Click(Sender: TObject);
procedure Prominente1Click(Sender: TObject);
procedure Neue_Runde1Click(Sender: TObject);
procedure Ende1Click(Sender: TObject);
procedure ber1Click(Sender: TObject);
procedure Statistiken1Click(Sender: TObject);
procedure Loeschen1Click(Sender: TObject);
procedure tiEnabledTimer(Sender: TObject);
procedure Hilfe1Click(Sender: TObject);
private
function Zufallswort:
string;
procedure Erzeugen(Suchwort:
string;
var Ratewort:
string);
function IstVorhanden (Zeichen: char; Wort:
string):Boolean;
procedure Ersetzen(Buchstabe: char; Suchwort:
string;
var Ratewort:
string);
procedure MenuLoeschen;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Hangman: THangman;
Phase, Zahl, Fehlversuche: Integer;
Suchwort, Ratewort:
String;
implementation
{$R *.dfm}
procedure THangman.FormCreate(Sender: TObject);
begin
Phase := 0;
Fehlversuche := 0;
Randomize;
imHangman.Canvas.Brush.Color := clWhite;
imHangman.Canvas.Fillrect(imHangman.Canvas.ClipRect)
end;
function THangman.Zufallswort:
string;
begin
case Zahl
of
0: Result := '
BERGETAPPE';
...
end;
procedure THangman.Erzeugen(Suchwort:
string;
var Ratewort:
string);
var i: integer;
begin
Ratewort := '
';
for i := 1
to Length(Suchwort)
do
Ratewort := Ratewort + '
_ '
end;
function THangman.IstVorhanden (Zeichen: char; Wort:
string):Boolean;
var i: integer;
Vorhanden: Boolean;
begin
i := 1;
Vorhanden := False;
while (Vorhanden = False)
or (i<= Length(Wort))
do
begin
if Zeichen = Wort[i]
then Vorhanden := True;
i := i+1;
end;
if Vorhanden = False
then begin
Fehlversuche := Fehlversuche + 1;
Phase := Phase + 1;
with imHangman.Canvas
do
case Phase
of
1:
begin
Pen.Width := 5;
Pie(10,410,110,270,110,340,10,340);
MoveTo(9,339);
Pen.Color := clWhite;
LineTo(110,339);
Pen.Color := clBlack
end;
2:
begin
MoveTo(60,270);
LineTo(60,10)
end;
3: LineTo(250,10);
4:
begin
MoveTo(60,50);
LineTo(100,10)
end;
5:
begin
MoveTo(250,10);
LineTo(250,60)
end;
6: Ellipse(225,60,275,110);
7:
begin
MoveTo(250,110);
LineTo(250,210)
end;
8:
begin
MoveTo(250,160);
LineTo(205,115)
end;
9:
begin
MoveTo(250,160);
LineTo(295,115)
end;
10:
begin
MoveTo(250,210);
LineTo(215,270)
end;
11:
begin
MoveTo(250,210);
LineTo(285,270)
end;
end;
end;
Result := Vorhanden;
end;
procedure THangman.Ersetzen(Buchstabe: char; Suchwort:
string;
var Ratewort:
string);
var i: integer;
begin
for i := 1
to Length(Suchwort)
do
if Suchwort[i] = Buchstabe
then Ratewort[2*i-1] := Buchstabe;
end;
procedure THangman.FormKeyPress(Sender: TObject;
var Key: Char);
var Zeichen, Unterstrich: Char;
begin
Key := Upcase(Key);
edBuchstabe.Text := '
';
if not (Key
in ['
A'..'
Z'])
then begin
Key := #00;
Messagebeep(mb_iconexclamation);
end
else begin
edBuchstabe.Text := Key;
IstVorhanden (Zeichen,Suchwort);
Ersetzen (Zeichen,Suchwort, Ratewort);
paWort.Caption := Ratewort;
Unterstrich := '
_';
end;
end;
procedure THangman.MenuLoeschen;
begin
Sport1.Checked := False;
Schule1.Checked := False;
Natur1.Checked := False;
Geografie1.Checked := False;
Fernsehen1.Checked := False;
Prominente1.Checked := False
end;
procedure THangman.Sport1Click(Sender: TObject);
begin
Zahl := Random(100);
MenuLoeschen;
Sport1.Checked := True
end;
procedure THangman.Neue_Runde1Click(Sender: TObject);
begin
edBuchstabe.Enabled := True;
MenuLoeschen;
Loeschen1.Click;
Fehlversuche := 0;
Phase := 0;
Zufallswort;
Erzeugen(Suchwort,Ratewort);
end;