Review – Usborne Computer Battlegames.

November 30th, 2013

Another review, this time one with lots of code to test out.  This time we’re doing Computer Battlegames.

IMG_4504_1

This book is full of BASIC programs to be entered, 13 in all,  although the last one involves graphics and there are separate listings for each computer for that one.

After a quick double page introduction to the book and comments about entering, debugging and running the programs we jump straight into them.

To avoid having large chunks of listings in these reviews I have instead made the listing available as a ZIP file here:

http://www.asciimation.co.nz/UsborneBookReviews/

The first listing…

IMG_4505_1

Robot Missile.

Apparently the humans are at war with the robots! Not the friendly ones who teach us how to code in these books I hope? This program is very simple.  It just chooses a random letter then you have 4 guesses to find out what it is with the computer telling you if the guess is before or after the letter.

Nothing hard to do here although all these listings are for the ZX81 with modifications for all the other machines. unfortunately the ZX81 doesn’t use standard ASCII codes so in all these listings whenever an ZX81 code is used you have to change the code used in the listing to the proper ASCII value.

IMG_4543_1

Throughout the book the listings are marked with little symbols next to some lines. These indicate the lines that are different on different machines.

IMG_4529_1

Next up…

IMG_4506_1

The Vital Message.

Next up we have The Vital Message. This is another very simple game.  It creates a list of random letters that you have to then enter in. Apparently all it takes to stop a war is entering in the proper simple code. This game uses the CLS command to clear the screen after displaying the code to you so you must remember it then type it in correctly.

IMG_4507_1

Shootout.

Next up we have Shootout. This one was interesting because on line 110 I hit a command Orwell didn’t support. That is the INKEY$ command.  Unlike INPUT which waits for you to enter some keys and then hit return the INKEY$ command checks immediately if any key is being pressed on the keyboard. I had to add that functionality into MS Basic running on Orwell.

Since INKEY$ is a function (although it needs no user input) I basically copied how the CHR$ function was done in the code.  It has to be a function since INKEY$ needs to return a value. Being a function you do have to specify an input parameter even though it isn’t actually used.

MS Basic doesn’t seem to handle empty strings as you would expect. If you enter a command like A$ = “” then try to compare A$ with “” it doesn’t return true. If you try to get the ASCII value of it with ASC() you get an error. Getting the length with LEN() will return 0. I did try creating an empty string in the code if no key was pressed but that seemed to cause issues so my INKEY$ function will always create a 1 character string (as does CHR$()).

So my INKEY$ will always return a length of 1 and, if no key is pressed, an ASCII value of 0.

Since I can’t seem to do a comparison against an empty string directly the way to check if a key is pressed is to look at the ASCII value and see if it is non zero:

IF ASC(INKEY$(0)) <> 0 THEN a key is pressed….

That seems to work very well.

IMG_4531_1

IMG_4508_1_1

Desert Tank Battle.

Next we have a game that uses some of the maths functions, namely SIN and ABS.  Again a simple little game that worked first time. It is another of the enter some values and it tells you how close you are games.

IMG_4509_1

Battle at Traitor’s castle.

Now this game proved interesting. There is a bug in the listing! Line 130 is supposed to check if the key you pressed matches the position of the O character in a line of dots (battlements – these games need some imagination). The code reads:

130 IF VAL (“O”+I$) = T THEN GOTO 170.

I$ is the key returned from INKEY$. T is the position of the O. VAL() returns a numeric value of a string. So if you press the “1” key it returns 1 as a number. Why they had “O” in the VAL I don’t know.

IMG_4532_1

IMG_4510_1

Robot Invaders.

This one was interesting. There isn’t anything new here but it was this listing that showed up the bug in my INKEY$ function when trying to return a zero length string. It’s interesting to note the previous listing also used INKEY$ but that worked. This one didn’t and it’s something to do with the fact that INKEY$ is called in a loop.  After the first time through the loop the P$ variable was being overwritten (I think) and so was lost. P$ is the random letter the code was generating to represent a robot to ‘shoot’ by matching it with a key press. I don’t fully understand why it broke yet but it works now.

It’s tricky to take a photo of this game as what it does is display a random letter in a random spot on the screen which you have to match. It clears the screen between each one.

IMG_4511_1

Secret Weapon.

Next up is secret weapon. Not much to say about this one. It’s another guess the values one but with two values. It tells you if you are close or not. This code is my first use of the SQR() function.

IMG_4535_1

IMG_4512_1

Escape.

This is another guess the random number type game. Nothing special here.

IMG_4513_1

Pirate Dogfight.

This game is a little more interesting as you have to match speed and distance in real time. It keeps looping reading your input and showing you the effect. You press keys adjusting your position until leven then you fire. It clears the screen between updates so there isn’t much to photograph!

IMG_4514_1

Supersonic Bomber.

This game is a little different and it uses dimensioned arrays. It randomly generates targets and you press the appropriate key to bomb the correct target. It uses a reverse FOR loop to count down and reduce the time you have between goes as the game progresses.

IMG_4536_1

IMG_4515_1

Iceberg.

This game uses a 2 dimensional array. It draws a simple grid and you maneuver about inside it trying to get an enemy ship, that always moves directly toward you, to crash into an iceberg. Asterixis represent icebergs. As the book says, strangely the enemy ship can see you but not these whacking great icebergs in front of it. I think perhaps it is better to think of the * as mines it doesn’t know about that you are trying to get it to crash into.

IMG_4538_1

There are actually some un-winnable start positions in this game as the one above shows. You (Y for you) can only move in four directions but they (Z for ‘ze robots’?) can move in eight so can get you on the diagonals. This is however one of the better games in the book.

IMG_4516_1

IMG_4517_1

The Wizard’s Wall.

This game was a bit more typing. Mainly all the bloody text of the instructions! It is the first game in the book to use GOSUBs. Again it is really just a guess the numbers type thing but it uses some tricky maths to spice things up a bit. Being so big (almost 2.5k!) it took some time for me to load the game in since I echo all the loading to the screen which really slows things down. I have started working on a silent load function which should be much faster.

IMG_4539_1

The final game in the book is different to all the rest as it uses graphics (well, simple ones). There  are separate listings for each computer. Unfortunately Orwell doesn’t support graphics (yet!) so this one will have to wait until then.

Finally the book gives some tips on adding to the programs as well as information on writing your own. Then if has a fairly good summary of BASIC commands.  We then have an ASCII chart (and a ZX81 chart with it’s silly values).

There is also this handy conversion chart for the different versions of Basic each machine uses.

IMG_4518_1

Conversion chart.

Finally we have answers to some of the questions and puzzles asked in the book along with snippets  of code for some of them. We also have a further reading section as a lot of these books do. The books mentioned are:

This was a fun book. Most of the programs are quick to enter but there are a lot of guess the number type ones. It will be interesting to see if it’s companion book, Computer Spacegames, is similar.

From Orwell’s point of view it was good since we got a new command implemented (INKEY$) and I learnt a little more about the internals of MS Basic. It also showed the need for a faster loading function with the longer programs which I shall continue to work on now.

4 Responses to “Review – Usborne Computer Battlegames.”

  1. david Says:

    Iceberg seems like an early version of the Unix Robots game. I wonder which came first?

    http://en.wikipedia.org/wiki/Robots_(BSD_game)
    http://ctho.org/games/robots/

  2. Simon Says:

    That must have been first and the BASIC game is a simplified version. I remember playing the Dalek version but I can’t remember what on. Must be age!

  3. Asciimation » Blog Archives » Review – Usborne Computer Spacegames. Says:

    […] finally another review. This time it’s the partner book to Computer Battlegames. But now we’re IN […]

  4. Euhill Says:

    At least you implemented the INKEY$ statement. Apple I/II and Commodore 64 and possibly other home computers that were based on the 6502 didn’t support that statement in their BASIC. Instead they had the less useful GETCH statement to get a single keystroke. The problem with it is that it behaved more like the INPUT statement and would stop the programs execution until you pressed a key. Makes it difficult to make real time games. They only way around the problem would have been to make a machine language subroutine for real time keyboard polling on those machines.