Napísal autor témy ovvo: 08.01.2008 23:28 | HEX | |
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TSest = class
procedure vykresli (x,y:integer;ob:TImage);
procedure vyfarbi (ob:TImage;ff,xx,yy:integer);
{constructor Create(xx, yy: Integer);}
end;
TPole= class
sused:boolean;
Farba:TColor;
end;
Thra = class
p:array[1..7,1..7] of TSest;
pole:array[1..7,1..7] of TPole;
X,Y:integer;
ob:TImage;
procedure vyskladaj;
procedure striedaj (xx,yy:integer);
procedure naplnpole(ob:TImage);
end;
var
Form1: TForm1;
g:TImage;
h:THra;
s:TSest;
k:integer;
hrac:0..1=1;
a:integer=20;
v:integer;
implementation
{$R *.dfm}
{constructor TSest.Create(xx,yy: Integer);
begin
X := xx;
Y := yy;
end;}
procedure TSest.vykresli (x,y:integer; ob:TImage);
var v:integer;
begin
a:=20;
v := round(a*0.877);
ob.Canvas.Polygon([Point(x+v,y),Point(x+2*v,y+a div 2),Point(x+2*v,y+a+a div 2),Point(x+v,y+2*a),Point(x,y+a+a div 2),Point(x,y+a div 2),Point(x+v,y)]);
end;
procedure TSest.vyfarbi(ob:TImage;ff,xx,yy:integer);
begin
if ff=1 then begin
ob.canvas.brush.Color:=clBlue;
ob.Canvas.Rectangle(330,430,360,460);
ob.Canvas.Brush.Color:=clRed;
ob.Canvas.FloodFill(xx,yy,clBlack,fsBorder);
end;
if ff=0 then begin
ob.canvas.brush.Color:=clRed;
ob.Canvas.Rectangle(330,430,360,460);
ob.Canvas.Brush.Color:=clBlue;
ob.Canvas.FloodFill(xx,yy,clBlack,fsBorder);
end;
end;
procedure Thra.vyskladaj;
var i,j,x,y:integer;
begin
v:= round(a*0.877);
x:=65;
y:=140;
for i:= 1 to 7 do begin
for j:=1 to 7 do begin
p[i,j]:=TSest.Create;
p[i,j].vykresli(x,y,g);
x:=x+2*v; //v riadku posune na dalsi hex
end;
y:=y+a+a div 2;
x:=65+i*v;
end;
end;
procedure THra.striedaj (xx,yy:integer);
begin
if hrac =1 then begin
s.vyfarbi(g,1,xx,yy);
hrac:=0;
end
else begin
s.vyfarbi(g,0,xx,yy);
hrac:=1;
end;
end;
procedure THra.naplnpole(ob:TImage);
var i,j,x,y,v:integer;
begin
a:=20;
v:= round(a*0.877);
x:=65+v;
y:=140+a;
for i:= 1 to 7 do begin
for j:=1 to 7 do begin
h.pole[i,j]:=TPole.Create;
h.pole[i,j].Farba:=ob.Canvas.Pixels[x,y];
x:=x+2*v;
end;
y:=y+a+a div 2;
x:=65+i*v+v;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
image1.Picture.LoadFromFile('BG.bmp');
g:=Image1;
h.vyskladaj;
Label1.Visible:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
h:=THra.Create;
for i:= 1 to 7 do begin
for j:=1 to 7 do begin
h.pole[i,j]:=TPole.Create;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var v,s:integer;
begin
for v := 1 to 7 do
for s := 1 to 7 do
h.p[s,v].Free;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (Image1.Canvas.Pixels[x,y]=clWhite) then
if (Image1.Canvas.Pixels[x,y]=clRed) or (Image1.Canvas.Pixels[x,y]= clBlue) then
else
begin
h.striedaj(x,y);
h.naplnpole(g);
end;
end;
end.
=====================
=====================
potialto by to malo byt funkcne aj s ukladanim farieb do pola +- nejake tie endy
|