Autor Beitrag
Battery
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Mi 15.02.06 16:57 
Hallo
ich habe das Spiel Hangman programmiert, sodass sich bei jedem falschen Versuch der Hangman aufgegebaut wird (bin Anfängerm daher über visible/ invislbe bilder ;-) )
Wenn ich jetzt ein neues Wort übernehmen möchte, hängt sich das Programm auf, obwohl es vorher einwandfrei lief und keine Fehler angezeigt werden.
Weis jemand Rat?

ausblenden volle Höhe Delphi-Quelltext
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:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Button2: TButton;
    GroupBox1: TGroupBox;
    Edit3: TEdit;
    GroupBox2: TGroupBox;
    Edit4: TEdit;
    Button3: TButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  wort,keyword: string;
  a,n,x,y,laenge: integer;
  buchst: char;

implementation

{$R *.DFM}

{------------------------------Wort einlesen--------------------------------}

procedure TForm1.Button1Click(Sender: TObject);
begin
wort:=string (edit1.text);
edit1.text:='';
laenge:=length (wort);
repeat
x:=x+1;
edit1.text:=edit1.text +'*';
until x = laenge;
keyword:=string (edit1.text)

end;

{--------------------------Buchstaben übernehmen-----------------------------}
procedure TForm1.Button2Click(Sender: TObject);
begin
buchst:=string (edit2.text)[1];
n:=0;
a:=0;
edit2.text:='';

repeat
n:=n+1;
if buchst = wort[n] then
begin
keyword[n]:=char (buchst);
edit1.text:=string (keyword);
a:=a+1;
end;
edit3.text:='';

if keyword = wort then
edit1.text:='Du hast gewonnen!!!Das Wort war:  '+wort+'';
if a = 0
then edit3.text:='Leider falsch!!';
until n = laenge;


if a=0 then  y:=y+1;
edit4.text:=inttostr(y);
if y = 9 then edit3.text:='Verloren!!!!';
if edit4.text = '1' then image1.visible:=true;
if edit4.text = '2' then image2.visible:=true;
if edit4.text = '3' then image3.visible:=true;
if edit4.text = '4' then image4.visible:=true;
if edit4.text = '5' then image5.visible:=true;
if edit4.text = '6' then image6.visible:=true;
if edit4.text = '7' then image7.visible:=true;
if edit4.text = '8' then image8.visible:=true;
if edit4.text = '9' then image9.visible:=true;



end;

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.color:=clgreen;
y:=0;

end;
{--------------------------Clear----------------------------}
procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.text:='Bitte neues Wort eingeben!';
edit2.text:='';
edit3.text:='';
edit4.text:='';
image1.visible:=false;
image2.visible:=false;
image3.visible:=false;
image4.visible:=false;
image5.visible:=false;
image6.visible:=false;
image7.visible:=false;
image8.visible:=false;
image9.visible:=false;
wort:='';
keyword:='';

end;

end.
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Mi 15.02.06 18:17 
:welcome: im DF

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
begin
x:=0;// das musst du noch einfügen
     // das x wurde immer weiter hoch gezählt deswegen 
     // isser vorher inner endlosschleife gelandet
wort:=edit1.text;//das "string" kannst du weg lassen "edit1.text" is schon ein string  
edit1.text:='';
laenge:=length (wort);  
repeat
 inc(x);//ist das gleiche wie x:=x+1; sieht aber besser aus  
 edit1.text:=edit1.text +'*';
until x = laenge;
keyword:=(edit1.text)//"string" kann  auch hier weg...
end;


um dich gleich mal mit mehr wissen voll zu pumpen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
if edit4.text = '1' then image1.visible:=true;  
if edit4.text = '2' then image2.visible:=true;  
if edit4.text = '3' then image3.visible:=true;  
if edit4.text = '4' then image4.visible:=true;  
if edit4.text = '5' then image5.visible:=true;  
if edit4.text = '6' then image6.visible:=true;  
if edit4.text = '7' then image7.visible:=true;  
if edit4.text = '8' then image8.visible:=true;  
if edit4.text = '9' then image9.visible:=true;

kann auch so geschrieben werden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
case edit4.text of
'1' : image1.visible:=true;  
'2' : image2.visible:=true;  
'3' : image3.visible:=true;  
'4' : image4.visible:=true;  
'5' : image5.visible:=true;  
'6' : image6.visible:=true;  
'7' : image7.visible:=true;  
'8' : image8.visible:=true;  
'9' : image9.visible:=true; 
end;


bei mehreren fast gleichen if abfragen is case imma nützlich

so weit von mia :wink:

_________________
GEIZ IST GEIL! - Ihr Sozialamt
Battery Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Mi 15.02.06 18:54 
Danke dir! Das Prog klappt jetzt einwandfrei! Und auch danke für die case -of abfrage(man lernt zu wenig in info... :( )