// Pexeso by Ondrej Jombík [Delphi project no.2]
// Pokus o čo najjednoduchšie riešenie
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls;
const
XSize=8;
YSize=8;
PexStrs=(XSize*YSize) div 2;
PexesoStr:array[0..PexStrs-1] of string=(
'Slovensko','Rakusko','Polsko','Madarsko','Rusko','Ukraina','Dansko','Norsko',
'Svedsko','Finsko','Island','Nahorny Karabach','Litva','Macedonsko','Grecko','Chorvatsko',
'Bulharsko','Cyprus','Kreta','Taliansko','Cesko','Portugalsko','Spanielsko','Francuzko',
'Anglicko','Skotsko','Wales','Irsko','Holandsko','Belgicko','Luxemburgsko','Svajciarsko');
type
TFormPexeso = class(TForm)
StringGrid: TStringGrid;
procedure PexesoCreate(Sender: TObject);
procedure StringGridDrawCell(Sender:TObject; Col,Row:Longint; Rect:TRect; State:TGridDrawState);
procedure StringGridSelectCell(Sender: TObject; Col, Row: Longint; var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormPexeso: TFormPexeso;
x1,y1:integer;
x2,y2:integer;
implementation
{$R *.DFM}
procedure TFormPexeso.PexesoCreate(Sender: TObject);
var
k,l,x,y:integer;
begin
x1:=-1;y1:=-1;
x2:=-1;y2:=-1;
StringGrid.Font.Color:=clBlue;
StringGrid.colCount:=xsize;
StringGrid.rowCount:=ysize;
StringGrid.refresh;
for k:=0 to XSize-1 do for l:=0 to YSize-1 do StringGRid.cells[k,l]:='';
for k:=0 to PexStrs*2-1 do begin
repeat
x:=random(xsize);
y:=random(ysize);
until StringGRid.Cells[x,y]='';
StringGRid.Cells[x,y]:=PexesoStr[k div 2];
end;
StringGrid.refresh;
end;
procedure TFormPexeso.StringGridDrawCell(Sender:TObject; Col,Row:Longint; Rect:TRect; State:TGridDrawState);
var h:string;
begin
h:=StringGrid.Cells[Col,Row];
if h='' then StringGrid.Canvas.Brush.Color:=clBlack
else
if ((col=x1) and (row=y1)) or ((col=x2) and (row=y2))then
StringGrid.Canvas.Brush.Color:=clGreen
else StringGrid.Canvas.Brush.Color:=clBlue;
StringGrid.Canvas.TextRect(Rect,Rect.Left,Rect.Top,h);
end;
procedure TFormPexeso.StringGridSelectCell(Sender:TObject; Col,Row:Longint; var CanSelect:Boolean);
begin
if StringGrid.cells[col,row]<>'' then begin
if (x1<>-1) and (y1<>-1) then begin
if (col<>x1) or (row<>y1) then begin
x2:=col;y2:=row;
stringgrid.refresh;
if StringGrid.cells[col,row]=STringGrid.cells[x1,y1] then begin
StringGrid.cells[col,row]:='';
STringGrid.cells[x1,y1]:='';
stringgrid.refresh;
end
else begin
end;
x1:=-1;y1:=-1;
x2:=-1;y2:=-1;
end
end
else begin
x1:=col;
y1:=row;
stringgrid.refresh;
end;
end;
end;
end.