![]() |
Slotmaschine in Delphi - Bitte um Hilfsstellung
Zurzeit arbeite ich an einer Slotmaschine wie eine, die man so aus den Casinos kennt. Sie ist noch relativ simpel gehalten und ich mache das ganze nur zu Lernzwecken.
Hier mal der aktuelle SCR Code :
Delphi-Quellcode:
Ich hab jetzt ein paar Fragen worauf ich noch keine gute Erklärung gefunden habe :
unit Unit1;
{$mode objfpc}{$H+} interface uses Classes, SysUtils, Windows, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Menus, ActnList, Spin, FileCtrl; type { TForm1 } TForm1 = class(TForm) FloatSpinEdit1: TFloatSpinEdit; Guthabenlb: TLabel; s4: TLabel; s5: TLabel; s6: TLabel; s7: TLabel; s8: TLabel; s9: TLabel; Timer3: TTimer; Winlb: TLabel; Loselb: TLabel; slotbn: TButton; s1: TLabel; s2: TLabel; s3: TLabel; Timer1: TTimer; Timer2: TTimer; procedure FormCreate(Sender: TObject); procedure slotbnClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure Timer3Timer(Sender: TObject); private { private declarations } FRollen : array [0..2, 0..9] of String; public { public declarations } end; var Form1: TForm1; wins,loses : Integer; guthaben : Double = 10; implementation {$R *.lfm} { TForm1 } procedure TForm1.slotbnClick(Sender: TObject); begin Guthaben := Guthaben - 1.00; Guthabenlb.Caption := FloatToStr(guthaben) + (' €'); Timer1.Enabled := True; Timer2.Enabled := True; slotbn.Enabled := false; end; procedure TForm1.FormCreate(Sender: TObject); var i: integer; j: integer; n: integer; digits: TStringlist; begin Digits := TStringList.Create; try for i := low(FRollen) to high(FRollen) do begin for j := low(FRollen[i]) to high(FRollen[i]) do Digits.Add(IntToStr(j)); for j := low(FRollen[i]) to high(FRollen[i]) do begin n := Random(Digits.Count); FRollen[i, j] := Digits[n]; Digits.Delete(n); end; end finally Digits.Free; end; for i:=low(FRollen) to high(FRollen) do begin end; end; //==================================================================================================\\ // Drehen der Slots im Zufallsmodus //==================================================================================================// procedure TForm1.Timer1Timer(Sender: TObject); begin s1.Caption := IntToStr(Random(9)); s2.Caption := IntToStr(Random(9)); s3.Caption := IntToStr(Random(9)); s4.Caption := IntToStr(Random(9)); s5.Caption := IntToStr(Random(9)); s6.Caption := IntToStr(Random(9)); s7.Caption := IntToStr(Random(9)); s8.Caption := IntToStr(Random(9)); s9.Caption := IntToStr(Random(9)); end; //==================================================================================================// //===================================================================================================\\ // Gewonnen / Verloren abfrage //===================================================================================================// procedure TForm1.Timer2Timer(Sender: TObject); begin Timer1.Enabled := False; Timer2.Enabled := false; if (s1.Caption = s5.Caption) and (s1.Caption = s9.Caption) then begin Guthaben := Guthaben + 5.00; Inc(wins); end else if (s1.Caption = s4.Caption) and (s1.Caption = s7.Caption) then begin Guthaben := Guthaben + 5.00; Inc(wins); end else if (s2.Caption = s5.Caption) and (s2.Caption = s8.Caption) then begin Guthaben := Guthaben + 5.00; Inc(wins); end else if (s3.Caption = s6.Caption) and (s3.Caption = s9.Caption) then begin Guthaben := Guthaben + 5.00; Inc(wins); end else if (s3.Caption = s5.Caption) and (s3.Caption = s7.Caption) then begin Guthaben := Guthaben + 5.00; Inc(wins); end else Inc(loses); slotbn.Enabled := True; Loselb.Caption := 'Loses: ' + IntToStr(loses); Winlb.Caption := 'Wins: ' + IntTostr(Wins); end; procedure TForm1.Timer3Timer(Sender: TObject); begin if (guthaben = 0) or (guthaben < 0) then begin Timer3.Enabled := False; MessageBox(handle,'Du hast verloren!','Verlierer!',MB_OK); close(); end; end; //======================================================================================================\\ end. Wie kann ich die Labels durch Icons ersetzen( Also, dass man dann z.B 3 Kronen hat) Wie kann ich die Gewinne spezifisch den Symbolen anpassen? (3 Äpfel z.B nur 4 €, 3 7er dann 400 ) Wie kann ich den Einsatz erhöhen und dadurch die Gewinne verringern/erhöhen. |
AW: Slotmaschine in Delphi - Bitte um Hilfsstellung
Du würdest Dich leichter tun, wenn Du Logik und Darstellung trennen würdest. D.h. die gesamte Logik kommt in eine eigene Klasse, wie Du das dann darstellst, steht Dir völlig frei.
|
AW: Slotmaschine in Delphi - Bitte um Hilfsstellung
Zitat:
|
AW: Slotmaschine in Delphi - Bitte um Hilfsstellung
Und damit zurück zu meiner Antwort. Das ist die einzig saubere Lösung, sonst bekommst Du später nur noch mehr Probleme, glaub mir das einfach mal.
|
AW: Slotmaschine in Delphi - Bitte um Hilfsstellung
Hach, das erinnert mich an meine Anfangszeit... :love: eins meiner ersten Anfängerprojekte mit 9 Jahren oder so war auch eine primitive Slot-Machine. Ich habe damals gefärbte Panels an Stelle von Symbolen verwendet.
Wenn du Symbole verwenden willst, kannst du dir mal TImage anschauen. Du kannst für jedee „Rolle“ mehrere solcher Images übereinanderlegen und sie nach Bedarf mit
Delphi-Quellcode:
aus- und einblenden. Den Status der einzelnen „Rollen“ musst du natürlich gesondert in Variablen abspeichern (Logik ↔ Darstellung), momentan speicherst du den Zustand ja direkt in den Captions der Labels.
Image.Visible := False/True
Natürlich ist es nicht die sauberste Lösung, mehrere Images übereinanderzulegen, aber für den Anfang sollte es reichen. Es ist auch eher unwahrscheinlich, dass er sich später überlegt, dass er doch lieber eine Slot-Machine mit 100 Rollen haben will, von daher sollte es da auch keine Probleme geben... ;). Und sooo komplex ist so ein Programm ja auch nicht, dass man den Teil nicht relativ schnell neu schreiben kann, wenn man mit der Lösung unzufrieden ist. |
AW: Slotmaschine in Delphi - Bitte um Hilfsstellung
Liste der Anhänge anzeigen (Anzahl: 2)
@Robin2k
Da du ja XE2 im Einsatz hast, bieten sich dafür natürlich die ![]() Im Anhang hast du ein kleine Projekt mit so eine Mini-Slot-Maschine, wo zum Einen der Code und die Anzeige getrennt ist, und zum Anderen die Verwendung der LiveBindings gezeigt wird. (Source und exe im Anhang) (BTW. mein 3000ter Beitrag :) ) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz