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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons, ExtCtrls;
const deb = 8;
type
TForm1 = class(TForm)
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
Button3: TButton;
Label1: TLabel;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure BoutonClick(Sender: TObject);
private
{ Déclarations privées }
jeu : array[0..deb-1,0..deb-1] of integer;
Voisine : array[-1..9,-1..9] of integer;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i,j : integer;
debutgauche, debuthaut, colonne,ligne : integer;
begin
randomize;
//rendre visible le groupbox
StringGrid1.visible := true;
debutgauche := 2;
debuthaut := 3;
for i:=1 to 9 do //lignes
begin
for j := 1 to 9 do //colonnes
//utilisation du create
with TButton.Create(self) do begin
Parent := Self;
Left := debutgauche; //position à gauche du bouton
Top := debuthaut; //position en haut du bouton
width := 40;
height := 40;
Name := ('l'+inttostr(i)+'c'+inttostr(j));
onclick := BoutonClick;
//mise à jour de gauche pour bouton suivant
debutgauche := debutgauche + 41 ; //widht => 100
visible:=false;
caption:='';
end;
debuthaut := debuthaut+41;
debutgauche:=2;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var nombreBombes, ligne, colonne, i,j, caze : integer;
var rect : Trect;
var ImgBombe : TBitmap;
var zero,un,deux,trois,quatre,cinq,six,sept,huit: TBitmap;
texte : string;
begin
colonne := 0;
ligne:=0;
for i:= -1 to 9 do
begin
for j:=-1 to 9 do
begin
Voisine[colonne,ligne]:=0;
end;
end;
nombreBombes:= 0;
while (nombreBombes <> 10 ) do
begin
ligne := random(8);
colonne := random(8);
ImgBombe:=TBitmap.Create;
ImgBombe.LoadFromFile('Bombe2.bmp');
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(colonne,ligne),ImgBombe); //Affichage bombes
ImgBombe.Free;
nombreBombes := nombreBombes+1;
Voisine[colonne,ligne] := 100;
end;
un:=TBitmap.Create;
un.LoadFromFile('un.bmp');
deux:=TBitmap.Create;
deux.LoadFromFile('deux.bmp');
trois:=TBitmap.Create;
trois.LoadFromFile('trois.bmp');
quatre:=TBitmap.Create;
quatre.LoadFromFile('quatre.bmp');
cinq:=TBitmap.Create;
cinq.LoadFromFile('cinq.bmp');
six:=TBitmap.Create;
six.LoadFromFile('six.bmp');
sept:=TBitmap.Create;
sept.LoadFromFile('sept.bmp');
huit:=TBitmap.Create;
huit.LoadFromFile('huit.bmp');
for i:=0 to 8 do
begin
texte:='';
for j:=0 to 8 do
begin
if Voisine[j,i] <> 100 then
caze:=(Voisine[j-1,i-1] + Voisine[j-1,i] + Voisine[j-1,i+1] + Voisine[j,i-1] + Voisine[j,i+1]
+ Voisine[j+1,i-1]+ Voisine[j+1,i]+ Voisine[j+1,i+1]) div 100
else caze :=100;
texte:=texte+inttostr(caze);
if caze = 0 then
begin
zero:=TBitmap.Create;
zero.LoadFromFile('zero.bmp');
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),zero);
zero.Free;
end;
if caze = 1 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),un);
if caze = 2 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),deux);
if caze = 3 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),trois);
if caze = 4 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),quatre);
if caze = 5 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),cinq);
if caze = 6 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),six);
if caze = 7 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),sept);
if caze = 8 then
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(j,i),huit);
end;
memo1.Lines.Add(texte);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var nombreBombes, ligne, colonne, i,j : integer;
var rect : Trect;
begin
colonne := i;
ligne:=j;
for i:= -1 to 9 do
begin
for j:=-1 to 9 do
begin
Voisine[i,j]:=0;
end;
end;
for i := 0 to 8 do
begin
for j := 0 to 8 do
begin
stringgrid1.canvas.brush.color := clgreen;
rect := stringgrid1.CellRect(i,j);
stringgrid1.Canvas.FillRect(rect);
end;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j : integer;
debutgauche, debuthaut : integer;
ligne, nbLigne : integer;
var monbouton : TButton;
begin
//visible tous les boutons
for i:=1 to 9 do //lignes
begin
for j := 1 to 9 do //colonnes
begin
monbouton := tbutton(findcomponent('l'+inttostr(i)+'c'+inttostr(j)));
monbouton.Show;
end;
end;
end;
procedure TForm1.BoutonClick(Sender: TObject);
var monbouton : Tbutton;
begin
monbouton := Tbutton(Sender);
if (monbouton <> nil) then
begin
monbouton := tbutton(findcomponent(monbouton.name));
if monbouton <> nil then
begin
//monbouton.Destroy
monbouton.hide;
button1click(sender);
end
else
showmessage('pas de bouton');
end;
end;
end. // FIN PROG |
Partager