1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116:
| type var CompFeld:Array[0..9,0..9] of string; zufallX,zufallY,richtung:integer;
procedure TForm1.NeuesSpiel1Click(Sender: TObject); var i,j:integer; begin StringGrid2.Enabled:=True; StringGrid2.color:=ClBlue; for i := 0 to 9 do begin StringGrid2.Cells[0,i]:=IntToStr(i); StringGrid2.Cells[i,0]:=IntToStr(i); for j :=0 to 9 do begin StringGrid2.Cells[i,j]:=''; CompFeld[i,j]:=''; end; end; randomize; Schiffsetzen(5); Schiffsetzen(4); Schiffsetzen(3); Schiffsetzen(3); Schiffsetzen(2);
end;
procedure TForm1.Schiffsetzen(Schiff:integer); var setzenmoeglich:boolean; i:integer; j:integer; begin repeat zufallX:=random(10); zufallY:=random(10); richtung:=random(2); setzenmoeglich:=true; if richtung = 1 then begin for i :=0 to schiff-1 do if CompFeld[zufallX+i,zufallY]<>'' then setzenmoeglich:=false; if zufallX+schiff-1 > 9 then setzenmoeglich:=false; end else begin for i :=0 to schiff-1 do if CompFeld[zufallX,zufallY+i]<>'' then setzenmoeglich:=false; if zufallY+schiff-1 > 9 then setzenmoeglich:=false; end; until setzenmoeglich=true; if setzenmoeglich=true then for j := 0 to schiff-1 do begin if richtung = 1 then CompFeld[zufallX+j,zufallY] := 'S' else CompFeld[zufallX,zufallY+j] := 'S'; end; if schiff = 5 then if setzenmoeglich =true then label1.caption:=IntToStr(StrToInt(label1.caption) + 1);
if schiff = 4 then if setzenmoeglich =true then label2.caption:= IntToStr(StrToInt(label2.caption) + 1); if schiff = 3 then if setzenmoeglich =true then label3.caption := IntToStr(StrToInt(label3.caption) + 1);
if schiff = 2 then if setzenmoeglich =true then label4.caption:= IntToStr(StrToInt(label4.caption) + 1);
end;
procedure TForm1.StringGrid2Click(Sender: TObject); var schuX,schuY:integer; begin labelklick.caption:=IntToStr(StrToInt(labelklick.caption) + 1); schuX:=StringGrid2.Col; schuY:=StringGrid2.Row; if CompFeld[schuX,schuY]='S' then begin CompFeld[schuX,schuY]:='T'; StringGrid2.Cells[schuX,schuY]:='T'; if MenschGewonnen then begin ShowMessage('Sie haben gewonnen!'); StringGrid2.Enabled:=False; Exit; end; end else begin if (CompFeld[schuX,schuY]='L') OR (CompFeld[schuX,schuY]='T') then begin showmessage('Da haben Sie schon mal hingeschossen!!!'); exit; end else begin StringGrid2.Cells[schuX,schuY]:='L'; CompFeld[schuX,schuY]:='L'; end; end; end;
end. |