Autor Beitrag
christian_m
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mi 09.05.07 21:09 
Hi Delphi Community!
Zurzeit versuche ich ein Brettspiel zu programmieren. Dazu habe ich als Spielfelder mehrere Shapes als Objekte eingefügt. Die Figuren sind Images.

Ich habe nun folgende Frage:
Kann man, um Platz im Quellcode zu sparen, variable Shapes aufrufen und die Position eines Shapes einem Image zuweisen ??
So in etwa:
ausblenden Quelltext
1:
2:
    image1.left:=shape[i+Zahl].left+5;
   image1.top:=shape[i+Zahl].top-20;


"i" entspricht dem aktuellen shape auf dem sich das image befindet;
"Zahl" ist eine gewürfelte Zahl, die man zur shapeZahl addieren soll.

//Oder kann man das mit den Tagnummern der Shapes realisieren??

Über Antworten/Beispiele wäre ich total froh

mfg christian_m
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 09.05.07 21:45 
Moin und :welcome: im Forum!

Du suchst Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mi 09.05.07 21:52 
Hallo Narses

Danke für die schnelle antwort

Chris
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 09.05.07 21:54 
Moin!

user profile iconchristian_m hat folgendes geschrieben:
Danke für die schnelle antwort

Bitte. ;)

Markierst du den Thread noch entsprechend, wenn dein Problem gelöst ist? Danke. :)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 10.05.07 13:18 
Ich bins nochmal!!

Nun hab ich mir zwar Beispiele zu FindComponent angeschaut, weiß jedoch nicht wie ich dies in den gewünschten Befehl umsetzen könnte.

Nochmal die Frage:

Was ist bei meinem Quellcode richtig/ was ist falsch, wenn ich ein shape habe auf dem ein image sich befindet
1. dieses sich (- mache ich dann bei onMouse.dblClick - ) auf die Position des "neuen
Shapes" verschiebt (nicht pixelweise)
-> das neue Shape soll berechnet werden, indem im Namen (??? oder anderst???) (oder die
Tagnummmer) die Zahl des Shapes mit der gewürfelten zahl addiert wird.
2. die neue Position des Images ist dann der neue Name (die neue Tagnummer??) des Shapes


Ich habe 10 Shapes und 1 Image:
die Position wird hier im Beispeil nur bei einer 1 berechnet( kann ich da auch wieder eine Schleife machen? :

for 1 to 6 do ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
for i:=1 to 10 do
 if Zahl = 1
 then
  begin
  //////die Position des Images ist die Position des aktuellen shapes + die gewürfelte Zahl
    <span style="color: red">// Wenn sich das Image auf dem alten Shape (Shape[i] befindet</span>    
    if Image1.top = (FindComponent('Shape' + IntToStr(i)) as TShape).top
    and if Image1.left = (FindComponent('Shape' + IntToStr(i)) as TShape).left
     then
      begin
  <span style="color: red">//ist das hier richtig oder ist dann das "alte Shape auf der Position des neuen Shapes? </span>
      (FindComponent('Shape' + IntToStr(i)) as TShape).top :=(FindComponent('Shape' +
       IntToStr(i)+IntToStr(Zahl)) as TShape).top;
      (FindComponent('Shape' + IntToStr(i)) as TShape).left := (FindComponent('Shape' +
       IntToStr(i)+IntToStr(Zahl)) as TShape).left;
        <span style="color: red">// das image soll auf die Position des neuen Shapes</span>
       image1.top := (FindComponent('Shape' + IntToStr(i)) as TShape).top-20;
       image1.left :=  (FindComponent('Shape' + IntToStr(i)) as TShape).left+5;


Vielen Dank im Voraus!

mfg Chris