Code: Select all
ScreenRes 790, 350, 16
Dim x As Integer, y As Integer, buttons As Integer, x1 As Integer, y1 As Integer, i as integer
Dim grida(100) As Integer
Dim gridb(100) As Integer
Dim destroyer As Integer
Dim submarine As Integer
Dim cruiser As Integer
Dim battleship As Integer
Dim carrier As Integer
Dim background As Any Ptr = ImageCreate( 800, 450 )
Dim hdestroyer As Any Ptr = ImageCreate( 60, 30 )
Dim hsubmarine As Any Ptr = ImageCreate( 90, 30 )
Dim hcruiser As Any Ptr = ImageCreate( 90, 30 )
Dim hbattleship As Any Ptr = ImageCreate(120, 30 )
Dim hcarrier As Any Ptr = ImageCreate( 150, 30 )
Dim vdestroyer As Any Ptr = ImageCreate( 30, 60 )
Dim vsubmarine As Any Ptr = ImageCreate( 30, 90 )
Dim vcruiser As Any Ptr = ImageCreate( 30, 90 )
Dim vbattleship As Any Ptr = ImageCreate( 30, 120 )
Dim vcarrier As Any Ptr = ImageCreate( 30, 150 )
Dim white As Any Ptr = ImageCreate( 8, 8 )
Dim red As Any Ptr = ImageCreate( 8, 8 )
Dim hit As Any Ptr = ImageCreate( 25, 12 )
Dim miss As Any Ptr = ImageCreate( 37, 12 )
Bload "background.bmp", background
put (0,0),background
Bload "hdestroyer.bmp", hdestroyer
Bload "hsubmarine.bmp", hsubmarine
Bload "hcruiser.bmp", hcruiser
Bload "hbattleship.bmp", hbattleship
Bload "hcarrier.bmp", hcarrier
Bload "vdestroyer.bmp", vdestroyer
Bload "vsubmarine.bmp", vsubmarine
Bload "vcruiser.bmp", vcruiser
Bload "vbattleship.bmp", vbattleship
Bload "vcarrier.bmp", vcarrier
Bload "white.bmp", white
Bload "red.bmp", red
' Put (x * 30 + 391, y * 30 + 51), red
' Put (x * 30 + 51, y * 30 + 51), red
Bload "hit.bmp", hit
'Put (710,270), hit
Bload "miss.bmp", miss
Put (704,270), miss
Do
'wait for a button press to choose a ship to place on the grid
Do While buttons = 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
'destroyer
If x > 704 And x < 728 And y > 6 And y < 68 And destroyer = 0 Then
destroyerstart:
'wait while the mouse button is down
Do While buttons > 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
'wait for a button press to place the destroyer on the grid
Do While buttons = 0 and x > 1: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
'place a horizontal destroyer
If x > 380 And x < 680 And y > 40 And y < 340 And buttons And 1 Then
'convert x and y from the mouse to 0 to 9 for the grid
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
'make sure the ship isn't going to be placed of the grid
if x1 > 8 then goto destroyerstart
'make sure that the destroyer won't be placed onto another ship by looking into the grid B array
for i = 0 to 1
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto destroyerstart
next i
'put the destroyer image onto the grid
Put (x1 * 30 + 380, y1 * 30 + 40), hdestroyer
'put two 1's in the grid B array to represent the destroyer
for i = 0 to 1
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
'place a vertical destroyer
elseIf x > 380 And x < 680 And y > 40 And y < 340 And buttons And 2 Then
'convert x and y from the mouse to 0 to 9 for the grid
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
'make sure the ship isn't going to be placed of the grid
if y1 > 8 then goto destroyerstart
'make sure that the destroyer won't be placed onto another ship by looking into the grid B array
for i = 0 to 10 step 10
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto destroyerstart
next i
'put the destroyer image onto the grid
Put (x1 * 30 + 380, y1 * 30 + 40), vdestroyer
'put two 1's in the grid B array to represent the destroyer
for i = 0 to 10 step 10
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
'go back and try again if the ship was unable to be place in the chosen place
else
goto destroyerstart
End If
'place a 1 in the variable to make sure no more then one destroyer is place on the grid
destroyer = 1
'submarine
ElseIf x > 705 And x < 729 And y > 163 And y < 254 And submarine = 0 Then
submarinestart:
Do While buttons > 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
Do While buttons = 0 and x > 1: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
If x > 380 And x < 680 And y > 40 And y < 340 And buttons And 1 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if x1 > 7 then goto submarinestart
for i = 0 to 2
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto submarinestart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), hsubmarine
for i = 0 to 2
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
elseIf x > 380 And x < 680 And y > 40 And y < 340 And buttons And 2 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if y1 > 7 then goto submarinestart
for i = 0 to 20 step 10
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto submarinestart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), vsubmarine
for i = 0 to 20 step 10
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
else
goto submarinestart
End If
submarine = 1
'cruiser
ElseIf x > 705 And x < 729 And y > 70 And y < 161 And cruiser = 0 Then
cruiserstart:
Do While buttons > 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
Do While buttons = 0 and x > 1: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
If x > 380 And x < 680 And y > 40 And y < 340 And buttons And 1 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if x1 > 7 then goto cruiserstart
for i = 0 to 2
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto cruiserstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), hcruiser
for i = 0 to 2
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
elseIf x > 380 And x < 680 And y > 40 And y < 340 And buttons And 2 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if y1 > 7 then goto cruiserstart
for i = 0 to 20 step 10
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto cruiserstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), vcruiser
for i = 0 to 20 step 10
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
else
goto cruiserstart
End If
cruiser = 1
'battleship
ElseIf x > 754 And x < 777 And y > 162 And y < 285 And battleship = 0 Then
battleshipstart:
Do While buttons > 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
Do While buttons = 0 and x > 1: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
If x > 380 And x < 680 And y > 40 And y < 340 And buttons And 1 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if x1 > 6 then goto battleshipstart
for i = 0 to 3
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto battleshipstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), hbattleship
for i = 0 to 3
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
elseIf x > 380 And x < 680 And y > 40 And y < 340 And buttons And 2 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if y1 > 6 then goto battleshipstart
for i = 0 to 30 step 10
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto battleshipstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), vbattleship
for i = 0 to 30 step 10
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
else
goto battleshipstart
End If
battleship = 1
'carrier
ElseIf x > 752 And x < 778 And y > 12 And y < 162 And carrier = 0 Then
carrierstart:
Do While buttons > 0: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
Do While buttons = 0 and x > 1: GetMouse (x, y, , buttons): Locate 1,1: Print Using "### : ### : # "; x; y; buttons: Sleep 10: Loop
If x > 380 And x < 680 And y > 40 And y < 340 And buttons And 1 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if x1 > 5 then goto carrierstart
for i = 0 to 4
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto carrierstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), hcarrier
for i = 0 to 4
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
elseIf x > 380 And x < 680 And y > 40 And y < 340 And buttons And 2 Then
x1 = Val(Left(Str((x - 380) / 30), 1))
y1 = Val(Left(Str((y - 40) / 30), 1))
if y1 > 5 then goto carrierstart
for i = 0 to 40 step 10
if gridb(i + (x1 + 1) + (10 * y1)) > 0 then goto carrierstart
next i
Put (x1 * 30 + 380, y1 * 30 + 40), vcarrier
for i = 0 to 40 step 10
gridb(i + (x1 + 1) + (10 * y1)) = 1
next i
else
goto carrierstart
End If
carrier = 1
'start or maybe restart button
ElseIf x > 695 And x < 782 And y > 293 And y < 315 And buttons And 1 Then
'quit button
ElseIf x > 695 And x < 782 And y > 320 And y < 342 And buttons And 1 Then
end
End If
'loop while the mouse button is down
GetMouse (x, y, , buttons)
Do While x > 1 And buttons And 1: GetMouse (x, y, , buttons): Sleep 10: Loop
Sleep 20
'if all the ships are placed then....
if destroyer = 1 and submarine = 1 and cruiser = 1 and battleship = 1 and carrier = 1 then
'Done setting ships
end if
Loop
ImageDestroy( background )
ImageDestroy( hdestroyer )
ImageDestroy( hsubmarine )
ImageDestroy( hcruiser )
ImageDestroy( hbattleship )
ImageDestroy( hcarrier )
ImageDestroy( vdestroyer )
ImageDestroy( vsubmarine )
ImageDestroy( vcruiser )
ImageDestroy( vbattleship )
ImageDestroy( vcarrier )
ImageDestroy( red )
ImageDestroy( white )
ImageDestroy( hit )
ImageDestroy( miss )
'Make and save grid image
'For x = 10 To 340 Step 30
' Line (x, 10)-(x, 340), &h3366FF
' Line (x + 340, 10)-(x + 340, 340), &h3366FF
'Next x
'For y = 10 To 340 Step 30
' Line (10, y)-(340, y), &h3366FF
' Line (350, y)-(680, y), &H3366FF
'Next y
'Bsave "background.bmp", 0
http://www.mediafire.com/?mntv5d4ypbd