Autor Beitrag
Simu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 04.08.04 10:21 
Hallo
Bin ein Spiel am programmieren (Schiffe vesenken).
Meine Schiffe bestehen aus kreuzen:
XX
XXX
XXXX
XXXXX
XXXXXX

jetzt möchte ich das Computerfeld (StringGrid) automatisch und nach zufall mit diesen Schiffen bestücken.

Kann mir da jemand auf die Sprünge helfen wie ich das aufbauen muss?
Vielen Dank

Simu
cht
Hält's aus hier
Beiträge: 9

Win 98 SE, Win XP
D6 Prof
BeitragVerfasst: So 08.08.04 13:01 
etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
var 
  ShipLength, i, k:byte;
  ShipCounts:array[2..6] of Byte;
  position:TPoint;
begin

//ShipCounts mit Schiffs-Anzahlen füllen

//Schiffe positionieren
for ShipLength:=2 to 6 do
for i:=0 to ShipCounts[ShipLength] do begin
  if (RandomRange(0,1)=1) then begin  //horizontal
    position.x:=RandomRange(0,ComputerStringGrid.ColCount-ShipLength);
    position.y:=RandomRange(0,ComputerStringGrid.RowCount-1);
    for k:=0 to ShipLength-1 do
    ComputerStringGrid.Cells[position.x+k,position.y]:='X';
  end else begin  //vertikal
    position.x:=RandomRange(0,ComputerStringGrid.ColCount-1);
    position.y:=RandomRange(0,ComputerStringGrid.RowCount-ShipLength);
    for k:=0 to ShipLength-1 do
    ComputerStringGrid.Cells[position.x,position.y+k]:='X';    
  end;
end;

Jetzt musst du dich nur noch darum kümmern dass nicht mehrere Schiffe übereinander liegen. Ich will dir ja schließlich nicht die ganze Arbeit wegnehmen. :)

mfG

cht
Simu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 11.08.04 17:22 
Danke!!
Werd mich mal an die arbeit machen und schauen ob ich das kann....

War auch nicht meine Absicht dass ich den ganzen Code bekomme, nur eine Starthilfe..

Danke nochmal!!

mfg Simu
Simu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 17.08.04 08:03 
Hallo cht
Der Code funktioniert. Hab nur das Problem das die Schiffe nur Vertikal gesetzt werden und ich sehe nicht wiso :oops:

Kannst Du mir sagen an was dass das liegen kann?

Danke!!

mfg