BASIC Code

Hurkle.BAS

Click on the game window below in order to type.

Hurkle is a game created by Bob Albrecht for the People's Computer Company and included in David Ahl's "Basic Computer Games." You have five guesses to find the Hurkle on a 10x10 grid by inputting its X/Y coordinates separated by a comma as in 0,0.

The Listing

PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**                       HURKLE                         **"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**     As seen in David Ahl's BASIC Computer Games      **"
PRINT TAB(11); "**     Converted and refactored by Michael Coorlim      **"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**********************************************************"
PRINT:PRINT:PRINT

We're ditching program lines in favor of labels.

GUESSES = 5 : REM ## HOW MANY GUESSES WE GIVE THE PLAYER
GRID = 10 : REM ## GRID SIZE

We have two variables, Guesses and Grid, which govern how many guesses we get, and the size of our grid. We could use these to set up difficulty levels, if we felt like it.

?
?"The Hurkle is hiding on a ";GRID;" by ";GRID;" Grid. It is made up of points identified"
?"by X,Y coordinates designated by a pair of numbers separated by a comma."
?
?"The grid's origin, 0,0, is in the Southwest corner. You get ";GUESSES;" tries to guess"
?"the Hurkle's coordinates, and I'll tell you its approximate direction if you"
?"guess wrong."
?

I've rewritten the instructions to make it a little more clear what's expected of the player.

REM ## SET HURKLE COORDINATES
HIDE_HURKLE:
X = INT(GRID*RND(1))
Y = INT(GRID*RND(1))

Changing the Hurkle's location variables to X and Y.

REM ## GUESS LOOP
FOR K = 1 to GUESSES

REGUESS:
?"GUESS #";K;" (X,Y)";
INPUT GX%, GY%
GX = INT(GX%)
GY = INT(GY%)

IF GX < 0 OR GX > GRID or GY < 0 or GY > GRID THEN
	? "Each coordinate must be an integer between 0 and 9. Separate them with a comma. ":?
 	GOTO REGUESS
END IF

The program did not originally check to make sure that the player's guess was in-bounds, or even whether or not it was an integer. I've added some rails.

REM ## CHECK TO SEE IF YOU GUESSED RIGHT
IF ABS(GX-X)+ABS(GY-Y)=0 THEN GOTO CATCH_HURKLE

Our math to see if our guess matches Hurkle's X/Y coordinates. I left this as it was, even though it wasn't how I would have done it.

REM ## PRINT DIRECTION
? "The hurkle is to your ";
if GY<Y THEN ?"north";
if GY>Y THEN ?"south";
if GX<X THEN ?"east";
if GX>X THEN ?"west";
?".":?
NEXT K

I streamlined the directional reporting, using simple if/thens without subroutines.

REM ## FAILED TO FIND

?:?"Sorry, you have failed to find the Hurkle in ";GUESSES;" guesses."
?" The Hurkle was at ";X;",";Y

TRY_AGAIN:
?:?"Get ready to try again, the Hurkle is hiding."
?
GOTO HIDE_HURKLE

CATCH_HURKLE:
?:?"You found the Hurkle in only ";K;" guesses!"
GOTO TRY_AGAIN

It's a simple program, and even simpler once I streamlined it.

#David Ahl