SlimSoft Napisano Luty 1, 2016 Zgłoś Share Napisano Luty 1, 2016 Wrzućcie 10 przycisków na formę i przypiszcie zdarzenia: oto kod unit code; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm3 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; Button9: TButton; Button10: TButton; 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); private { Private declarations } public procedure SprawdzStan; function KrzyzykVictoria: Boolean; function Kolkovictoria: Boolean; procedure NoweRozdanie; { Public declarations } end; var Form3: TForm3; Table: array [1..9] of byte = (0,0,0,0,0,0,0,0,0); // tablica stanów: { 0 - bez napisu 1: - kółko 2: - krzyżyk } Gracz: Integer = 0; //gracz 1 - kółko, 0 - krzyżyk implementation {$R *.dfm} procedure TForm3.Button10Click(Sender: TObject); begin button10.Enabled := False; If Application.MessageBox(':-) nowe rozdanie?','Kółko i krzyżyk',MB_IconInformation or MB_YESNO) = ID_YES then NoweRozdanie; Button10.Enabled := True; end; procedure TForm3.Button1Click(Sender: TObject); begin if Button1.Caption <> '' then exit; case Gracz of 0: begin button1.Caption := 'x'; Table[1] := 2; sprawdzStan; gracz := 1; button1.Enabled := False; end; 1: begin button1.Caption := 'o'; Table[1] := 1; sprawdzStan; gracz := 0; button1.Enabled := False; end; end; end; procedure TForm3.Button2Click(Sender: TObject); begin if Button2.Caption <> '' then exit; case Gracz of 0: begin button2.Caption := 'x'; Table[2] := 2; sprawdzStan; gracz := 1; button2.Enabled := False; end; 1: begin button2.Caption := 'o'; Table[2] := 1; sprawdzStan; gracz := 0; button2.Enabled := False; end; end; end; procedure TForm3.Button3Click(Sender: TObject); begin if Button3.Caption <> '' then exit; case Gracz of 0: begin button3.Caption := 'x'; Table[3] := 2; sprawdzStan; gracz := 1; button3.Enabled := False; end; 1: begin button3.Caption := 'o'; Table[3] := 1; sprawdzStan; gracz := 0; button3.Enabled := False; end; end; end; procedure TForm3.Button4Click(Sender: TObject); begin if Button4.Caption <> '' then exit; case Gracz of 0: begin button4.Caption := 'x'; Table[4] := 2; sprawdzStan; gracz := 1; button4.Enabled := False; end; 1: begin button4.Caption := 'o'; Table[4] := 1; sprawdzStan; gracz := 0; button4.Enabled := False; end; end; end; procedure TForm3.Button5Click(Sender: TObject); begin if Button5.Caption <> '' then exit; case Gracz of 0: begin button5.Caption := 'x'; Table[5] := 2; sprawdzStan; gracz := 1; button5.Enabled := False; end; 1: begin button5.Caption := 'o'; Table[5] := 1; sprawdzStan; gracz := 0; button5.Enabled := False; end; end; end; procedure TForm3.Button6Click(Sender: TObject); begin if Button6.Caption <> '' then exit; case Gracz of 0: begin button6.Caption := 'x'; Table[6] := 2; sprawdzStan; gracz := 1; button6.Enabled := False; end; 1: begin button6.Caption := 'o'; Table[6] := 1; sprawdzStan; gracz := 0; button6.Enabled := False; end; end; end; procedure TForm3.Button7Click(Sender: TObject); begin if Button7.Caption <> '' then exit; case Gracz of 0: begin button7.Caption := 'x'; Table[7] := 2; sprawdzStan; gracz := 1; button7.Enabled := False; end; 1: begin button7.Caption := 'o'; Table[7] := 1; sprawdzStan; gracz := 0; button7.Enabled := False; end; end; end; procedure TForm3.Button8Click(Sender: TObject); begin if Button8.Caption <> '' then exit; case Gracz of 0: begin button8.Caption := 'x'; Table[8] := 2; sprawdzStan; gracz := 1; button8.Enabled := False; end; 1: begin button8.Caption := 'o'; Table[8] := 1; sprawdzStan; gracz := 0; button8.Enabled := False; end; end; end; procedure TForm3.Button9Click(Sender: TObject); begin if Button9.Caption <> '' then exit; case Gracz of 0: begin button9.Caption := 'x'; Table[9] := 2; sprawdzStan; gracz := 1; button9.Enabled := False; end; 1: begin button9.Caption := 'o'; Table[9] := 1; sprawdzStan; gracz := 0; button9.Enabled := False; end; end; end; procedure TForm3.NoweRozdanie; begin Button1.Caption := ''; Button2.Caption := ''; Button3.Caption := ''; Button4.Caption := ''; Button5.Caption := ''; Button6.Caption := ''; Button7.Caption := ''; Button8.Caption := ''; Button9.Caption := ''; Table[1] := 0; Table[2] := 0; Table[3] := 0; Table[4] := 0; Table[5] := 0; Table[6] := 0; Table[7] := 0; Table[8] := 0; Table[9] := 0; Gracz := 1; Button1.Enabled := True; Button2.Enabled := True; Button3.Enabled := True; Button4.Enabled := True; Button5.Enabled := True; Button6.Enabled := True; Button7.Enabled := True; Button8.Enabled := True; Button9.Enabled := True; end; procedure TForm3.SprawdzStan; begin { KRZYŻYK } // krzyzyk w poziomie if (Table[1] = 2) and (Table[2] = 2) and (Table[3] = 2) then KrzyzykVictoria; if (Table[4] = 2) and (Table[5] = 2) and (Table[6] = 2) then KrzyzykVictoria; if (Table[7] = 2) and (Table[8] = 2) and (Table[9] = 2) then KrzyzykVictoria; // krzyżyk w pionie if (Table[1] = 2) and (Table[4] = 2) and (Table[7] = 2) then KrzyzykVictoria; if (Table[2] = 2) and (Table[5] = 2) and (Table[8] = 2) then KrzyzykVictoria; if (Table[3] = 2) and (Table[6] = 2) and (Table[9] = 2) then KrzyzykVictoria; // krzyżyk po skosie if (Table[1] = 2) and (Table[5] = 2) and (Table[9] = 2) then KrzyzykVictoria; if (Table[7] = 2) and (Table[5] = 2) and (Table[3] = 2) then KrzyzykVictoria; { KÓŁKO} // kółko w poziomie if (Table[1] = 1) and (Table[2] = 1) and (Table[3] = 1) then KolkoVictoria; if (Table[4] = 1) and (Table[5] = 1) and (Table[6] = 1) then KolkoVictoria; if (Table[7] = 1) and (Table[8] = 1) and (Table[9] = 1) then KolkoVictoria; // kółko w pionie if (Table[1] = 1) and (Table[4] = 1) and (Table[7] = 1) then KolkoVictoria; if (Table[2] = 1) and (Table[5] = 1) and (Table[8] = 1) then KolkoVictoria; if (Table[3] = 1) and (Table[6] = 1) and (Table[9] = 1) then KolkoVictoria; // kółko po skosie if (Table[1] = 1) and (Table[5] = 1) and (Table[9] = 1) then KolkoVictoria; if (Table[7] = 1) and (Table[5] = 1) and (Table[3] = 1) then KolkoVictoria; end; function TForm3.Kolkovictoria: Boolean; begin If Application.MessageBox('Wygrało kółko o :-) nowe rozdanie?','Kółko i krzyżyk',MB_IconInformation or MB_YESNO) = ID_YES then NoweRozdanie; Result := True; end; function TForm3.KrzyzykVictoria: Boolean; begin If Application.MessageBox('Wygrał krzyżyk x :-) nowe rozdanie?','Kółko i krzyżyk',MB_IconInformation or MB_YESNO) = ID_YES then NoweRozdanie; Result := True; end; end. Link do komentarza Udostępnij na innych stronach More sharing options...
babubabu Napisano Luty 3, 2016 Zgłoś Share Napisano Luty 3, 2016 http://forum.4programmers.net/Off-Topic/Oceny_i_recenzje/265782-w_jaki_sposob_zrobic_gre_kolko_i_krzyzyk Link do komentarza Udostępnij na innych stronach More sharing options...
Polecane posty
Zarchiwizowany
Ten temat jest archiwizowany i nie można dodawać nowych odpowiedzi.