Autor Beitrag
Elayla
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: So 08.06.03 22:02 
Ich hab ein kleines Problem, ich will ein Testprogramm schreiben das ein Array füllt mit den Nummern 1-3, welche Kartenstückchen representieren.
Jetzt möchte ich die Stückchen zeichnen, dafür habe ich eine Case-Of Abfrage in einer Repeat-Schleife eingebettet (Ich weiss das is sehr plump, aber mir fällt nix anderes ein :oops: )
Aber ich weis nicht wie man ein 2-dimensionales Array mit Case-Of "Vergleicht" und irgendwie funktioniert meine Prozedur nicht,
vielleicht könnt ihr mir ja helfen :wink:

ausblenden 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:
procedure Mapcreate;
var
  x,y,i,j:integer;
Begin
  x:=0;
  y:=0;
  i:=0;
  j:=0;
  Repeat
    Repeat
       Case Map[i,j] of
       1Begin
            Form1.DXImageList1.Items[0].Draw(Form1.DXDraw1.Surface,x,y,0);
          End;
       2Begin
            Form1.DXImageList1.Items[1].Draw(Form1.DXDraw1.Surface,x,y,0);
          End;
       3Begin
            Form1.DXImageList1.Items[2].Draw(Form1.DXDraw1.Surface,x,y,0);
          End;
       End;
    x:=x+40;
    i:=i+1;
    Until x=640;
      y:=y+40;
      j:=j+1;
    Until y=480;

End;



Moderiert von user profile icontommie-lie: Delphi-Tags hinzugefügt
umpani
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 389



BeitragVerfasst: So 08.06.03 22:14 
Hallo,

deine Procedure funktioniert deshalb nicht, weil du die i variabele nicht mehr auf 0 zurücksetzt (nach der ersten Repeatschleife).

Aber wenn dein Array aus Integerwerten besteht, dann machs doch so (ist viel kürzer):



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure Mapcreate; 
var 
x,y:integer; 
Begin 

for x := 1 to 12 do
  for y := 1 to 16 do
    begin
       Form1.DXImageList1.Items[map[x,y]-1].Draw(Form1.DXDraw1.Surface,x*40,y*40,0); {Minus eins, da deine arraywerte von 1 bis 3 gehen und die Imagelist bei 0 anfängt}
    end;
   Form1.DXDraw1.flip:
End;



Moderiert von user profile icontommie-lie: Code- durch Delphi-Tags ersetzt

_________________
Lernen, ohne zu denken, ist eitel; denken, ohne zu lernen, ist gefährlich. Konfuzius
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: So 08.06.03 22:20 
Umpf, stimmt das is viel besser :D
Naja man merkt das Abends die Luft weg is bei mir :wink:
Ich probiers gleich mal aus, danke dir :)
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: So 08.06.03 22:32 
Hmm der rechnet ne Weile zeigt aber nix an.
Prozedur scheint also zu funktionieren.
Stimmt diese Prozedur denn?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.DXDraw1Initialize(Sender: TObject);
var
  x,y:integer;
begin
  Randomize;
  For x:=1 To 16 Do
    For y:=1 To 12 Do
      Begin
        Map[x,y]:=random(3)+1;
      End;
  Mapcreate;
end;


Dürfte doch nix falsch sein, auf alle Einstellungen habe ich auch geachtet, wo könnte der Fehler liegen?

Achso, ich habe Form1.DXDraw1.Flip mit in die Schleife reingenommen, weil er sonst ja nur das letzte Feld zeichnet(oder?)


Moderiert von user profile icontommie-lie: Delphi-Tags hinzugefügt
P.S.: Demnächst bitte Delphi-Tags für Quellcodes nehmen, Danke! :)
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: So 08.06.03 22:43 
Hmm ich hab die Prozedur mit OnClick aufgerufen und nu funktionierts super :)

Warum funktioniert der Prozeduraufruf "Mapcreate" in keiner anderen Art und Weise, nur bei Click, nicht bei Initialize, nicht bei Enter, nix :cry:
umpani
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 389



BeitragVerfasst: Mo 09.06.03 10:12 
Versuch es mal nicht mit

procedure mapcrate;

sondern mit

procedure tform1.mapcreate;


Dann musst du es nur noch entsprechend in den Dateikopf eintragen.

Und denk daran, die Imagelist auf das dxdraw zu initialisieren.

_________________
Lernen, ohne zu denken, ist eitel; denken, ohne zu lernen, ist gefährlich. Konfuzius
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Mo 09.06.03 10:55 
K ich versuchs gleich mal, danke :)

Uhh, wie ruf ich die Prozedur auf?:

procedure TForm1.Mapcreate(Sender: TObject; a,b:integer);
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mo 09.06.03 17:09 
ausblenden Delphi-Quelltext
1:
  Form1.Mapcreate(Sender; a,b:integer); // was a und b ist weiß ich nicht  :(					

_________________
MFG
Michael Springwald, "kann kein englisch...."
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Mo 09.06.03 17:19 
Ahh ok, a und b sind die Positionen von denen die Prozedur anfangen soll die Karte zu zeichen, damit ich auch noch nach links und rechts scrollen kann :)
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mo 09.06.03 18:54 
a heißt eingetlich x und b heißt y :)

_________________
MFG
Michael Springwald, "kann kein englisch...."
Elayla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Mo 09.06.03 18:56 
Jain ^^
Hier zum nachvollziehen :P

Zitat:
procedure Mapcreate(a,b:integer);
var
x,y:integer;
Begin
if activ = 1 Then
Begin
Form1.DXDraw1.Surface.Fill(0);
for x := 1 to 16 do
for y := 1 to 12 do
begin
Form1.DXImageList1.Items[(map[a+x,b+y]-1)].Draw(Form1.DXDraw1.Surface,(x-1)*40,(y-1)*40,0);
end;
Form1.DXDraw1.flip;
End;
activ:=2;
End;