Usborne 1980s computer books helped many of today’s tech professionals were inspired by the Usborne computing books they read as children. The books included program listings for such iconic computers as the ZX Spectrum, the BBC Micro and the Commodore 64, and are still used in some computer clubs today.
Each of these Usborne books had endless examples of BASIC programs, each to be typed in by the user and modified with simple step by step instructions.
Robot Missile is a very simple code guessing game, where the player has 4 turns to guess the correct code to disarm the missile and win the game.
Here I’ve re-written the BASIC code into C, for no other reason than to so what it looks like written in C for a modern computer, including computers like the Raspberry Pi.
Usborne books still continue to publish books on many topics including programming using modern languages but on their website they also allow the old classic books to be downloaded for free, so if you want to play around with them click here.
/*
Robot Missile
The year is 2582 and the people of Earth are in the
midst of battle against the Robots. A lethal Robot
Missile has just landed and everyone is depending
on you to find the secret code which unlocks its
defuse mechanism. It you fail, the entire Earth
Command Headquarters will be blown up.
Your compute knows what the code letter is. You
must type in your guess and it will tell you whether
the code letter is earlier or later in the alphabet.
You have four chances to find the correct letter
before the missile blows up.
Compile: gcc -o robotm robotm.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
void exit(int status);
int main() {
int n, i, x;
char s;
time_t t;
i = 0;
x = 0;
n = 0;
system("clear");
printf("Robot Missile\n\n");
printf("Type the correct code\n");
printf("letter (A-Z) to defuse\n");
printf("the missle.\n\n");
printf("You have 4 chances\n");
srand((unsigned) time(&t));
n = 65 + rand() % 26;
while (x < 4) {
printf("ENTER CODE: ");
scanf(" %c", &s);
i = toupper(s);
if (i == n) {
printf("TICK...FZZZZ...CLICK...\n");
printf("YOU DID IT\n\n");
exit(0);
} else if (i < n) {
printf("LATER ");
} else if (i > n) {
printf("EARLIER ");
}
printf("THAN %c\n\n",s);
x++;
}
printf("BOOOOOOOOMMM...\n");
printf("YOU BLEW IT.\n");
printf("THE CORRECT CODE WAS %c\n\n",n);
return 0;
}