AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

kniffel - zahlenabfrage

Ein Thema von pheel · begonnen am 26. Mai 2010 · letzter Beitrag vom 27. Mai 2010
Antwort Antwort
Seite 1 von 2  1 2      
pheel

Registriert seit: 26. Mai 2010
Ort: Frankfurt a.M.
4 Beiträge
 
Delphi 6 Personal
 
#1

kniffel - zahlenabfrage

  Alt 26. Mai 2010, 18:17
Soo hallo erstmal an die Community
Ich weiß nun nicht genau ob diese Frage auch wirklich hier herein gehört aber ich stelle
sie mal hier, kann ja bestimmt auch noch verschoben werden. Falls sie verschoben wird, danke dafür und entschuldigung.

So nun meine Frage.
Bin noch nicht lange beim programmieren an delphi, habe es jetz seit letzten Sommer in der Schule und stehe vor folgender Frage:
Ich möchte das Würfelspiel "Kniffel" bauen.
jetzt habe ich die anzeige von den würfeln auf einem shape, der als tisch dienen soll, schon gemacht.
ein zweites formular wo die werte gespeichert werden wird noch gemacht.
ich habe vor jeden würfel eine checkbox gemacht.
Bei einem buttonclick wird jeder würfel neu gewürfelt und halt je nach gewürfelter Zahl in die Variable des Würfels eingetragen, AUßER
die CheckBox vor dem Würfel ist aktiviert, dann bleibt der würfel liegen, was natürlich so sein soll als ob man sich beim kniffel die würfel
die man liegen lassen will zur seite legt.

dann soll das programm immer wieder abfragen was schon da liegt was es gebrauchen könnte d.h. wenn ich drei 6er habe, ob ich sie nun als 3er pasch oder eben als drei 6er werten will. dafür sollen dann jeweils für jede methode die man machen kann buttons erscheinen.
aber genau da liegt das problem. ich weise bei knopfdruck jeder variable (in meinem fall w1,w2,w3,w4,w5 für jeden würfel) eine zahl zu.
wie erkennt das programm, das 3 von diesen werten die zahl 6 ist, denn erst wenn halt mindestens 3 würfel die zahl 6 haben, soll ein button mit der aufschrift "dreierpasch" oder "drei 6er" erscheinen.
muss ich dann irgendwie die zahlen, die den variablen zugewiesen wurden in einem pool machen und dann abfragen "for each 6 in the pool begin" oder wie?

ich hoffe ihr versteht mein problem und könnt euch kurz für mich zeit nehmen.
MfG Philip
  Mit Zitat antworten Zitat
Benutzerbild von Wolfgang Mix
Wolfgang Mix

Registriert seit: 13. Mai 2009
Ort: Lübeck
1.222 Beiträge
 
Delphi 2005 Personal
 
#2

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 19:15
Erst einmal herzlich willkommen in der DP
Ich glaube, es kommen keine Antworten, weil dein
Vorhaben den meisten nicht ganz klar ist.
Zeige einmal ein bisschen Code und die Stelle,
wo es hängt. Dann wird sicher weiter geholfen.
Wolfgang Mix
if you can't explain it simply you don't understand it well enough - A. Einstein
Mein Baby:http://www.epubli.de/shop/buch/Grund...41818516/52824
  Mit Zitat antworten Zitat
pheel

Registriert seit: 26. Mai 2010
Ort: Frankfurt a.M.
4 Beiträge
 
Delphi 6 Personal
 
#3

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 19:49
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image30: TImage;
    BtWurf: TButton;
    procedure BtWurfClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  w1,w2,w3,w4,w5,w6: integer;
implementation

{$R *.dfm}

procedure TForm1.BtWurfClick(Sender: TObject);
begin

randomize;
if CheckBox1.Checked = false then //ich frage ab welcher würfel gewürfelt wird
 begin
  Image1.Visible:=false;
  Image2.Visible:=false;
  Image3.Visible:=false;
  Image4.Visible:=false;
  Image5.Visible:=false;
  Image6.Visible:=false;
  w1:=random(6)+1;
 end;
if CheckBox2.Checked = false then
 begin
  Image7.Visible:=false;
  Image8.Visible:=false;
  Image9.Visible:=false;
  Image10.Visible:=false;
  Image11.Visible:=false;
  Image12.Visible:=false;
  w2:=random(6)+1;
 end;
if CheckBox3.Checked = false then
 begin
  Image13.Visible:=false;
  Image14.Visible:=false;
  Image15.Visible:=false;
  Image16.Visible:=false;
  Image17.Visible:=false;
  Image18.Visible:=false;
  w3:=random(6)+1;
 end;
if CheckBox4.Checked = false then
 begin
  Image19.Visible:=false;
  Image20.Visible:=false;
  Image21.Visible:=false;
  Image22.Visible:=false;
  Image23.Visible:=false;
  Image24.Visible:=false;
  w4:=random(6)+1;
 end;
if CheckBox5.Checked = false then
 begin
  Image25.Visible:=false;
  Image26.Visible:=false;
  Image27.Visible:=false;
  Image28.Visible:=false;
  Image29.Visible:=false;
  Image30.Visible:=false;
  w5:=random(6)+1;
 end;

if w1 = 1 then //fragt ab und zeigt die bilder
 Image1.Visible:=true;
if w1 = 2 then
 Image2.Visible:=true;
if w1 = 3 then
 Image3.Visible:=true;
if w1 = 4 then
 Image4.Visible:=true;
if w1 = 5 then
 Image5.Visible:=true;
if w1 = 6 then
 Image6.Visible:=true;

if w2 = 1 then
 Image7.Visible:=true;
if w2 = 2 then
 Image8.Visible:=true;
if w2 = 3 then
 Image9.Visible:=true;
if w2 = 4 then
 Image10.Visible:=true;
if w2 = 5 then
 Image11.Visible:=true;
if w2 = 6 then
 Image12.Visible:=true;

if w3 = 1 then
 Image13.Visible:=true;
if w3 = 2 then
 Image14.Visible:=true;
if w3 = 3 then
 Image15.Visible:=true;
if w3 = 4 then
 Image16.Visible:=true;
if w3 = 5 then
 Image17.Visible:=true;
if w3 = 6 then
 Image18.Visible:=true;

if w4 = 1 then
 Image19.Visible:=true;
if w4 = 2 then
 Image20.Visible:=true;
if w4 = 3 then
 Image21.Visible:=true;
if w4 = 4 then
 Image22.Visible:=true;
if w4 = 5 then
 Image23.Visible:=true;
if w4 = 6 then
 Image24.Visible:=true;

if w5 = 1 then
 Image25.Visible:=true;
if w5 = 2 then
 Image26.Visible:=true;
if w5 = 3 then
 Image27.Visible:=true;
if w5 = 4 then
 Image28.Visible:=true;
if w5 = 5 then
 Image29.Visible:=true;
if w5 = 6 then
 Image30.Visible:=true;
end;

end.
so soviel hab ich und jetzt möchte ich, dass das programm erkennt wieviele 6er oder 3er oder 4er ich "gewürfelt" habe.
image1 bis image30 sind bilder zu den würfeln. also die gewürfelte zahl als bild eines würfels^^
  Mit Zitat antworten Zitat
Tron4U
(Gast)

n/a Beiträge
 
#4

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:03
hi,

warum hast 30 images es gibt doch nur 6 mögliche würfelaugen?

an sonsten wirds einfacher wenn du die würfel in ein array legst:

var w: array[1..6] of byte;

würfeln würde dann z.b. so gehn:

for i:=1 to 6 do w[i]:=random(6)+1;

secher zählen dann so:

sechser:=0;
for i:=1 to 6 do if w[i]:=6 then inc(sechser);

...

hilft dir das ?
  Mit Zitat antworten Zitat
-Phantom-

Registriert seit: 26. Nov 2009
Ort: Bockhorst
319 Beiträge
 
Delphi 7 Enterprise
 
#5

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:06
Wenn ich das richtig verstanden habe suchst du vielleicht "and" ?
Delphi-Quellcode:
If (w1=6) and (w2=6) then
{show pic}
Mathias Jansen
  Mit Zitat antworten Zitat
Klaus01
Online

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#6

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:06
Guten Abend,

ich würde Dir ein Array vorschlagen welches die Anzahl der 1er-6er aufnimmt.

Delphi-Quellcode:
var
  augen: Array[1..6] of Byte;

...

 inc(augen[w1]); // erhöht den Wert im Augen Array des wurfes von Würfel_1 um 1
Wenn eine 3 gewürfelt wird, wird die Position 3 des Arrays um 1 erhöht.

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Benutzerbild von Wolfgang Mix
Wolfgang Mix

Registriert seit: 13. Mai 2009
Ort: Lübeck
1.222 Beiträge
 
Delphi 2005 Personal
 
#7

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:11
Ausserdem:

Delphi-Quellcode:
if w1 = 1 then //fragt ab und zeigt die bilder
Image1.Visible:=true;
if w1 = 2 then
Image2.Visible:=true;
if w1 = 3 then
Image3.Visible:=true;
if w1 = 4 then
Image4.Visible:=true;
if w1 = 5 then
Image5.Visible:=true;
if w1 = 6 then
Image6.Visible:=true;
wird übersichtlicher mit

Delphi-Quellcode:
case w1 of
  1: Image1.Visible:=true;
  2: Image2.Visible:=true;
  ...
end;
Wolfgang Mix
if you can't explain it simply you don't understand it well enough - A. Einstein
Mein Baby:http://www.epubli.de/shop/buch/Grund...41818516/52824
  Mit Zitat antworten Zitat
Noedel

Registriert seit: 7. Aug 2008
204 Beiträge
 
Delphi 7 Professional
 
#8

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:19
Zitat von Wolfgang Mix:
Ausserdem:

Delphi-Quellcode:
if w1 = 1 then //fragt ab und zeigt die bilder
Image1.Visible:=true;
if w1 = 2 then
Image2.Visible:=true;
if w1 = 3 then
Image3.Visible:=true;
if w1 = 4 then
Image4.Visible:=true;
if w1 = 5 then
Image5.Visible:=true;
if w1 = 6 then
Image6.Visible:=true;
wird übersichtlicher mit

Delphi-Quellcode:
case w1 of
  1: Image1.Visible:=true;
  2: Image2.Visible:=true;
  ...
end;
Dann können wir auch gleich
TImage(FindComponent('Image'+IntToStr(w1))).Visible:=true nehmen
-"Was studierst du eigentlich? Nerdologie?"
-"Informatik..."
-"Wusst ich´s doch!"
  Mit Zitat antworten Zitat
Benutzerbild von Wolfgang Mix
Wolfgang Mix

Registriert seit: 13. Mai 2009
Ort: Lübeck
1.222 Beiträge
 
Delphi 2005 Personal
 
#9

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:22
Okay, aber eher nicht für Einsteiger
Wolfgang Mix
if you can't explain it simply you don't understand it well enough - A. Einstein
Mein Baby:http://www.epubli.de/shop/buch/Grund...41818516/52824
  Mit Zitat antworten Zitat
Noedel

Registriert seit: 7. Aug 2008
204 Beiträge
 
Delphi 7 Professional
 
#10

Re: kniffel - zahlenabfrage

  Alt 26. Mai 2010, 20:36
Gut, dann kann er sich das "FindComponent" aber schon einmal vormerken. Für´s Erste wird ja die "Case"-Abfrage reichen.
-"Was studierst du eigentlich? Nerdologie?"
-"Informatik..."
-"Wusst ich´s doch!"
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:49 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