Batten down the hatches as you fight it out with your Amstrad CPC 464 in Battleships by Steve Lucas This is a computerised version of the familiar game of Battleships in which you and your opponent hide five ships on a nine by nine grid. Each location on the grid is given a co-ordinate name such as A4 (letter first) and you must take turns with your opponent (the computer) to fire torpedoes at your opponents grid. The winner is the one who sinks all their opponents ships first. When typing in this program, take care to distinguish between the variable 1 Cower case L) and the number 1. I decided to make the computer play a rather dumb game so as to give you (the player) a chance of winning! You could make the game more difficult by altering the routine which searches for your ships (Lines 1980-2150). Program Notes Conversion The program makes use of many special commands available in Amstrad Basic. The While Wend loop could be replaced with either a Repeat Until loop or a conditional Goto. Note that the While Wend loop checks for the condition at the start of the loop, whereas a Repeat Until loop checks the condition at the end of the loop. Lower$ converts a variable to lower case, while Upper$ converts a stnng to upper case. Locate X, Y moves the text cursor to position X, Y. This is equivalent to Print Tab (X, Y) on the BBC. Print At on the Spectrum and Plot x, y, AS on the Oric. Ink is used to select the four colours available in the palette for Mode 1, a 40 column mode. Paper and Pen choose foreground and background colours from the Inks available. The Amstrad interprets upper case and lower case variables as being identical Variables - cc holds computer score
- yc holds your score
- a$(x,y) holds your board
- b$(x,y) holds computer's board
- c$(x) holds names of ships
- d$(x) holds mput co-ordinates
- xl,yl,x,y hold co-ordinates
- l,p, hold length of ships
Line No.- 10-50 selects mode/colours
- 60 titles/instructions
- 70-170 dim arrays'reads ships
- 180-320 draws board
- 330-470 program control
- 490-610 instructions
- 620-1000 sets up computer's board
- 1010-1070 checks array
- 1080-1120 fills array
- 1130-1480 sets up your board
- 1510-2150 fires torpedoes
PopularComputingWeekly841115 |