Thema: Delphi Galgenmännchen

Einzelnen Beitrag anzeigen

Tomislav

Registriert seit: 1. Dez 2005
34 Beiträge
 
#29

Re: Galgenmännchen

  Alt 1. Dez 2005, 20:37
Delphi-Quellcode:
procedure TForm1.btnWortwahlClick(Sender: TObject);
var Woerterliste: TStringlist;
var Wort, A, B, C, D, E, F, G, H, I, J, K, L: String;

begin
  Woerterliste := TStringList.Create;
  try
  Woerterliste.LoadFromFile('Woerter.txt');
  Wort := Woerterliste[Random(Woerterliste.Count{ + 1 - 1})];
  finally
  Woerterliste.Free;
  A := Wort[1];
  B := Wort[2];
  C := Wort[3];
  D := Wort[4];
  E := Wort[5];
  F := Wort[6];
  G := Wort[7];
  H := Wort[8];
  I := Wort[9];
  J := Wort[10];
  K := Wort[11];
  L := Wort[12];


  GBWort.Visible := true;
end;
end;
ok so muss es aussehen.

Ich habe für alles eine Lösung nur für die 2 Spieler nicht!!!
Könnte man das mit einer Procedur/Spieler machen?

der jetztige code sieht so aus

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    N1: TMenuItem;
    Beenden1: TMenuItem;
    Neu1: TMenuItem;
    lblSpieler1: TLabel;
    edtNameS1: TEdit;
    lblSpieler2: TLabel;
    edtNameS2: TEdit;
    btnStart: TButton;
    lblName1: TLabel;
    lblName2: TLabel;
    PBP1: TPaintBox;
    PBP2: TPaintBox;
    btnWortwahl: TButton;
    GBBuchstaben: TGroupBox;
    btnF: TButton;
    btnE: TButton;
    btnB: TButton;
    btnG: TButton;
    btnA: TButton;
    btnC: TButton;
    btnD: TButton;
    btnM: TButton;
    btnL: TButton;
    btnK: TButton;
    btnJ: TButton;
    btnI: TButton;
    btnH: TButton;
    btnS: TButton;
    btnR: TButton;
    btnO: TButton;
    btnT: TButton;
    btnN: TButton;
    btnP: TButton;
    btnQ: TButton;
    btnV: TButton;
    btnW: TButton;
    btnX: TButton;
    btnY: TButton;
    btnZ: TButton;
    btnU: TButton;
    GBWort: TGroupBox;
    lblString1: TLabel;
    lblString2: TLabel;
    lblString3: TLabel;
    lblString4: TLabel;
    lblString6: TLabel;
    lblString5: TLabel;
    lblString7: TLabel;
    lblString8: TLabel;
    lblString9: TLabel;
    lblString10: TLabel;
    lblString11: TLabel;
    lblString12: TLabel;
    procedure btnStartClick(Sender: TObject);
    procedure Beenden1Click(Sender: TObject);
    procedure Neu1Click(Sender: TObject);
    procedure FormOnKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnAClick(Sender: TObject);
    procedure btnBClick(Sender: TObject);
    procedure btnCClick(Sender: TObject);
    procedure btnDClick(Sender: TObject);
    procedure btnEClick(Sender: TObject);
    procedure btnFClick(Sender: TObject);
    procedure btnGClick(Sender: TObject);
    procedure btnHClick(Sender: TObject);
    procedure btnIClick(Sender: TObject);
    procedure btnJClick(Sender: TObject);
    procedure btnKClick(Sender: TObject);
    procedure btnLClick(Sender: TObject);
    procedure btnMClick(Sender: TObject);
    procedure btnNClick(Sender: TObject);
    procedure btnOClick(Sender: TObject);
    procedure btnPClick(Sender: TObject);
    procedure btnQClick(Sender: TObject);
    procedure btnRClick(Sender: TObject);
    procedure btnSClick(Sender: TObject);
    procedure btnTClick(Sender: TObject);
    procedure btnUClick(Sender: TObject);
    procedure btnVClick(Sender: TObject);
    procedure btnWClick(Sender: TObject);
    procedure btnXClick(Sender: TObject);
    procedure btnYClick(Sender: TObject);
    procedure btnZClick(Sender: TObject);
    procedure btnWortwahlClick(Sender: TObject);
    procedure Kontrolle(Sender: TObject);
  private

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

  var S1, S2:String;
  var x, y: TPoint;
  var Wort, Antwort, Loesung, A, B, C, D, E, F, G, H, I, J, K, L: String;

procedure TForm1.btnStartClick(Sender: TObject);
begin
 S1 := String(edtNameS1.Text);
 S2 := String(edtNameS2.Text);
 if
 (S1 = 'Name') or (S2 = 'Name')
 then
 Application.MessageBox('Bitte geben Sie einen Namen ein!!!','Warnung!')
 else
 begin
 PBP1.Visible := true;
 PBP2.Visible := true;
 edtNameS1.Visible := false;
 edtNameS2.Visible := false;
 lblSpieler1.Visible := false;
 lblSpieler2.Visible := false;
 btnStart.Visible := false;
 lblName1.Visible := true;
 lblName2.Visible := true;
 lblName1.Caption := String(S1);
 lblName2.Caption := String(S2);
 lblName1.Alignment := taCenter;
 lblName2.Alignment := taCenter;
 lblName1.Width := 88;
 lblName2.Width := 88;
 btnWortwahl.Visible := true;
 GBBuchstaben.Visible := true;
 btnA.Visible := true;
 btnB.Visible := true;
 btnC.Visible := true;
 btnD.Visible := true;
 btnE.Visible := true;
 btnF.Visible := true;
 btnG.Visible := true;
 btnH.Visible := true;
 btnI.Visible := true;
 btnJ.Visible := true;
 btnK.Visible := true;
 btnL.Visible := true;
 btnM.Visible := true;
 btnN.Visible := true;
 btnO.Visible := true;
 btnP.Visible := true;
 btnQ.Visible := true;
 btnR.Visible := true;
 btnS.Visible := true;
 btnT.Visible := true;
 btnU.Visible := true;
 btnV.Visible := true;
 btnW.Visible := true;
 btnX.Visible := true;
 btnY.Visible := true;
 btnZ.Visible := true;
 PBP1.Canvas.Rectangle (0,0,PBP1.height,PBP1.width);
   with PBP1 do
   begin
    x.x := 5;
    x.y := height-5;
    y.x := width-5;
    y.y := x.y;
    canvas.moveto(x.x, x.y);
    canvas.lineto(y.x, y.y);
   end;
 PBP2.Canvas.Rectangle (0,0,PBP2.height,PBP2.width);
   with PBP2 do
   begin
    x.x := 5;
    x.y := height-5;
    y.x := width-5;
    y.y := x.y;
    canvas.moveto(x.x, x.y);
    canvas.lineto(y.x, y.y);
   end;
 end;
end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
 Form1.Close;
end;

procedure TForm1.Neu1Click(Sender: TObject);
begin
 edtNameS1.Visible := true;
 edtNameS2.Visible := true;
 edtNameS1.Text := 'Name';
 edtNameS2.Text := 'Name';
 lblSpieler1.Visible := true;
 lblSpieler2.Visible := true;
 btnStart.Visible := true;
 lblName1.Visible := false;
 lblName2.Visible := false;
 PBP1.Visible := false;
 PBP2.Visible := false;
 btnWortwahl.Visible := false;
 GBBuchstaben.Visible := false;
 GBWort.Visible := false;

end;

procedure TForm1.FormOnKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if chr(Key) = 'Athen btnAClick(Sender);
if chr(Key) = 'Bthen btnBClick(Sender);
if chr(Key) = 'Cthen btnCClick(Sender);
if chr(Key) = 'Dthen btnDClick(Sender);
if chr(Key) = 'Ethen btnEClick(Sender);
if chr(Key) = 'Fthen btnFClick(Sender);
if chr(Key) = 'Gthen btnGClick(Sender);
if chr(Key) = 'Hthen btnHClick(Sender);
if chr(Key) = 'Ithen btnIClick(Sender);
if chr(Key) = 'Jthen btnJClick(Sender);
if chr(Key) = 'Kthen btnKClick(Sender);
if chr(Key) = 'Lthen btnLClick(Sender);
if chr(Key) = 'Mthen btnMClick(Sender);
if chr(Key) = 'Nthen btnNClick(Sender);
if chr(Key) = 'Othen btnOClick(Sender);
if chr(Key) = 'Pthen btnPClick(Sender);
if chr(Key) = 'Qthen btnQClick(Sender);
if chr(Key) = 'Rthen btnRClick(Sender);
if chr(Key) = 'Sthen btnSClick(Sender);
if chr(Key) = 'Tthen btnTClick(Sender);
if chr(Key) = 'Uthen btnUClick(Sender);
if chr(Key) = 'Vthen btnVClick(Sender);
if chr(Key) = 'Wthen btnWClick(Sender);
if chr(Key) = 'Xthen btnXClick(Sender);
if chr(Key) = 'Ythen btnYClick(Sender);
if chr(Key) = 'Zthen btnZClick(Sender);
end;

procedure TForm1.btnAClick(Sender: TObject);
begin
 btnA.Visible := false;
 Antwort := 'A';
 Loesung := 'A';
 Kontrolle(Sender);
end;

procedure TForm1.btnBClick(Sender: TObject);
begin
 btnB.Visible := false;
 Antwort := 'B';
 Loesung := 'B';
 Kontrolle(Sender);
end;

procedure TForm1.btnCClick(Sender: TObject);
begin
 btnC.Visible := false;
 Antwort := 'C';
 Loesung := 'C';
 Kontrolle(Sender);
end;

procedure TForm1.btnDClick(Sender: TObject);
begin
 btnD.Visible := false;
 Antwort := 'D';
 Loesung := 'D';
 Kontrolle(Sender);
end;

procedure TForm1.btnEClick(Sender: TObject);
begin
 btnE.Visible := false;
 Antwort := 'E';
 Loesung := 'E';
 Kontrolle(Sender);
end;

procedure TForm1.btnFClick(Sender: TObject);
begin
 btnF.Visible := false;
 Antwort := 'F';
 Loesung := 'F';
 Kontrolle(Sender);
end;

procedure TForm1.btnGClick(Sender: TObject);
begin
 btnG.Visible := false;
 Antwort := 'G';
 Loesung := 'G';
 Kontrolle(Sender);
end;

procedure TForm1.btnHClick(Sender: TObject);
begin
 btnH.Visible := false;
 Antwort := 'H';
 Loesung := 'H';
 Kontrolle(Sender);
end;

procedure TForm1.btnIClick(Sender: TObject);
begin
 btnI.Visible := false;
 Antwort := 'I';
 Loesung := 'I';
 Kontrolle(Sender);
end;

procedure TForm1.btnJClick(Sender: TObject);
begin
 btnJ.Visible := false;
 Antwort := 'J';
 Loesung := 'J';
 Kontrolle(Sender);
end;

procedure TForm1.btnKClick(Sender: TObject);
begin
 btnK.Visible := false;
 Antwort := 'K';
 Loesung := 'K';
 Kontrolle(Sender);
end;

procedure TForm1.btnLClick(Sender: TObject);
begin
 btnL.Visible := false;
 Antwort := 'L';
 Loesung := 'L';
 Kontrolle(Sender);
end;

procedure TForm1.btnMClick(Sender: TObject);
begin
 btnM.Visible := false;
 Antwort := 'M';
 Loesung := 'M';
 Kontrolle(Sender);
end;

procedure TForm1.btnNClick(Sender: TObject);
begin
 btnN.Visible := false;
 Antwort := 'N';
 Loesung := 'N';
 Kontrolle(Sender);
end;

procedure TForm1.btnOClick(Sender: TObject);
begin
 btnO.Visible := false;
 Antwort := 'O';
 Loesung := 'O';
 Kontrolle(Sender);
end;

procedure TForm1.btnPClick(Sender: TObject);
begin
 btnP.Visible := false;
 Antwort := 'P';
 Loesung := 'P';
 Kontrolle(Sender);
end;

procedure TForm1.btnQClick(Sender: TObject);
begin
 btnQ.Visible := false;
 Antwort := 'Q';
 Loesung := 'Q';
 Kontrolle(Sender);
end;

procedure TForm1.btnRClick(Sender: TObject);
begin
 btnR.Visible := false;
 Antwort := 'R';
 Loesung := 'R';
 Kontrolle(Sender);
end;

procedure TForm1.btnSClick(Sender: TObject);
begin
 btnS.Visible := false;
 Antwort := 'S';
 Loesung := 'S';
 Kontrolle(Sender);
end;

procedure TForm1.btnTClick(Sender: TObject);
begin
 btnT.Visible := false;
 Antwort := 'T';
 Loesung := 'T';
 Kontrolle(Sender);
end;

procedure TForm1.btnUClick(Sender: TObject);
begin
 btnU.Visible := false;
 Antwort := 'U';
 Loesung := 'U';
 Kontrolle(Sender);
end;

procedure TForm1.btnVClick(Sender: TObject);
begin
 btnV.Visible := false;
 Antwort := 'V';
 Loesung := 'V';
 Kontrolle(Sender);
end;

procedure TForm1.btnWClick(Sender: TObject);
begin
 btnW.Visible := false;
 Antwort := 'W';
 Loesung := 'W';
 Kontrolle(Sender);
end;

procedure TForm1.btnXClick(Sender: TObject);
begin
 btnX.Visible := false;
 Antwort := 'X';
 Loesung := 'X';
 Kontrolle(Sender);
end;

procedure TForm1.btnYClick(Sender: TObject);
begin
 btnY.Visible := false;
 Antwort := 'Y';
 Loesung := 'Y';
 Kontrolle(Sender);
end;

procedure TForm1.btnZClick(Sender: TObject);
begin
 btnZ.Visible := false;
 Antwort := 'Z';
 Loesung := 'Z';
 Kontrolle(Sender);
end;

procedure TForm1.btnWortwahlClick(Sender: TObject);
 var Woerterliste: TStringlist;
begin
  Woerterliste := TStringList.Create;
  try
  Woerterliste.LoadFromFile('Woerter.txt');
  Wort := Woerterliste[Random(Woerterliste.Count{ + 1 - 1})];
  finally
  Woerterliste.Free;
  A := Wort[1];
  B := Wort[2];
  C := Wort[3];
  D := Wort[4];
  E := Wort[5];
  F := Wort[6];
  G := Wort[7];
  H := Wort[8];
  I := Wort[9];
  J := Wort[10];
  K := Wort[11];
  L := Wort[12];

  if
  (A = ' ')
  then
  lblString1.Caption := ' '
  else
  lblString1.Caption := '_';

  if
  (B = ' ')
  then
  lblString2.Caption := ' '
  else
  lblString2.Caption := '_';

  if
  (C = ' ')
  then
  lblString3.Caption := ' '
  else
  lblString3.Caption := '_';

  if
  (D = ' ')
  then
  lblString4.Caption := ' '
  else
  lblString4.Caption := '_';

  if
  (E = ' ')
  then
  lblString5.Caption := ' '
  else
  lblString5.Caption := '_';

  if
  (F = ' ')
  then
  lblString6.Caption := ' '
  else
  lblString6.Caption := '_';

  if
  (G = ' ')
  then
  lblString7.Caption := ' '
  else
  lblString7.Caption := '_';

  if
  (H = ' ')
  then
  lblString8.Caption := ' '
  else
  lblString8.Caption := '_';

  if
  (I = ' ')
  then
  lblString9.Caption := ' '
  else
  lblString9.Caption := '_';

  if
  (J = ' ')
  then
  lblString10.Caption := ' '
  else
  lblString10.Caption := '_';

  if
  (K = ' ')
  then
  lblString11.Caption := ' '
  else
  lblString11.Caption := '_';

  if
  (L = ' ')
  then
  lblString12.Caption := ' '
  else
  lblString12.Caption := '_';


  GBWort.Visible := true;
  btnA.Visible := true;
  btnB.Visible := true;
  btnC.Visible := true;
  btnD.Visible := true;
  btnE.Visible := true;
  btnF.Visible := true;
  btnG.Visible := true;
  btnH.Visible := true;
  btnI.Visible := true;
  btnJ.Visible := true;
  btnK.Visible := true;
  btnL.Visible := true;
  btnM.Visible := true;
  btnN.Visible := true;
  btnO.Visible := true;
  btnP.Visible := true;
  btnQ.Visible := true;
  btnR.Visible := true;
  btnS.Visible := true;
  btnT.Visible := true;
  btnU.Visible := true;
  btnV.Visible := true;
  btnW.Visible := true;
  btnX.Visible := true;
  btnY.Visible := true;
  btnZ.Visible := true;
end;
end;

procedure TForm1.Kontrolle(Sender: TObject);
begin
 if
 (Antwort = A)
 then
 lblString1.Caption := Loesung;

  if
 (Antwort = B)
 then
 lblString2.Caption := Loesung;

  if
 (Antwort = C)
 then
 lblString3.Caption := Loesung;

  if
 (Antwort = D)
 then
 lblString4.Caption := Loesung;

  if
 (Antwort = E)
 then
 lblString5.Caption := Loesung;

  if
 (Antwort = F)
 then
 lblString6.Caption := Loesung;

  if
 (Antwort = G)
 then
 lblString7.Caption := Loesung;

  if
 (Antwort = H)
 then
 lblString8.Caption := Loesung;

  if
 (Antwort = I)
 then
 lblString9.Caption := Loesung;

  if
 (Antwort = J)
 then
 lblString10.Caption := Loesung;

  if
 (Antwort = K)
 then
 lblString11.Caption := Loesung;

  if
 (Antwort = L)
 then
 lblString12.Caption := Loesung;
end;


end.
  Mit Zitat antworten Zitat