Einzelnen Beitrag anzeigen

Blutfeuernacht

Registriert seit: 20. Mär 2015
2 Beiträge
 
#1

Spieleprogrammierung Hilfe benötigt

  Alt 20. Mär 2015, 11:00
Ich möchte eine Spielesammlung mit Tic Tac Toe und Schere, Stein, Papier erstellen, aber bei mir einige Fehler angezeigt und da ich noch ein ziemlicher Laie bin, weiß ich nicht, woran es liegt... Danke schon mal im Voraus!

Delphi-Quellcode:
unit U_p;

interface

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

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    NeuesSpiel1: TMenuItem;
    Schlieen1: TMenuItem;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Spiele1: TMenuItem;
    Galgenmnnchen1: TMenuItem;
    icTacToe1: TMenuItem;
    Viergewinnt1: TMenuItem;
    SchereSteinPapiewahdf1: TMenuItem;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    procedure icTacToe1Click(Sender: TObject);
    procedure Schlieen1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure TForm1.Druecken(Sender: TObject);
    procedure SchereSteinPapiewahdf1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  spieler: integer;
  tic: integer;

implementation

{$R *.dfm}

procedure TForm1.Druecken(tic:Double);
begin
 tic:=tic+1;
 if tic=3 then tic:=0;
end;

procedure TForm1.icTacToe1Click(Sender: TObject);
begin
  ShowMessage('Spieler 1 fängt an');
  spieler:=1;

  Button1.Visible:=true;
  Button2.Visible:=true;
  Button3.Visible:=true;
  Button4.Visible:=true;
  Button5.Visible:=true;
  Button6.Visible:=true;
  Button7.Visible:=true;
  Button8.Visible:=true;
  Button9.Visible:=true;


  With Canvas do begin
      Pen.Color:=clBlack;
      Pen.Width:=5;
      MoveTo(200,0);
      LineTo(200,600);
      MoveTo(400,0);
      LineTo(400,600);
      MoveTo(0,200);
      LineTo(600,200);
      MoveTo(0,400);
      LineTo(600,400);
                 end;

end;

procedure TForm1.Schlieen1Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Visible:=false;
Button2.Visible:=false;
Button3.Visible:=false;
Button4.Visible:=false;
Button5.Visible:=false;
Button6.Visible:=false;
Button7.Visible:=false;
Button8.Visible:=false;
Button9.Visible:=false;
Image1.Visible:=false;
Image2.Visible:=false;
Image3.Visible:=false;
Image4.Visible:=false;
Image5.Visible:=false;
Image6.Visible:=false;
RadioButton1.Visible:=false;
RadioButton2.Visible:=false;
RadioButton3.Visible:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Druecken(spieler);
 If spieler=1
     then begin
            (Button1.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(10,10);
                                                  LineTo(190,190);
                                                  MoveTo(10,190);
                                                  LineTo(190,10);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button1.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(10,10,190,190);
                                                 End;

          end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button2.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(10,210);
                                                  LineTo(190,390);
                                                  MoveTo(10,390);
                                                  LineTo(190,210);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button2.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(10,210,190,390);
                                                 End;

          end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Druecken(spieler);
 If spieler=1
     then begin
            spieler:=2;
            (Button3.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(10,410);
                                                  LineTo(190,590);
                                                  MoveTo(10,590);
                                                  LineTo(190,410);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button3.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(10,410,190,590);
                                                 End;

          end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Druecken(spieler);
  If spieler=1
     then begin
            spieler:=2;
            (Button4.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(210,10);
                                                  LineTo(390,190);
                                                  MoveTo(390,10);
                                                  LineTo(210,190);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button4.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(210,10,390,190);
                                                 End;

          end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button5.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(210,210);
                                                  LineTo(390,390);
                                                  MoveTo(210,390);
                                                  LineTo(390,210);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button5.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(210,210,390,390);
                                                 End;

          end;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button6.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(210,410);
                                                  LineTo(390,590);
                                                  MoveTo(210,590);
                                                  LineTo(390,410);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button6.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(210,410,390,590);
                                                 End;

          end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button7.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(410,10);
                                                  LineTo(590,190);
                                                  MoveTo(590,10);
                                                  LineTo(410,190);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button7.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(410,10,590,190);
                                                 End;

          end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button8.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(410,210);
                                                  LineTo(590,390);
                                                  MoveTo(410,390);
                                                  LineTo(590,210);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button8.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(410,210,590,390);
                                                 End;

          end;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
Druecken(spieler);
If spieler=1
     then begin
            spieler:=2;
            (Button9.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clBlack;
                                                  Pen.Width:=7;
                                                  MoveTo(410,410);
                                                  LineTo(590,590);
                                                  MoveTo(410,590);
                                                  LineTo(590,410);
                                                 End;
          end
  Else
  If spieler=2
     then begin
            (Button9.Visible:=false);
                               With Canvas Do Begin
                                                  Pen.Color:=clPurple;
                                                  Pen.Width:=7;
                                                  Ellipse(410,410,590,590);
                                                 End;

          end;
end;

procedure TForm1.SchereSteinPapiewahdf1Click(Sender: TObject);
Const
nachricht:array[1..3] of string=('Unentschieden.','Spieler hat gewonnen.','Spieler hat verloren.');
symbole:array[1..3]of string=('Schere','Stein','Papier');

Var pc,msg:byte;
begin
  ShowMessage('Spieler fängt an');

RadioButton1.Visible:=true;
RadioButton2.Visible:=true;
RadioButton3.Visible:=true;

  If RadioButton1.Checked or RadioButton2.Checked or RadioButton3.Checked
     then begin
           pc:=random(3)+1;
           ShowMessage('Computer hat'+symbole[pc]+'.');
           case pc of
           1: If RadioButton1.Checked then msg:=1 else if RadioButton2.Checked then msg:=2 else
           If RadioButton3.Checked then msg:=3;
           2: If RadioButton1.Checked then msg:=3 else if RadioButton2.Checked then msg:=1 else
           If RadioButton3.Checked then msg:=2;
           3: If RadioButton1.Checked then msg:=2 else if RadioButton2.Checked then msg:=3 else
           If RadioButton3.Checked then msg:=1;
           end;
  ShowMessage(nachricht[msg]);
  end else ShowMessage('Bitte erst einen Button auswählen!');


end;

end.

Geändert von r_kerber (23. Mär 2015 um 07:03 Uhr) Grund: Ich habe hier mal die Delphi-Tags hinzugefügt. Ist so besser lesbar.
  Mit Zitat antworten Zitat