Einzelnen Beitrag anzeigen

deznutsxi

Registriert seit: 1. Jun 2010
1 Beiträge
 
#1

Schiffe versenken Delphi Hilfe!!

  Alt 1. Jun 2010, 00:36
Hallo!!
Ich habe mich mit Delphi beschäftigt und benötige Hilfe.
Wollte SChiffe versenken programmieren, stehe jedoch vor einigen Problemen.
Wenn ich mit der Button2.Click procedure die SChiffe verstecken will (maximal 5) ist es dennoch möglich
mehr als 5 Schiffe zu verstecken, obwohl dies eigentlich durch die Kopfschleife verhindert seien sollte. Beim zufälligen Verstecken werden aber immer nur 5 "versteckt".
Jetzt noch eine andere Frage, wie kann ich die angezeigten Schiffe dann "unsichtbar" machen,sodass erst bei einem Treffer deren Position wieder erkennbar ist, bzw. wie wäre das "Suchen" der Schiffe am Besten umsetzbar!?

Vielen Dank für eure Hilfe

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, jpeg, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image30: TImage;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    Label12: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure anzeige();
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i,j,k:integer;
  a:array[1..5,1..6] of integer;

implementation

{$R *.dfm}

procedure TForm1.anzeige();


begin
if a[1][1]=0 then image1.picture.LoadFromFile('wasser.jpg');
if a[1][1]=1 then image1.picture.LoadFromFile('schuss.jpg');
if a[1][1]=2 then image1.picture.LoadFromFile('schiff.jpg');
if a[1][1]=3 then image1.picture.LoadFromFile('wrack.jpg');

if a[1][2]=0 then image2.picture.LoadFromFile('wasser.jpg');
if a[1][2]=1 then image2.picture.LoadFromFile('schuss.jpg');
if a[1][2]=2 then image2.picture.LoadFromFile('schiff.jpg');
if a[1][2]=3 then image2.picture.LoadFromFile('wrack.jpg');

if a[1][3]=0 then image3.picture.LoadFromFile('wasser.jpg');
if a[1][3]=1 then image3.picture.LoadFromFile('schuss.jpg');
if a[1][3]=2 then image3.picture.LoadFromFile('schiff.jpg');
if a[1][3]=3 then image3.picture.LoadFromFile('wrack.jpg');

if a[1][4]=0 then image4.picture.LoadFromFile('wasser.jpg');
if a[1][4]=1 then image4.picture.LoadFromFile('schuss.jpg');
if a[1][4]=2 then image4.picture.LoadFromFile('schiff.jpg');
if a[1][4]=3 then image4.picture.LoadFromFile('wrack.jpg');

if a[1][5]=0 then image5.picture.LoadFromFile('wasser.jpg');
if a[1][5]=1 then image5.picture.LoadFromFile('schuss.jpg');
if a[1][5]=2 then image5.picture.LoadFromFile('schiff.jpg');
if a[1][5]=3 then image5.picture.LoadFromFile('wrack.jpg');

if a[1][6]=0 then image6.picture.LoadFromFile('wasser.jpg');
if a[1][6]=1 then image6.picture.LoadFromFile('schuss.jpg');
if a[1][6]=2 then image6.picture.LoadFromFile('schiff.jpg');
if a[1][6]=3 then image6.picture.LoadFromFile('wrack.jpg');

if a[2][1]=0 then image7.picture.LoadFromFile('wasser.jpg');
if a[2][1]=1 then image7.picture.LoadFromFile('schuss.jpg');
if a[2][1]=2 then image7.picture.LoadFromFile('schiff.jpg');
if a[2][1]=3 then image7.picture.LoadFromFile('wrack.jpg');

if a[2][2]=0 then image8.picture.LoadFromFile('wasser.jpg');
if a[2][2]=1 then image8.picture.LoadFromFile('schuss.jpg');
if a[2][2]=2 then image8.picture.LoadFromFile('schiff.jpg');
if a[2][2]=3 then image8.picture.LoadFromFile('wrack.jpg');

if a[2][3]=0 then image9.picture.LoadFromFile('wasser.jpg');
if a[2][3]=1 then image9.picture.LoadFromFile('schuss.jpg');
if a[2][3]=2 then image9.picture.LoadFromFile('schiff.jpg');
if a[2][3]=3 then image9.picture.LoadFromFile('wrack.jpg');

if a[2][4]=0 then image10.picture.LoadFromFile('wasser.jpg');
if a[2][4]=1 then image10.picture.LoadFromFile('schuss.jpg');
if a[2][4]=2 then image10.picture.LoadFromFile('schiff.jpg');
if a[2][4]=3 then image10.picture.LoadFromFile('wrack.jpg');

if a[2][5]=0 then image11.picture.LoadFromFile('wasser.jpg');
if a[2][5]=1 then image11.picture.LoadFromFile('schuss.jpg');
if a[2][5]=2 then image11.picture.LoadFromFile('schiff.jpg');
if a[2][5]=3 then image11.picture.LoadFromFile('wrack.jpg');

if a[2][6]=0 then image12.picture.LoadFromFile('wasser.jpg');
if a[2][6]=1 then image12.picture.LoadFromFile('schuss.jpg');
if a[2][6]=2 then image12.picture.LoadFromFile('schiff.jpg');
if a[2][6]=3 then image12.picture.LoadFromFile('wrack.jpg');

if a[3][1]=0 then image13.picture.LoadFromFile('wasser.jpg');
if a[3][1]=1 then image13.picture.LoadFromFile('schuss.jpg');
if a[3][1]=2 then image13.picture.LoadFromFile('schiff.jpg');
if a[3][1]=3 then image13.picture.LoadFromFile('wrack.jpg');

if a[3][2]=0 then image14.picture.LoadFromFile('wasser.jpg');
if a[3][2]=1 then image14.picture.LoadFromFile('schuss.jpg');
if a[3][2]=2 then image14.picture.LoadFromFile('schiff.jpg');
if a[3][2]=3 then image14.picture.LoadFromFile('wrack.jpg');

if a[3][3]=0 then image15.picture.LoadFromFile('wasser.jpg');
if a[3][3]=1 then image15.picture.LoadFromFile('schuss.jpg');
if a[3][3]=2 then image15.picture.LoadFromFile('schiff.jpg');
if a[3][3]=3 then image15.picture.LoadFromFile('wrack.jpg');

if a[3][4]=0 then image16.picture.LoadFromFile('wasser.jpg');
if a[3][4]=1 then image16.picture.LoadFromFile('schuss.jpg');
if a[3][4]=2 then image16.picture.LoadFromFile('schiff.jpg');
if a[3][4]=3 then image16.picture.LoadFromFile('wrack.jpg');

if a[3][5]=0 then image17.picture.LoadFromFile('wasser.jpg');
if a[3][5]=1 then image17.picture.LoadFromFile('schuss.jpg');
if a[3][5]=2 then image17.picture.LoadFromFile('schiff.jpg');
if a[3][5]=3 then image17.picture.LoadFromFile('wrack.jpg');

if a[3][6]=0 then image18.picture.LoadFromFile('wasser.jpg');
if a[3][6]=1 then image18.picture.LoadFromFile('schuss.jpg');
if a[3][6]=2 then image18.picture.LoadFromFile('schiff.jpg');
if a[3][6]=3 then image18.picture.LoadFromFile('wrack.jpg');

if a[4][1]=0 then image19.picture.LoadFromFile('wasser.jpg');
if a[4][1]=1 then image19.picture.LoadFromFile('schuss.jpg');
if a[4][1]=2 then image19.picture.LoadFromFile('schiff.jpg');
if a[4][1]=3 then image19.picture.LoadFromFile('wrack.jpg');

if a[4][2]=0 then image20.picture.LoadFromFile('wasser.jpg');
if a[4][2]=1 then image20.picture.LoadFromFile('schuss.jpg');
if a[4][2]=2 then image20.picture.LoadFromFile('schiff.jpg');
if a[4][2]=3 then image20.picture.LoadFromFile('wrack.jpg');

if a[4][3]=0 then image21.picture.LoadFromFile('wasser.jpg');
if a[4][3]=1 then image21.picture.LoadFromFile('schuss.jpg');
if a[4][3]=2 then image21.picture.LoadFromFile('schiff.jpg');
if a[4][3]=3 then image21.picture.LoadFromFile('wrack.jpg');

if a[4][4]=0 then image22.picture.LoadFromFile('wasser.jpg');
if a[4][4]=1 then image22.picture.LoadFromFile('schuss.jpg');
if a[4][4]=2 then image22.picture.LoadFromFile('schiff.jpg');
if a[4][4]=3 then image22.picture.LoadFromFile('wrack.jpg');

if a[4][5]=0 then image23.picture.LoadFromFile('wasser.jpg');
if a[4][5]=1 then image23.picture.LoadFromFile('schuss.jpg');
if a[4][5]=2 then image23.picture.LoadFromFile('schiff.jpg');
if a[4][5]=3 then image23.picture.LoadFromFile('wrack.jpg');

if a[4][6]=0 then image24.picture.LoadFromFile('wasser.jpg');
if a[4][6]=1 then image24.picture.LoadFromFile('schuss.jpg');
if a[4][6]=2 then image24.picture.LoadFromFile('schiff.jpg');
if a[4][6]=3 then image24.picture.LoadFromFile('wrack.jpg');

if a[5][1]=0 then image25.picture.LoadFromFile('wasser.jpg');
if a[5][1]=1 then image25.picture.LoadFromFile('schuss.jpg');
if a[5][1]=2 then image25.picture.LoadFromFile('schiff.jpg');
if a[5][1]=3 then image25.picture.LoadFromFile('wrack.jpg');

if a[5][2]=0 then image26.picture.LoadFromFile('wasser.jpg');
if a[5][2]=1 then image26.picture.LoadFromFile('schuss.jpg');
if a[5][2]=2 then image26.picture.LoadFromFile('schiff.jpg');
if a[5][2]=3 then image26.picture.LoadFromFile('wrack.jpg');

if a[5][3]=0 then image27.picture.LoadFromFile('wasser.jpg');
if a[5][3]=1 then image27.picture.LoadFromFile('schuss.jpg');
if a[5][3]=2 then image27.picture.LoadFromFile('schiff.jpg');
if a[5][3]=3 then image27.picture.LoadFromFile('wrack.jpg');

if a[5][4]=0 then image28.picture.LoadFromFile('wasser.jpg');
if a[5][4]=1 then image28.picture.LoadFromFile('schuss.jpg');
if a[5][4]=2 then image28.picture.LoadFromFile('schiff.jpg');
if a[5][4]=3 then image28.picture.LoadFromFile('wrack.jpg');

if a[5][5]=0 then image29.picture.LoadFromFile('wasser.jpg');
if a[5][5]=1 then image29.picture.LoadFromFile('schuss.jpg');
if a[5][5]=2 then image29.picture.LoadFromFile('schiff.jpg');
if a[5][5]=3 then image29.picture.LoadFromFile('wrack.jpg');

if a[5][6]=0 then image30.picture.LoadFromFile('wasser.jpg');
if a[5][6]=1 then image30.picture.LoadFromFile('schuss.jpg');
if a[5][6]=2 then image30.picture.LoadFromFile('schiff.jpg');
if a[5][6]=3 then image30.picture.LoadFromFile('wrack.jpg');


end;

procedure TForm1.Button1Click(Sender: TObject);

begin
randomize;

for i:=1 to 5 do
  for j:=1 to 6 do
      a[i][j]:=0;

k:=1;
while (k<=5) do
begin
i:=random(5)+1;
j:=random(6)+1;
  if a[i][j]=0 then
  begin
  a[i][j]:=2;
  k:=k+1;
  end;

anzeige();

  end;
  end;



procedure TForm1.Button2Click(Sender: TObject);

begin
k:=1;
i:=strtoint(edit1.Text);
j:=strtoint(edit2.text);
if a[i][j]=0 then
while (k<=5) do
  begin
  a[i][j]:=2;
  k:=k+1;
  end;

anzeige();

  end;


end.
  Mit Zitat antworten Zitat