Autor Beitrag
masteroffinalfantasy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 31.01.05 21:31 
hi leute bin gerade am schreiben und stehe vor einem problem
ich wil meine würfelauswerten, willes aber nicht so kompliziert veranstalten und tausende von ifs benutzen.ich weiß bloß net wie man das anders machen kann
hier da code:
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:
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var Form2:TFOrm;
 ge,y:Array[1..5]of Integer;
 i,x,n,z,punkte,g1,g2:Integer;
 temp:string;
 w1,w2,w3,w4,w5,wx:boolean;
implementation

{$R *.dfm}

  procedure TForm2.Button2Click(Sender: TObject);
begin

 if x=3 then begin showmessage('Maximal 3 Würfe sind erlaubt!'); exit;end;
 Randomize;
 ge[1]:=0;
 ge[2]:=0;
 ge[3]:=0;
 ge[4]:=0;
 ge[5]:=0;


 for i:=1 to n do begin
 ge[i]:=random(6)+1;
 end;
 if ge[1]>0 then Panel1.caption:=inttostr(ge[1]);
 if ge[2]>0 then Panel2.caption:=inttostr(ge[2]);
 if ge[3]>0 then Panel3.caption:=inttostr(ge[3]);
 if ge[4]>0 then Panel4.caption:=inttostr(ge[4]);
 if ge[5]>0 then Panel5.caption:=inttostr(ge[5]);
  x:=x+1;
 if w1=true then Panel1.caption:=inttostr(y[1]);
 if w2=true then Panel2.caption:=inttostr(y[2]);
 if w3=true then Panel3.caption:=inttostr(y[3]);
 if w4=true then Panel4.caption:=inttostr(y[4]);
 if w5=true then Panel5.caption:=inttostr(y[5]);
  end;
 procedure TForm2.FormActivate(Sender: TObject);
begin
n:=5;
end;


procedure TForm2.Panel1Click(Sender: TObject);
begin
if w1=true then exit;
y[1]:=strtoint(Panel1.caption);
w1:=true;
end;

procedure TForm2.Panel2Click(Sender: TObject);
begin
 if w2=true then exit;
y[2]:=strtoint(Panel2.caption);
w2:=true;
end;

procedure TForm2.Panel3Click(Sender: TObject);
begin
 if w3=true then exit;
y[3]:=strtoint(Panel3.caption);
w3:=true;
end;

procedure TForm2.Panel4Click(Sender: TObject);
begin
 if w4=true then exit;
y[4]:=strtoint(Panel4.caption);
w4:=true;
end;

procedure TForm2.Panel5Click(Sender: TObject);
begin
 if w5=true then exit;
y[5]:=strtoint(Panel5.caption);
w5:=true;
end;

procedure TForm2.Button1Click(Sender: TObject);
BEGIN
  y[1]:=strtoint(panel1.caption);
  y[2]:=strtoint(panel2.caption);
  y[3]:=strtoint(panel3.caption);
  y[4]:=strtoint(panel4.caption);
  y[5]:=strtoint(panel5.caption);
   //hier auswerten

end;

end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Socher
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

warmes flüssiges Blut
D7 Prof, D8 Prof
BeitragVerfasst: Mo 31.01.05 21:42 
mach aus "w1,w2,w3,w4,w5,wx:boolean;" auch ein array und Pack das
ganze dann in eine Schleife:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i:=1 to n do if ge[i]>0 then Panel1.caption:=inttostr(ge[i]);  

x:=x+1;  

for i:=1 to n do if w[i]=true then Panel1.caption:=inttostr(y[i]);


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.

_________________
FREIHEIT


Zuletzt bearbeitet von Socher am Mo 31.01.05 21:45, insgesamt 1-mal bearbeitet
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 31.01.05 21:44 
und wiekann ich dann herausbekommen obs fullhouse und sowas is?
Socher
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

warmes flüssiges Blut
D7 Prof, D8 Prof
BeitragVerfasst: Mo 31.01.05 22:31 
Füge noch ein Memo1 und Button3 ein und dann..


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:
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:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
unit Unit1;

interface

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

type
  TForm2 = class(TForm)
    Button2: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Button1: TButton;
    Button3: TButton;
    Memo1: TMemo;
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure Panel2Click(Sender: TObject);
    procedure Panel3Click(Sender: TObject);
    procedure Panel4Click(Sender: TObject);
    procedure Panel5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var Form2:TFOrm;  
 ge,y:Array[1..5]of Integer;  
 i,x,n,z,punkte,g1,g2:Integer;  
 temp:string;  
 w1,w2,w3,w4,w5,wx:boolean;  
implementation  

 
{$R *.dfm}


  procedure TForm2.Button2Click(Sender: TObject);  
begin  

 
 if x=3 then begin showmessage('Maximal 3 Würfe sind erlaubt!'); exit;end;  
 Randomize;  
 ge[1]:=0;  
 ge[2]:=0;  
 ge[3]:=0;  
 ge[4]:=0;  
 ge[5]:=0;  

 

 
 for i:=1 to n do begin  
 ge[i]:=random(6)+1;  
 end;
 if ge[1]>0 then Panel1.caption:=inttostr(ge[1]);  
 if ge[2]>0 then Panel2.caption:=inttostr(ge[2]);  
 if ge[3]>0 then Panel3.caption:=inttostr(ge[3]);  
 if ge[4]>0 then Panel4.caption:=inttostr(ge[4]);  
 if ge[5]>0 then Panel5.caption:=inttostr(ge[5]);  
  x:=x+1;  
 if w1=true then Panel1.caption:=inttostr(y[1]);  
 if w2=true then Panel2.caption:=inttostr(y[2]);  
 if w3=true then Panel3.caption:=inttostr(y[3]);  
 if w4=true then Panel4.caption:=inttostr(y[4]);  
 if w5=true then Panel5.caption:=inttostr(y[5]);  
  end;
 procedure TForm2.FormActivate(Sender: TObject);  
begin  
n:=5;  
end;  

 


procedure TForm2.Panel1Click(Sender: TObject);  
begin  
if w1=true then exit;  
y[1]:=strtoint(Panel1.caption);  
w1:=true;  
end;  

 
procedure TForm2.Panel2Click(Sender: TObject);  
begin  
 if w2=true then exit;  
y[2]:=strtoint(Panel2.caption);  
w2:=true;  
end;  

 
procedure TForm2.Panel3Click(Sender: TObject);  
begin  
 if w3=true then exit;  
y[3]:=strtoint(Panel3.caption);  
w3:=true;  
end;  

 
procedure TForm2.Panel4Click(Sender: TObject);  
begin  
 if w4=true then exit;  
y[4]:=strtoint(Panel4.caption);  
w4:=true;  
end;  

 
procedure TForm2.Panel5Click(Sender: TObject);  
begin  
 if w5=true then exit;  
y[5]:=strtoint(Panel5.caption);  
w5:=true;  
end;  


procedure TForm2.Button1Click(Sender: TObject);  
BEGIN  
  y[1]:=strtoint(panel1.caption);  
  y[2]:=strtoint(panel2.caption);  
  y[3]:=strtoint(panel3.caption);  
  y[4]:=strtoint(panel4.caption);  
  y[5]:=strtoint(panel5.caption);
   //hier auswerten


end;


procedure TForm2.Button3Click(Sender: TObject);
var i,j:integer;
    nw:array[1..6of integer; // Vorkommen der Zahlen
    Pasch2er,Pasch3er:integer;
begin
for i:=1 to 6 do nw[i]:=0;
Pasch2er:=0;
Pasch3er:=0;

y[1]:=strtoint(panel1.Caption);
y[2]:=strtoint(panel2.Caption);
y[3]:=strtoint(panel3.Caption);
y[4]:=strtoint(panel4.Caption);
y[5]:=strtoint(panel5.Caption);

memo1.Clear;

for i:=1 to 5 do
  begin
  if y[i]=1 then inc(nw[1],1); // Anzahl Einsen
  if y[i]=2 then inc(nw[2],1); // Anzahl Zweien
  if y[i]=3 then inc(nw[3],1);
  if y[i]=4 then inc(nw[4],1);
  if y[i]=5 then inc(nw[5],1);
  if y[i]=6 then inc(nw[6],1);
  end;


  for i:=1 to 5 do memo1.Lines.Add(inttostr(y[i])+'/');

for i:=1 to 6 do
   begin
   if nw[i]=2 then
     begin
     Memo1.Lines.Add('Zweirpasch mit '+inttostr(i));
     inc(Pasch2er,1);
     end;
   if nw[i]=3 then
     begin
     Memo1.Lines.Add('Dreierpasch mit '+inttostr(i));
     inc(Pasch3er,1);
     end;
   if nw[i]=4 then Memo1.Lines.Add('Viererpasch mit '+inttostr(i));
   if nw[i]=5 then Memo1.Lines.Add('Fünferpasch mit '+inttostr(i));

   end;

if (Pasch2er=1and (Pasch3er=1then Memo1.Lines.Add('Full House');
end;

end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.

_________________
FREIHEIT