Einzelnen Beitrag anzeigen

KleineAerztin

Registriert seit: 29. Dez 2008
17 Beiträge
 
#1

Memory Spiel -> Computer ziehen

  Alt 18. Jun 2009, 15:15
Hallo, wir haben jetze seit einem Jahr ungefähr Informatikunterrricht, aber leider etwas zu wenig, um wirklich mitzukommen. Wir haben jetzt eine letzte Aufgabe bekommen. Wir haben ein fertiges Programm bekommen, ein Memory-Spiel. Und wir sollen es jetzt so einstellen, dass wenn man alleine spielt, der Computer mitspielen soll. Ame besten wäre es sogar, wenn es verschiedene Schwierigkeitsgrade gibt. Und ich wollte nun einmal fragen, ob ihr mir vlt dabei helfen könntet... ?
MfG Mandy


Hier ncoh das Programm...
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Weiter: TButton;
    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;
    Image31: TImage;
    Image32: TImage;
    Image33: TImage;
    Image34: TImage;
    Image35: TImage;
    Image36: TImage;
    Button5: TButton;
    Button6: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Button26: TButton;
    Button27: TButton;
    Button28: TButton;
    Button29: TButton;
    Button30: TButton;
    Button31: TButton;
    Button32: TButton;
    Button33: TButton;
    Button34: TButton;
    Button35: TButton;
    Button36: TButton;
    Button7: TButton;
    Label5: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Start: TButton;
    Label6: TLabel;
    ComboBox1: TComboBox;
    Label7: TLabel;
    Label8: TLabel;
    ComboBox2: TComboBox;
    Ende: TButton;
    procedure WeiterClick(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 Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button30Click(Sender: TObject);
    procedure Button24Click(Sender: TObject);
    procedure Button25Click(Sender: TObject);
    procedure Button26Click(Sender: TObject);
    procedure Button27Click(Sender: TObject);
    procedure Button28Click(Sender: TObject);
    procedure Button29Click(Sender: TObject);
    procedure Button31Click(Sender: TObject);
    procedure Button32Click(Sender: TObject);
    procedure Button33Click(Sender: TObject);
    procedure Button34Click(Sender: TObject);
    procedure Button35Click(Sender: TObject);
    procedure Button36Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure StartClick(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure EndeClick(Sender: TObject);
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var
  Form1 : TForm1;
  karte1,karte2 : TImage;
  butt1,butt2 : TButton;
  bu : array[1..36] of TButton;
  bild : array[1..36] of integer;
  anzk : integer = 0;
  Spielerzahl : integer = 1;
  SpNr : integer = 1;
  Punkte : array[1..4] of integer;
  gefunden : integer = 0;
  compu : boolean = false;
  sgrad : integer = 1;

implementation

{$R *.DFM}


function imageunter(B : TButton) : TImage;
var i : integer;
     imag : TImage;
begin
  i:=1;
  repeat
    imag:=Form1.findcomponent('Image'+inttostr(i)) as TImage;
    i:=i+1;
  until (imag.top = B.top) and (imag.left = b.left);
  result:=imag;
end;


procedure mischen;
var helpt,helpl,i,z1,z2 : integer;
    k1,k2 : TImage;
begin
  randomize;
  for i:=1 to 100 do
  begin
    z1:=random(36)+1;
    z2:=random(36)+1;
    k1:=Form1.findcomponent('Image'+inttostr(z1)) as TImage;
    k2:=Form1.findcomponent('Image'+inttostr(z2)) as TImage;
    helpt:=k1.top; helpl:=k1.left;
    k1.top:=k2.top; k1.left:=k2.left;
    k2.top:=helpt; k2.left:=helpl;
  end;
end;


procedure spielstandaktualisieren;
var i : integer;
    E : TEdit;
begin
  for i:=1 to 4 do
  begin
    E:=Form1.findcomponent('Edit'+inttostr(i)) as TEdit;
    E.text:=inttostr(Punkte[i]);
  end;
end;


procedure neu;
var i : integer;
    image : TImage;
begin
  for i:= 1 to 36 do
  begin
    bu[i]:=Form1.findcomponent('Button'+inttostr(i)) as TButton;
    bu[i].enabled:=true;
    bu[i].visible:=true;
    bild[i]:=0;
    image:=Form1.findcomponent('Image'+inttostr(i)) as TImage;
    image.visible:=true;
  end;
  for i:=1 to 4 do Punkte[i]:=0;
  SpNr:=1;
  spielstandaktualisieren;
  gefunden:=0;
  mischen;
end;


procedure aufdecken(buttonx : TButton);
var i,j : integer;
     B : TButton;
begin
  j:=1;
  repeat
    B:=Form1.findcomponent('Button'+inttostr(j)) as TButton;
    j:=j+1;
  until (B.top = buttonx.top) and (B.left = buttonx.left);
  Bild[j-1]:=imageunter(buttonx).tag;
  i:=1;
  anzk:=anzk+1;
  buttonx.visible:=false;
  case anzk of
  1 : begin
        butt1:=buttonx;
        repeat
          karte1:=Form1.findcomponent('Image'+inttostr(i)) as TImage;
          i:=i+1;
        until (karte1.top = buttonx.top) and (karte1.left = buttonx.left);
      end;
  2 : begin
        butt2:=buttonx;
        repeat
          karte2:=Form1.findcomponent('Image'+inttostr(i)) as TImage;
          i:=i+1;
        until (karte2.top = buttonx.top) and (karte2.left = buttonx.left);
      end;
  end;
end;


procedure computerzug1;
begin
end;

procedure computerzug2;
begin
end;

procedure computerzug3;
begin
end;



procedure TForm1.StartClick(Sender: TObject);
var L1 : TLabel;
    E1 : TEdit;
    i : integer;
begin
  weiter.visible:=true;
  start.visible:=false;
  combobox1.visible:=false;
  label6.visible:=false;
  spielerzahl:=strtoint(combobox1.text);
  for i:=1 to 4 do Punkte[i]:=0;
  if spielerzahl = 1 then
  begin
    label2.caption:='Total Recall:';
    compu:=true;
    label8.visible:=true;
    combobox2.visible:=true;
    spielerzahl:=2;
  end;
  for i:=1 to spielerzahl do
  begin
    L1:=Form1.findcomponent('label'+inttostr(i)) as Tlabel;
    E1:=Form1.findcomponent('edit'+inttostr(i)) as TEdit;
    L1.visible:=true;
    E1.visible:=true;
  end;
end;

procedure TForm1.WeiterClick(Sender: TObject);
var lab : TLabel;
    B : TButton;
    i : integer;
begin
  if gefunden =18 then neu
  else
    begin
      if anzk=2 then
      begin
        if karte1.tag=karte2.tag then
        begin
          karte1.visible:=false;
          karte2.visible:=false;
          gefunden:=gefunden+1;
          Punkte[SpNr]:=Punkte[SpNr]+1;
          spielstandaktualisieren;
          anzk:=0;
          i:=1;
          repeat
            B:=Form1.findcomponent('Button'+inttostr(i)) as TButton;
            i:=i+1;
          until (B.top = karte1.top) and (B.left = karte1.left);
          bild[i-1]:=-1;
          i:=1;
          repeat
            B:=Form1.findcomponent('Button'+inttostr(i)) as TButton;
            i:=i+1;
          until (B.top = karte2.top) and (B.left = karte2.left);
          bild[i-1]:=-1;
        end
        else
        begin
          butt1.visible:=true;
          butt2.visible:=true;
          lab:=Form1.findcomponent('label'+inttostr(SpNr)) as TLabel;
          lab.color:=clbackground;
          SpNr:=(SpNr+1) mod (Spielerzahl+1); if SpNr = 0 then SpNr:=1;
          lab:=Form1.findcomponent('label'+inttostr(SpNr)) as TLabel;
          lab.color:=clred;
          anzk:=0;
        end;
        if compu and (SpNr = 2) and (gefunden<18) then
        begin
          case sgrad of
            1 : computerzug1;
            2 : computerzug2;
            3 : computerzug3;
          end;
        end;
      end;
    end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button2);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button3);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button4);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button5);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button6);
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button7);
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button8);
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button9);
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button10);
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button11);
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button12);
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button13);
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button14);
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button15);
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button16);
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button17);
end;

procedure TForm1.Button18Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button18);
end;

procedure TForm1.Button19Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button19);
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button20);
end;

procedure TForm1.Button21Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button21);
end;

procedure TForm1.Button22Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button22);
end;

procedure TForm1.Button23Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button23);
end;

procedure TForm1.Button30Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button30);
end;

procedure TForm1.Button24Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button24);
end;

procedure TForm1.Button25Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button25);
end;

procedure TForm1.Button26Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button26);
end;

procedure TForm1.Button27Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button27);
end;

procedure TForm1.Button28Click(Sender: TObject);
begin
if anzk<2 then aufdecken(Button28);
end;

procedure TForm1.Button29Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button29);
end;

procedure TForm1.Button31Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button31);
end;

procedure TForm1.Button32Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button32);
end;

procedure TForm1.Button33Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button33);
end;

procedure TForm1.Button34Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button34);
end;

procedure TForm1.Button35Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button35);
end;

procedure TForm1.Button36Click(Sender: TObject);
begin
  if anzk<2 then aufdecken(Button36);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  neu;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
begin
  sgrad:=strtoint(combobox2.text);
end;

procedure TForm1.EndeClick(Sender: TObject);
begin
  Application.terminate;
end;

end.
[edit=Phoenix] Code in Delphi-Tags gepackt. Das nächste mal bitte selber machen. Mfg, Phoenix[/edit]
  Mit Zitat antworten Zitat