Thema: Mastermind

Einzelnen Beitrag anzeigen

bigg
(Gast)

n/a Beiträge
 
#14

Re: Mastermind

  Alt 30. Dez 2005, 15:05
moin,

ich habe mir mal deinen Source angeguckt und festgestellt, das du wirklich jede Kombination manuell abfragst.

Delphi-Quellcode:
if (shape1.brush.color = clwhite) or (shape2.Brush.Color = clwhite) or (shape3.Brush.Color = clwhite) or (shape4.Brush.Color = clwhite) then showmessage ('Weiß ist keine Farbe. Bitte alle ausfüllen!!!') else
begin
  button1.Enabled := false;
button2.Enabled := true;

  if shape1.brush.color = clmaroon then Farbe[1] := 1 else
    if shape1.brush.Color = clgreen then Farbe[1] := 2 else
      if shape1.brush.Color = clnavy then Farbe[1] := 3 else
        if shape1.brush.Color = clyellow then Farbe[1] := 4 else
          if shape1.brush.Color = clteal then Farbe[1] := 5 else
            if shape1.brush.Color = clpurple then Farbe[1] := 6;

  if shape2.brush.color = clmaroon then Farbe[2] := 1 else
    if shape2.brush.Color = clgreen then Farbe[2] := 2 else
      if shape2.brush.Color = clnavy then Farbe[2] := 3 else
        if shape2.brush.Color = clyellow then Farbe[2] := 4 else
          if shape2.brush.Color = clteal then Farbe[2] := 5 else
            if shape2.brush.Color = clpurple then Farbe[2] := 6;
  
if shape3.brush.color = clmaroon then Farbe[3] := 1 else
    if shape3.brush.Color = clgreen then Farbe du hier eine Schleif[3] := 2 else
      if shape3.brush.Color = clnavy then Farbe[3] := 3 else
        if shape3.brush.Color = clyellow then Farbe[3] := 4 else
          if shape3.brush.Color = clteal then Farbe[3] := 5 else
            if shape3.brush.Color = clpurple then Farbe[1] := 6;
  
if shape4.brush.color = clmaroon then Farbe[4] := 1 else
    if shape4.brush.Color = clgreen then Farbe[4] := 2 else
      if shape4.brush.Color = clnavy then Farbe[4] := 3 else
        if shape4.brush.Color = clyellow then Farbe[4] := 4 else
          if shape4.brush.Color = clteal then Farbe[4] := 5 else
            if shape4.brush.Color = clpurple then Farbe[4] := 6 ;
activ := 2;
senddata;
Der obere Teil lässt sich mit einer Schleife wesentlich komfortabler lösen.

Wobei ich hier nicht den Farbcode erfragen würde, sondern einfach nur eine simple Nummer.
Du hast 6 Farben, die sich in ihrer Reihenfolge nichtverändern, also könntest du genauso 6 Nummern den Farben zuweisen von 1 bis 6.

In einem Array of TColor stehen dann die einzelnen Farben. Über den Index
(Nummer von 1-6) erhälst du anschließend die Farbe aus dem Array of TColor.


Die Shapes könnte man genauso gut dynamisch erstellen.
Wenn ich mich nicht täusche, sind es etwa 80, die du schon zur Entwurfszeit erstellt hast.
Noch eleganter wäre eine Klasse, aber das ist für den Anfang sicherlich zu heavy für dich.
  Mit Zitat antworten Zitat