Einzelnen Beitrag anzeigen

Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#17

Re: Kartenspiel Algorithmus

  Alt 3. Feb 2004, 19:16
Zitat von the_master:
Zitat von Nico1:
Eine Frage noch(bin nur so interresiert weil ich auch grad das brauche) aber warum kommt bei mir bis auf eine Herzausnahme NUR KARO?
Du musst im OnCreate der Form noch Randomize hinschreiben.
Er hat doch nicht etwa für jeden Funktionsaufruf das Programm neugestartet?

Ich hab übrigens noch einen Fehler gefunden... Mit 0 zu zählen zu beginnen ist ja doch besser. Jetzt tötet mich, ihr Pascal-Only-Jedis!

Delphi-Quellcode:
function PickCards(): String;
var
  Picked, i: Integer;
  Cards: set of 1..54;
  s: String;
begin
  Cards := [];
  for i := 1 to 10 do begin
    Picked := Random(54) + 1;
    if (not (Picked in Cards)) then
      Cards := Cards + [Picked];
  end;

  Result := '';
  for i := 1 to 54
    if (i in Cards) then begin
      case ((i - 1) div 13) of
        0: Result := 'Kreuz ';
        1: Result := 'Pik ';
        2: Result := 'Herz ';
        3: Result := 'Karo ';
      end;
      case ((i - 1) mod 13) of
        1: Result := Result + 'As';
        2..10: Result := Result + IntToStr(i mod 13);
        11: Result := Result + 'Bube';
        12: Result := Result + 'Dame';
        0: Result := Result + 'König';
      end;
    end;
end;
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat