Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:13 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
stimmt das dann so?
Ja, das ist nicht falsch. :zustimm: Aber auch noch nicht alles... :? Immer mit der Ruhe. ;)

Ich würde das etwas allgemeiner formulieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function TForm1.LebtNachbar(x, y: Integer): Boolean;
begin
  ShowMessageFmt('vorher: x=%d, y=%d', [x, y]); // das hier ist nur zum Testen
  if (x < 0then
    x := x +N;
  if (y < 0then
    y := y +N;
  ShowMessageFmt('nachher: x=%d, y=%d', [x, y]); // das hier ist nur zum Testen
  Result := Feld[x, y];
end;

Probier´s mal mit dem Test-Button aus. :les:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 14:16 
das ist gut :) das klappt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:19 
Moin!

OK, nächster Schritt: ändere mal in dem btnTest-Handler die Aufrufparameter ab, so dass die rechte untere Zelle abgefragt wird. Dann auf den Test-Button klicken. Gibt´s da evtl. noch Probleme? :lupe:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 14:33 
da gibt es jetzt zellen mit [4,4] und so und die gibt es nicht, die müssen wieder auf die andere seite

das hab ich jetzt so abgeändert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function TForm1.LebtNachbar(x, y: Integer): Boolean;
begin
  ShowMessageFmt('vorher: x=%d, y=%d', [x, y]); // das hier ist nur zum Testen
  if (x < 0then
    x := x +N;
  if (y < 0then
    y := y +N;
   if (x > (N-1)) then
    x := x -N;
  if (y > (N-1)) then
    y := y -N;
  ShowMessageFmt('nachher: x=%d, y=%d', [x, y]); // das hier ist nur zum Testen
  Result := Feld[x, y];
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:37 
Moin!

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
da gibt es jetzt zellen mit [4,4] und so und die gibt es nicht, die müssen wieder auf die andere seite
Jap. :)

user profile iconNini hat folgendes geschrieben Zum zitierten Posting springen:
das hab ich jetzt so abgeändert:
Funktionsfähig, zwar etwas umständlich, aber OK! :zustimm:

Dann nimm mal die Testausgaben raus, damit du dich gleich nicht "totklickst". ;) Wir sind soweit, einen echten Lauf zu probieren. :hair: Also klick dir mal drei schwarze Zellen horizontal oder vertikal zusammen (einen "Strich"), dann auf den btnLesen, dann btnRechnen, dann btnSchreiben und ab da:
btnRechnen -> btnSchreiben -> btnRechnen -> btnSchreiben usw.

Was passiert? :lupe:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 14:40 
erst sind die zellen oxo dann ooo
oxo xxx
oxo ooo

und das wechselt sich immer ab
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:46 
Moin!

Passt, der Strich wechselt also immer von liegend auf stehend und zurück. ;)

Dann mach mal die mittleren 4 Zellen schwarz und lass den Rand weiß. Wieder so vorgehen wie gerade, Lesen, Rechnen, Schreiben, Rechnen, Schreiben, etc.

Was passiert?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 14:47 
die vier in der mitte bleiben schwarz, der rest bleibt weiß
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:52 
Moin!

Und, ist das OK so oder nicht? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 14:56 
das stimmt so
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 14:58 
Moin!

Fein. :zustimm:

Dann erweitern wir erstmal das Feld auf 5x5 Shapes. Kannst du das mal kurz machen? Was muss man da alles tun (Stichpunkte reichen)?

Wenn das läuft, machen wir noch die Automatik dazu und dann ist gut. :)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 15:00 
- die shapes hinzufügen
- die shapes auch mit in die procedure TForm1.Shape1MouseDown einbinden
- N von 4 auf 5 ändern
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 15:01 
Moin!

GO! :zustimm:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 15:06 
schon erledigt ;)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 15:22 
Moin!

Top! :D

Jetzt noch eine kleine Optimierung: wir haben immer nach einem Klick auf den btnRechnen auch auf den btnSchreiben gemacht (sonst sieht man ja nicht, was da berechnet wurde). Das machen wir jetzt per Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.btnRechnenClick(Sender: TObject);
  var
    x, y: Integer;
    FeldNeu: TFeld;
begin
  for y := 0 to N-1 do
    for x := 0 to N-1 do
      if Feld[x, y] then // lebende Zelle
        FeldNeu[x, y] := (AnzahlLebenderNachbarn(x, y) in [2..3]) // Überleben
      else // tote Zelle
        FeldNeu[x, y] := (AnzahlLebenderNachbarn(x, y) = 3); // Geburt
  Feld := FeldNeu;
  btnSchreibenClick(Self); // virtuell auf den Button klicken
end;


Dann löschst du alle Buttons aus dem Formular (dabei sollte der Code für die Button-Handler stehen bleiben - bis auf den Test-Button, den kannst du ganz rausnehmen, mit Code).

Jetzt geht´s an die Automatik: leg einen Timer auf das Formular, den Namen änderst du auf "Timer" (die "1" kann weg, wir brauchen nur einen) und die Eigenschaft .Enabled auf "False" (der soll nicht von selbst loslaufen, wenn das Programm startet). Anschließend legst du noch eine Checkbox neu auf das Formular, die nennst du mal "ckAutomatik" und bei Caption kannst du reinschreiben, was du möchtest, die Eigenschaft .Checked bleibt auf "False" stehen.

Jetzt machst du einen Doppelklick auf der Checkbox, es wird ein Handler erstellt, da schreibst du rein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.ckAutomatikClick(Sender: TObject);
begin
  if ckAutomatik.Checked then begin // Haken reingeklickt
    btnLesenClick(Self); // Feld einlesen
    Timer.Enabled := True; // Timer einschalten
  end
  else // Haken rausgeklickt
    Timer.Enabled := False; // Timer ausschalten
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 15:31 
ok, ich habe alles so gemacht
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 15:32 
Moin!

Gut, was passiert, wenn du den Haken setzt?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 15:37 
gar nichts :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 15.03.15 15:39 
Moin!

Warum? :lupe: Und was tun wir dagegen? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nini Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 170
Erhaltene Danke: 12



BeitragVerfasst: So 15.03.15 15:42 
weil in der lesenprozedur nicht gesagt wird, dass die rechenprozedur aufgerufen wird, also muss ich dort jetzt das so machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.btnLesenClick(Sender: TObject);
var x, y, snr: Integer;
    Shape: TShape;
begin
    for y := 0 to N-1 do // von unten nach oben
        for x := 0 to N-1 do begin // von rechts nach links
            snr := x +y *N +1;
            Shape := TShape(FindComponent('Shape' +IntToStr(snr)));
            if (Shape.Brush.Color = clBlack) then
               Feld[x, y] := True
            else
               Feld[x, y] := False;
        end;
      btnRechnenClick(Self);
end;