Battleship 10Liner (C64) by romwer
A downloadable game
################################# # BASIC Tenliners Contest 2025 # # # # Battleship 10Liner # # (c) 2025 Roman Werner @romwer # # email: roman.werner@gmail.com # #################################
Battleship 10Liner is the interpration of the classic game Battleship (or "Schiffe versenken", "Seeschlacht", "Flottenmanöver" in German).
Note: To take into account the restrictions of 10 lines of code (PUR80) the ships are being placed horizontally only.
Task and Goal
=============
- There are 5 ships in 5 different sizes randomly placed in each grid:
1 *
2 **
3 ***
4 ****
5 *****
- You can see your own ships in the left grid but you cannot see the opponents ships yet (right grid).
- Try to locate and blast all ships in the enemy territory before the computer does on yours.
- Type in the coordinates, first the column a-j then <enter>, then the row 0-9 and <enter>.
- A successful hit will be shown as an asterisk (*) plus the color of the discovered ship, a miss will be shown as a circle.
- When you hit a ship then you have another turn before it goes back to the computer. And vice versa.
- If you manage to blast all 5 ships before the computer, then you have won the game.
Control:
========
keyboard keys a-j and 0-9. Confirm each entry with <enter>.
Game Requirements:
==================
- C64/C128* with BASIC 2.0 runtime environment (or compatible)
- 1 Player
*Also playable on Windows/MacOS/iOS/Android (C64 Emulator required)
Battleship BASIC program code:
==============================
0d=10:dIm(3,d,d):r=646:s=54272:u=40:m=1232:?"{clear}";:fOi=0to4.5stE.5:pO53280+i,15 1goS7:fOj=0toi:on-(m(p,x+j,y)>0orx+j>=d)gO1:nE:fOj=0toi:m(p,x+j,y)=i+1:nE:p=1-p 2nE:a(0)=160:a(1)=215:a(2)=170:t=5:goS8:p=1:t=21:goS8:w$(0)="lose!":w$(1)="win!" 3pO214,16:?:ifptH?"{dark gray} a-j";:inputx$:?" 0-9";:inputy:x=aB(aS(x$)-65):ifx>9ory>9gO3 4b=1-(m(p,x,y)>0):m(p+2,x,y)=b:goS6:x=x-(p=0):on-(b=2aNx<d)gO5:p=1-p:goS7:gO3 5p(p)=p(p)+1:on-(m(p+2,x,y)>0)goS7:on-(p(p)<15)gO3:?tA16)r$w$(p):pOk,0:wAk,1:rU 6o=m+int(y)*u+p*16+x:pOo,a(b):c=m(p,x,y):pOs+o*-(c>0),c:fOw=0to99:a=fR(0):nE:reT 7x=rN(0)*d:y=rN(0)*d:on-(m(p+2,x,y)>0)gO7:r$="{down*3}{dark gray} you ":reT 8x$=" ":?"{home}"tA16)"{dark gray}battleship{down*2}":?tAt+3)"abcdefghij{down}":fOj=0to9:?tAt)j;:fOi=0to9 9pOr,14-a:c=m(p,i,j):pOr+(c=0orp>0),c:?"{reverse on} {dark gray}";:a=8-a:nE:a=8-a:?:nE:k=198:reT
Tip: Copy/paste the program-Code into CBM prg Studio (http://www.ajordison.co.uk/).
There you can see the commands in nice color highlighting and you can directly execute the game in an emulator of your choice.
Battleship Tenliner explained (000=row 0/100=row 1/...):
========================================================
000 d=10 :rem constant for dimension
001 dimm(3,d,d) :rem 0-1=10x10 grids for ship position / 2-3=10x10 grids for hit/miss
002 r=646 :rem address for text color
003 s=54272 :rem constant - in addition with screen address becomes color ram
004 u=40 :rem constant - chars per row
005 m=1232 :rem constant - screen address for left grid to place hit via poke
006 print"{clear}"; :rem clear screen
007 fori=0to4.5step.5 :rem creates the outer loop as 0 0 1 1 2 2 3 3 4 4
008 poke53280+i,15 :rem set border and backkground color to light gray
100 gosub700 :rem get random x and y startposition for the 5 ships
101 for j=0 to i :rem for the length of the ship...
102 on-(m(p,x+j,y)>0orx+j>=d)goto100 :rem ...check if it can be placed there. if not get another position
103 next
104 forj=0toi :rem if it passes the check then
105 m(p,x+j,y)=i+1 :rem place the ship color
106 next
107 p=1-p :rem switch player grid so that both grids get random ships placed
200 next
201 a(0)=160 :rem inverse space
202 a(1)=215 :rem inverse circle
203 a(2)=170 :rem inverse asterisk
204 t=5 :rem tab position for first grid
205 gosub800 :rem draw left grid
206 p=1 :rem switch to right grid
207 t=21: rem tab position for second grid
208 gosub800 :rem draw right grid
209 w$(0)="lose!" :rem string array for end result
210 w$(1)="win!"
300 poke214,16 :rem mainloop start - place cursor on row 16
301 print :rem only works in combination with an empty print (makes it row 17)
302 ifpthenprint"{dark gray} a-j";:inputx$:print" 0-9";:inputy:x=aB(aS(x$)-65):ifx>9ory>9gO3 :rem when p=1 (right grid) then allow user input with some error handling
400 b=1-(m(p,x,y)>0) :rem if grid position contains a color then make b=2 (hit), otherwise b=1 (miss)
401 m(p+2,x,y)=b :rem assign value to hit/miss grid
402 gosub600 :rem show on grid
403 x=x-(p=0) :rem computer only: increase column position to fill a hit from left to right
404 on-(b=2andx<d)goto500 :rem if it was a hit and filler did not hit the right end, add 1 to the hit counter (15 wins the game)
405 p=1-p :rem switch player 0>1 1>0
406 gosub700 :rem get random x/y grid position for computer's next try
407 goto300 :rem mainloop end
500 p(p)=p(p)+1 :rem add 1 to the hit counter for the current player
501 on-(m(p+2,x,y)>0)gosub700 :rem computer only: if next x position already has a marker get new x/y
502 on-(p(p)<15)goto300 :rem go back to mainloop as long as the player has not reached 15 hits
503 printtab(16)r$w$(p) :rem print end result
504 pokek,0 :rem reset key buffer
505 waitk,1 :rem wait for key
506 run :rem restart game
600 o=m+int(y)*u+p*16+x :rem calculate screen offset
601 pokeo,a(b) :rem place character
602 c=m(p,x,y) :rem get ship value (=color)
603 pokes+o*-(c>0),c :rem only place color if value >0
604 forw=0to99 :rem wait loop
605 a=fre(0) :rem ... waste some time
606 next
607 return
700 x=rnd(0)*d :rem for x column get a value between 0 and 9
701 y=rnd(0)*d :rem for y row get a value between 0 and 9
702 on-(m(p+2,x,y)>0)goto700 :rem if this position already has a hit/miss marker, get new coordinates
703 r$="{down*3}{dark gray} you " :rem assign left string for end result message
704 return
800 x$=" " :rem initialize the x$ string to avoid input errors when player hits enter without value
801 print"{home}"tab(16)"{dark gray}battleship{down*2}" :rem print title
802 printtab(t+3)"abcdefghij{down}" :rem print grid colum header
803 forj=0to9 :rem for 9 rows
804 printtab(t)j; :rem print row number
805 fori=0to9 :rem for 9 grid cells
900 poker,14-a :rem set color to 14 (light blue) or 6 (dark blue)
901 c=m(p,i,j) :rem get ship color
902 poker+(c=0orp>0),c :rem if ship color exists then set ship color (but only for left grid)
903 print"{reverse on} {dark gray}";: rem print cell
904 a=8-a :rem toggle between 8 and 0
905 next
906 a=8-a :rem toggle again to start with the other color in the next row
907 print :rem place cursor into the next row
908 next
909 k=198 :rem constant for keyboard buffer
910 return
Trivia
======
- The game concept of Battleship was first documented in a russian's diary at world war I (1907). Played with pen and paper.
Published | 4 hours ago |
Status | Released |
Author | BASIC 10Liner |
Genre | Strategy |
Tags | 10liner, 8-Bit, basic, commodore, Commodore 64 |
Download
Install instructions
Starting in VICE: C64 emulator (http://vice-emu.sourceforge.net/):
================
Start the emulator and then drag and drop the "battleship.prg" into the VICE window.
-or-
Load the program with the command: load "battleship.prg",8
Then start the program with: run
Leave a comment
Log in with itch.io to leave a comment.