C64 Workshop Part 1

Creating a High/Low Game

A high/low game is my favourite “first project” when learning a language. We have to figure out: input, output, randomness, if/then logic, and comparisons.

Objective

Create a high/low game where the user must guess a number between 1 and 100 (or higher).

Requirements

Bonus


Resources / Reference

PRINT

Outputs text.

Example:

10 PRINT "HELLO WORLD"

IF

Checks a condition, if true, executes code after “THEN”.

Examples:

10 A=10
20 IF A>10 THEN PRINT "!!!"
30 IF A<10 THEN PRINT "..."
40 IF A=67 THEN PRINT "67!"
50 IF A<>10 THEN PRINT "NOT 10"

GOTO

Jump to the specified line number.

Example:

10 PRINT "INFINITE LOOP"
20 GOTO 10

RND

Generates a random number between 0.0 and 1.0 in different modes.

For more information see: c64-wiki.com/wiki/RND

Examples:

10 X=RND(-TI)
20 PRINT INT(RND(1)*100)

First line initializes the random seed. Second line generates a random number between 0 and 99 (inclusive).

2 extra commands are used here “TI” for “time), and “INT” to round our number down to a whole number. We make time negative to select a random number set on the C64.

INPUT

Gets input from the keyboard until <Enter> is pressed.

Example:

10 INPUT "GUESS"; A%
20 PRINT A%

CHR$

Outputs a single character (useful for control codes like changing text colour).

Example:

10 PRINT CHR$(28)"RED"CHR$(5)

Outputs “RED”, because of CHR$(5) all following outputs will be white.

Colour Codes

Colour Code Colour Code
White CHR$(5) Orange CHR$(129)
Red CHR$(28) Black CHR$(144)
Green CHR$(30) Brown CHR$(149)
Blue CHR$(31) Light Red CHR$(150)
Grey 1 CHR$(151) Grey 2 CHR$(152)
Light Green CHR$(153) Light Blue CHR$(154)
Grey 3 CHR$(155) Purple CHR$(156)
Yellow CHR$(158) Cyan CHR$(159)

Next: Part 2 - Drawing Graphics | Back to Home