BATTLESHIPS
by Paul Kettlewell
from Home Computing Weekly, 23rd October 1984


Danger on the high seas

Do you want to command your own fleet? Paul Kettlewell's program gives
you the chance to be a war hero, but watch out, the enemy gives as
good as it gets.


This version of the pencil and paper game Battleships engages you and
the ever-hostile ZX81 in a battle of naval strategy. After running the
program the computer goes into FAST mode for about one minute allowing
admirals to finish their game of bowls.

Both fleets consist of:
* two battleships length four units BBBB
* two cruisers length three units CCC
* two destroyers length two units DD
* four submarines length one unit S
These must be anchored in a grid of 10*10 units. Ships may be placed
horizontally, vertically or diagonally. However, different ships may
not occupy adjacent squares (including those diagonally adjacent).

On the prompt "Position of stern?" the co-ordinates of one of the ends
of the ship should be entered, then the direction after the "Direction?"
prompt. The possible directions are given by the compass in the right-
hand window. For example, to place a battleship in squares A1, B2, C3,
D4 you can either put the stern in A1 by entering "A1" then direction
"4" or position "D4" followed by direction "8". This is repeated until
your fleet is safely anchored.

However, the tranquility is soon broken when a shell is fired at your
ships. If this unprovoked first shot misses it will fall harmlessly
into the sea and will be marked as a miss with a grey graphic; if a
ship is hit by the shell the letter becomes the inverse letter.

On the command FIRE you must retaliate by selecting a square on your
opponent's grid, as yet blank, and enter it as before "letter number".
If the square becomes grey you have missed, or if it becomes an
inverse letter you have a hit.

The two of you now take turns to unleash deadly missiles on each
other. Submarines are sunk after one hit, though larger ships require
a hit on each unit of their length before they are destroyed.

Note:
* Once a ship is destroyed the area around the ship is filled with
  grey since you are not allowed to occupy adjacent squares.
* If you fire at a square which has already been eliminated you will
  be informed that you are wasting ammunition.

The winner is the first to completely destroy the opposing fleet.


Variables

A(4,10,10) hold computer's and player's grids
B$ player's input
C(2) number of ships each player has left
CC computer's "aim" mode
CD code of graphic
D direction
DO fixed direction
F flag set if ship will not fit into grid
G,H,I loop variables
L length of ship
LC length of ship computer is trying to destroy
X,XX,Y,YY co-ordinates
XC,YC previous co-ordinates at which computer fired
Z general purpose variable


How it works

  10- 170 set up computer's grid
  60      finds length and code of ship
  70-  90 random position and direction
 100- 160 try all directions, repeat until ship fits then fill grid
 210- 540 print screen
 560- 750 input position and direction from player
 760- 780 check to see if ship will fit
 790- 840 print ship
 860- 900 remove compass
 910- 970 remove markers from around ships which prevent ships touching
1000-1080 initialise variables
1090      changes player
1092-1094 if computer's go, choose co-ordinates
1095-1110 player inputs square
1120-1190 wasted shot routine
1200-1210 set array to show hit
1212-1225 print hit on screen
1230      if miss, changes player
1235      if computer hit, goes into search mode to look for rest of ship
1240-1295 test to see if ship is totally destroyed
1310-1330 reduce number of ships left, check if either side has won,
          remove computer from search mode
1360-1490 fill in spaces around ship
1500      next player's go
5000-5110 check to see if ship fits in grid
5150-5300 fill grid with code for ship, surround ship with "8" to
          prevent other ships touching it
5310-5330 return, setting F=1 if ship will not fit
5400-5470 find length L, code CD for ship type S
5500-5620 player's input, converted to co-ordinates
6000-6170 search for end of ship and give direction of ship from that end
6200-6260 count the number of units destroyed
7000-7060 choose random square to fire at
7070-7290 if only one part of ship hit, search around and select one
          possible direction ship could be in
7300-7370 if more than one part of ship destroyed, look for space at
          either end
7380-7400 return with co-ordinates
8000-8090 end of game routine


Hints on conversion

Conversion should not produce too many problems. Both grids need to be
printed. The codes used are 8 a miss, 39 B, 40 C, 41 D, 56 S and 128
added to each of these to get the inverse character.





DEVIL'S ISLAND
by Simon Trigg
from Home Computing Weekly, 23-29th October 1984


Escape from Devil's Island

In this program you're doomed to a life of imprisonment unless you can
outwit your captors and claim your freedom. Simon Trigg's exciting
game gives you a taste of life inside one of the world's most infamous
prisons.


This game is set in the notorious Devil's Island prison camp. Made
famous through films and books, you can now get an insider's view from
this computer program.

You must escape from your confinement and attain your freedom, but
it's no easy task. There are three different prison blocks from which
you must break out and you only have three chances, so take care.

There are guards prowling around who will stop at nothing to foil your
escape attempts, and each time you complete a screen another guard is
added, so it becomes progressively more difficult.

Just to make the game a bit more tricky, you can't go through a door
until a guard has opened it for you, so there are plenty of obstacles
in the way of your plans.

If you find Devil's Island security is foolproof and all your bids for
freedom end in failure, you can remove lines 496 and 615. This will
make you move faster so that you'll have more chance of success and
there is less likelihood that you'll have to endure life imprisonment.


Variables

a(1 to 10)  stores position of guards
k  holds amount of guards on screen
l  lives left
s  score
scr  screen you are on
x  determines which guards move
q,r  position of man
a$  row of characters used to read keyboard
z,y  distance between man and guards
m  count for number of guards


How it works

  10      goes to instructions and UDGs
  20-  30 set up variables
 100- 400 set up screen and print man on it
 440      reads keyboard
 445      jumps to routine which checks if guard has touched man
          if no key pressed
 450- 480 detect which key pressed and move man if space
 484- 490 check if collision between man and guards
 493      checks if man reached safety; if yes goes to congratulation
          routine
 494- 495 check distance between man and guards
 496- 615 move guards if space or door in front
 620      jumps back to keyboard scanning routine
1000-1075 print message, play tune, add up score, add 1 to screens
          completed, add extra guard, check if all three screens
          completed; if yes jumps to escape routine
1080      prints message, waits for key to be pressed, starts next
          screen
2000-2020 print escaped message, make noise, ask if want to play again
2030-2050 check if appropriate key pressed
3000-3020 print message, decrease lives, print attempts remaining,
          wait for a key press
8000-8110 print instructions
9000-9030 set up UDGs


Hints on conversion

This program takes advantage of the Spectrum's user defined graphics.
It would be best to rewrite it for any other micro because it uses
commands to search certain areas of the screen, such as SCREEN$ and
ATTR, which return the graphics and attributes of a character at that
position.

The BEEP command can easily be replaced, but other computers may have
a different PRINT AT screen; ie. instead of rows numbered 0 to 21 and
columns numbered 0 to 31 the screen might be numbered 1 to 512 and the
command PRINT @ might be used.

