Registriert seit: 6. Mai 2010
19 Beiträge
|
Re: Schiffe versenken, Platzierung
24. Mai 2010, 12:07
Ich bin jetzt schon relativ weit gekommen, nur wie überprüfe ich ob die Schiffe nebeneinanderliegen? Denn das sollte ja eigentlich nicht möglich sein.
Momentan sieht der Quelltext bei mir so aus:
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
DrawGrid1: TDrawGrid;
BHori: TButton;
Image1: TImage;
Image2: TImage;
BVerti: TButton;
IHori: TImage;
IVerti: TImage;
Image3: TImage;
Image4: TImage;
DrawGrid2: TDrawGrid;
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure BHoriClick(Sender: TObject);
procedure BVertiClick(Sender: TObject);
private
arr2: array[0..9,0..9] of boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c,d,e,f,g,h,z:integer;
implementation
{$R *.DFM}
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
begin
with sender as TDrawgrid do
begin
if arr2[acol,arow]
then canvas.brush.color := clred
else canvas.brush.color := clwhite;
canvas.fillrect(rect);
end;
end;
end;
procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var row,col:integer;
begin
DrawGrid1.MouseToCell(X, Y,Col, Row); //Mausposition auslesen
if z=5 then //5er Schiff
if a=1 then
begin
if col<6 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
arr2[col+c,row+g]:= not arr2[col+c,row+g];
arr2[col+d,row+h]:= not arr2[col+d,row+h];
image4.visible:=false;
z:=z+1;
end;
end
else
if row<6 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
arr2[col+c,row+g]:= not arr2[col+c,row+g];
arr2[col+d,row+h]:= not arr2[col+d,row+h];
image4.visible:=false;
z:=z+1;
end;
if z=4 then //4er Schiff
if a=1 then
begin
if col<7 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
arr2[col+c,row+g]:= not arr2[col+c,row+g];
image3.visible:=false;
z:=z+1;
end;
end
else
if row<7 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
arr2[col+c,row+g]:= not arr2[col+c,row+g];
image3.visible:=false;
z:=z+1;
end;
if z=3 then //3er Schiff
if a=1 then
begin
if col<8 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
image2.visible:=false;
z:=z+1;
end;
end
else
if row<8 then
begin
arr2[col,row] := not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
arr2[col+b,row+f]:= not arr2[col+b,row+f];
image2.visible:=false;
z:=z+1;
end;
if z=2 then //2er Schiff
if a=1 then
begin
if col<9 then
begin
arr2[col,row]:= not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
image1.visible:=false;
z:=z+1;
end;
end
else
if row<9 then
begin
arr2[col,row]:= not arr2[col,row];
arr2[col+a,row+e]:= not arr2[col+a,row+e];
image1.visible:=false;
z:=z+1;
end;
DrawGrid1.Repaint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
z:=2;
a:=1; b:=2; c:=3; d:=4;
e:=0; f:=0; g:=0; h:=0;
end;
procedure TForm1.BHoriClick(Sender: TObject);
begin
IVerti.visible:=false; //Horizontale Ausrichtung
IHori.visible:=true;
a:=0; b:=0; c:=0; d:=0;
e:=1; f:=2; g:=3; h:=4;
end;
procedure TForm1.BVertiClick(Sender: TObject);
begin
IVerti.visible:=true; //Vertikale Ausrichtung
IHori.visible:=false;
a:=1; b:=2; c:=3; d:=4;
e:=0; f:=0; g:=0; h:=0;
end;
end.
|