1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
| unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
RadioButton5: TRadioButton;
RadioButton6: TRadioButton;
RadioButton7: TRadioButton;
RadioButton8: TRadioButton;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
Label1: TLabel;
Timer1: TTimer;
procedure SetCaption;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
uses
Couleurs, Grille;
{$R *.dfm}
function IIf(const expr: boolean; const i1, i2: integer): integer;
begin
if expr then Result := i1 else Result := i2;
end;
const
Palette: array[0..6]of TColor = (
Gray,
SlateBlue,
DarkSlateBlue,
Tangerine,
DarkPastelGreen,
Indigo,
LemonChiffon
);
EnCours = 'Partie en cours';
BlancGagne = 'Joueur 1 gagnant';
NoirGagne = 'Joueur 2 gagnant';
GrillePleine = 'Grille pleine';
var
Boutons: array[MinX..MaxX]of TButton;
Disques: array[MinX..MaxX, MinY..MaxY]of TShape;
Chute: record
Action: boolean;
X: integer;
end;
DemiCoups: integer;
Grille1: TGrille;
Fin: boolean;
function EtatDuJeu: string;
begin
if Gagne(Grille1, Noir) then
Result := NoirGagne
else
if DemiCoups = MaxX * MaxY then
Result := GrillePleine
else
if Gagne(Grille1, Blanc) then
Result := BlancGagne
else
Result := EnCours;
end;
procedure TForm1.SetCaption;
begin
Label1.Caption := EtatDuJeu;
Fin := Label1.Caption <> EnCours;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
x, y: integer;
begin
Self.WindowState := wsMaximized;
Self.Color := Palette[0];
Panel1.Color := Palette[1];
Panel1.Top := (GetSystemMetrics(SM_CYFULLSCREEN) - Panel1.Height) div 2;
Panel1.Left := (GetSystemMetrics(SM_CXFULLSCREEN) - Panel1.Width) div 2;
Label1.Color := Palette[5];
Label1.Font.Color := Palette[6];
for x := MinX to MaxX do
begin
Boutons[x] := TButton.Create(Self);
with Boutons[x] do
begin
Parent := Panel1;
Name := Chr(x-1+Ord('A'));
Left := 56*(x-1)+4;
Top := 344;
Width := 56;
Height := 28;
Tag := x;
onClick := Button1Click;
onKeyDown := Button1KeyDown;
end;
for y := MinY to MaxY do
begin
Disques[x, y] := TShape.Create(Self);
with Disques[x, y] do
begin
Parent := Panel1;
Name := Chr(x-1+Ord('A'))+Chr(y-1+Ord('1'));
Left := 56*x-52+4;
Top := 56*(6-y+1)-52+4;
Width := 48;
Height := 48;
Shape := stCircle;
Pen.Color := Palette[2];
Brush.Color := Self.Color;
end;
end;
end;
Chute.Action := False;
DemiCoups := 0;
Vider(Grille1);
SetCaption;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x, y: integer;
c: tColor;
p: tPion;
begin
if (Sender as TButton).Tag = Button1.Tag then
begin
Close;
Exit;
end;
if Fin then
begin
for x := MinX to MaxX do
for y := MinY to MaxY do
Disques[x, y].Brush.Color := Self.Color;
DemiCoups := 0;
Vider(Grille1);
SetCaption;
Exit;
end;
x := (Sender as TButton).Tag;
if not Chute.Action and (Disques[x, MaxY].Brush.Color = Self.Color) then
begin
c := IIF(DemiCoups mod 2=0, Palette[3], Palette[4]);
Disques[x, MaxY].Brush.Color := c;
Chute.Action := True;
Chute.X := x;
p := IIF(DemiCoups mod 2=0, Pion*Blanc, Pion*Noir);
Ajouter(Grille1, p, x);
Inc(DemiCoups);
SetCaption;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
x, y: integer;
p: tPion;
c: tColor;
begin
if Chute.Action then
begin
y := MaxY;
while Disques[Chute.X, y].Brush.Color = Self.Color do
Dec(y);
if (y > MinY) and (Disques[Chute.X, y-1].Brush.Color = Self.Color) then
begin
Disques[Chute.X, y-1].Brush.Color := Disques[Chute.X, y].Brush.Color;
Disques[Chute.X, y].Brush.Color := Color;
end else
Chute.Action := False;
end else
if (((DemiCoups mod 2=0) and not RadioButton1.Checked)
or
((DemiCoups mod 2=1) and not RadioButton5.Checked))
and not Fin then
begin
p := IIF(DemiCoups mod 2=0, Pion*Blanc, Pion*Noir);
c := IIF(DemiCoups mod 2=0, Palette[3], Palette[4]);
if ((DemiCoups mod 2=0) and RadioButton2.Checked)
or ((DemiCoups mod 2=1) and RadioButton6.Checked)
then
x := CoupAutomatique1(Grille1)
else
if ((DemiCoups mod 2=0) and RadioButton3.Checked)
or ((DemiCoups mod 2=1) and RadioButton7.Checked)
then
x := CoupAutomatique2(Grille1, p)
else
if ((DemiCoups mod 2=0) and RadioButton4.Checked)
or ((DemiCoups mod 2=1) and RadioButton8.Checked)
then
x := CoupAutomatique3(Grille1, p);
Disques[x, MaxY].Brush.Color := c;
Chute.Action := True;
Chute.X := x;
Ajouter(Grille1, p, x);
Inc(DemiCoups);
SetCaption;
end;
end;
procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
Close;
end;
end. |
Partager