1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174:
| unit mGalgenmaennchen;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type THangman = class(TForm) laRatenSie: TLabel; laRatewort: TLabel; imZeichenflaeche: TImage; edEingabe: TEdit; edFehlversuche: TEdit; laFehlversuch: TLabel; procedure FormCreate(Suchwort: string; var Ratewort:string ); procedure FormKeyPress(Sender: TObject; var Key: Char); private i,Fehlversuche: integer; Ratewort,Suchwort: string; Buchstabe,Zeichen: char; 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 Zeichnen; public end;
var Hangman: THangman;
implementation
function THangman.Zufallswort:string; var Zahl: integer; begin Zahl := Random (10); case Zahl of 0: Result := 'INFORMATIK'; 1: Result := 'SYLT'; 2: Result := 'SCHLIESSFAECHER'; 3: Result := 'KUTIKULA'; 4: Result := 'TANGENTENSTEIGUNGSFUNKTION'; 5: Result := 'ETHANOLSAEURE'; 6: Result := 'KORBLEGER'; 7: Result := 'AKTIVIERUNGSENERGIE'; 8: Result := 'FINGERHUT'; 9: Result := 'GITARRENSAITE'; end; end;
procedure THangman.Erzeugen (Suchwort: string; var Ratewort: string); var i: integer; begin Ratewort := ''; for i := 1 to Length (Suchwort) do Ratewort := Ratewort + '_ '; end;
procedure THangman.FormKeyPress(Sender: TObject; var Key: Char); var Zeichen: char; Fehlversuche: integer; begin Fehlversuche := 0; Zeichen := Upcase(Key); edEingabe.Text := Zeichen; if IstVorhanden(Zeichen,Suchwort) = True then begin Ersetzen(Zeichen,Suchwort,Ratewort); laRatewort.Caption := Ratewort end else begin Zeichnen; Fehlversuche := Fehlversuche + 1; end end;
function THangman.IstVorhanden (Zeichen: char; Wort: string):boolean; var i: integer; Vorhanden: boolean; begin i := 1; Vorhanden := False; repeat if Zeichen = Wort[i] then Vorhanden := True; i := i + 1; until (Vorhanden = True) or (i > Length(Wort)); 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 Buchstabe=Suchwort[i] then Ratewort [2*i-1]:=Buchstabe end;
{$R *.dfm}
procedure THangman.FormCreate(Suchwort: string; var Ratewort:string ); begin i := 0; imZeichenflaeche.Canvas.Rectangle(0,0,imZeichenflaeche.Width,imZeichenflaeche.Height); end;
procedure THangman.Zeichnen; var Fehlversuche: integer; begin i := i+1; with imZeichenflaeche.Canvas do case i of 1: begin Pie(40,190,60,210,40,205,60,205); Fehlversuche := Fehlversuche + 1; end; 2: begin MoveTo (50,190); LineTo (50,110); end; 3: begin MoveTo (50,110); LineTo (90,110); end; 4: begin MoveTo (75,110); LineTo (50,130); end; 5: begin MoveTo (90,110); LineTo (90,130); end; 6: Ellipse (80,130,100,150); 7: begin MoveTo (90,150); LineTo (90,175); end; 8: begin MoveTo (90,175); LineTo (80,185); end; 9: begin MoveTo (90,175); LineTo (100,185); end; 10: begin MoveTo (90,165); LineTo (80,160); end; 11: begin MoveTo (90,165); LineTo (100,160); ShowMessage('Sie haben verloren!'); end; end; end; end. |