Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Schulprojekt Kniffel ! 3/4 Pasch und Full house (https://www.delphipraxis.net/160966-schulprojekt-kniffel-3-4-pasch-und-full-house.html)

keikedeike 9. Jun 2011 21:48

Schulprojekt Kniffel ! 3/4 Pasch und Full house
 
Hallo

Hab ein Schulprojekt 'Kniffel' bzw 'Yahtzee'

Hab dat Projekt jetzt soweit fertig nur fehlt mir noch 3/4 Pasch und Das Full House, jedoch habe ich keine Ahnung wie ich die Programieren soll ! Er ist ziemlich dringend denn muss nächste Woche abgeben :shock:


Wäre echt nett wenn ihr mit Helfen könnten




hab den 3-Pasch mal programmiert jedoch geht er nur wenn der 1. Wurfel zum Pasch gehört zb 32331 wenn die Würfel auf 23133 fallen funktioniert der Knopf nicht ! Schicke mal den den Quelltext




Delphi-Quellcode:
procedure Tzt.btndreierpaschClick(Sender: TObject);
var i,j,comp:integer;
         str:string;
begin
  btndreierpasch.enabled := false;
  btnbegin.enabled := true;
  comp:=1;
  str:=lbl1.caption+lbl2.caption+lbl3.caption+lbl4.caption+lbl5.caption;

  for i:=0 to 4 do
  begin
  if comp < 3 then
  begin
  comp:=1;
    for j:=i+1 to 4 do
    begin
      if (str[i])=(str[j]) then
      comp:=comp+1;
    end;
    end;
    end;

    if comp >= 3 then
    lbldreierpasch.caption:=(inttostr (strtoint(lbl1.caption)+ strtoint(lbl2.caption)+ strtoint(lbl3.caption)+ strtoint(lbl4.caption)+ strtoint(lbl5.caption)));
    lblN.caption := '0';


Danke im vorraus :-D
mfg Keikedeike

Norbert987 9. Jun 2011 23:33

AW: Schulprojekt Kniffel ! 3/4 Pasch und Full house
 
Strings beginnen in Delphi an Position 1. Somit brauchst du deine Schleifen nur von 1-5 statt 0-4 laufen zu lassen und das Problem sollte gelöst sein.

Bitte benutzer beim nächstenmal die Delphi Code Tags

Delphi-Quellcode:
procedure Tzt.btndreierpaschClick(Sender: TObject);
var
  i,j,comp:integer;
  str:string;
begin
  btndreierpasch.enabled := false;
  btnbegin.enabled := true;
  comp:=1;
  str:=lbl1.caption+lbl2.caption+lbl3.caption+lbl4.c aption+lbl5.caption;

  for i:=1 to 5 do
  begin
    if comp < 3 then
    begin
      comp:=1;
      for j:=i+1 to 5 do
      begin
        if (str[i])=(str[j]) then
          comp:=comp+1;
      end;
    end;
  end;

  if comp >= 3 then
    lbldreierpasch.caption:=(inttostr (strtoint(lbl1.caption)+ strtoint(lbl2.caption)+ strtoint(lbl3.caption)+ strtoint(lbl4.caption)+ strtoint(lbl5.caption)));
 
  lblN.caption := '0';
Gruß, Norbert

keikedeike 10. Jun 2011 00:13

AW: Schulprojekt Kniffel ! 3/4 Pasch und Full house
 
hey :P danke für deine schnell Lösung hab aber jetzt irgentwie nen andern Weg gefunden um den 3/4 Pasch zu machen !


Hab nun noch immer keine Lösung für den Full House Knopf :shock:

Ideen wären gut ! :P

danke im vorraus

mfg Keikedeike

DeddyH 10. Jun 2011 07:14

AW: Schulprojekt Kniffel ! 3/4 Pasch und Full house
 
Ich hatte doch bereits im anderen Thread einen Tipp gegeben.

Bjoerk 10. Jun 2011 13:04

AW: Schulprojekt Kniffel ! 3/4 Pasch und Full house
 
Haben in der Mittagspause auch mal gekniffelt. Wenn du die Ergebnisse der 5 Würfel in einem array speicherst wird’s leichter. Wenn du dieses array sortierst, wird’s noch leichter.

Delphi-Quellcode:
type
  TWuerfel = array [1..5] of integer;
Delphi-Quellcode:
function Sortiere (const W: TWuerfel): TWuerfel;
var
  I, J, T: integer;
begin
  Result:= W;
  for I:= 1 to 4 do
    for J:= I+1 to 5 do
      if Result[I] > Result[J] then
      begin
        T:= Result[I];
        Result[I]:= Result[J];
        Result[J]:= T;
      end;
end;


function Chance (const W: TWuerfel): integer;
var
  I: integer;
begin
  Result:= 0;
  for I:= 1 to 5 do
    Inc(Result, W[I]);
end;


function Dreierpasch (const W: TWuerfel): integer;
var
  I, N: integer;
  S: TWuerfel;
begin
  S:= Sortiere(W);
  Result:= 0;

  N:= 0;
  for I:= 1 to 2 do
    if S[I] = S[I+1] then Inc(N);
  if N = 2 then Result:= Chance(W);

  N:= 0;
  for I:= 2 to 3 do
    if S[I] = S[I+1] then Inc(N);
  if N = 2 then Result:= Chance(W);

  N:= 0;
  for I:= 3 to 4 do
    if S[I] = S[I+1] then Inc(N);
  if N = 2 then Result:= Chance(W);
end;


function FullHouse (const W: TWuerfel): integer;
var
  I, N: integer;
  S: TWuerfel;
begin
  S:= Sortiere(W);
  Result:= 0;

  N:= 0;
  for I:= 1 to 2 do
    if S[I] = S[I+1] then Inc(N);
  if N = 2 then
    if S[4] = S[5] then Result:= 25;

  N:= 0;
  for I:= 3 to 4 do
    if S[I] = S[I+1] then Inc(N);
  if N = 2 then
    if S[1] = S[2] then Result:= 25;
end;


function KleineStrasse (const W: TWuerfel): integer;
var
  I, N: integer;
  S: TWuerfel;
begin
  Result:= 0;
  S:= Sortiere(W);

  N:= 0;
  for I:= 1 to 3 do
    if S[I+1] = S[I]+1 then Inc(N);
  if N = 3 then Result:= 30;

  N:= 0;
  for I:= 2 to 4 do
    if S[I+1] = S[I]+1 then Inc(N);
  if N = 3 then Result:= 30;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz