Sinclair QL Beginner's Manual page 102

Hide thumbs Also See for QL:
Table of Contents

Advertisement

MULTIPLE DECISIONS - SELect
Where there are three or more possible actions and none is dependant on a previous choice the
natural structure to use is SELect which enables selection from any number of possibilities.
EXAMPLE
A magic snake grows without limit by adding a section to its front. Each section may be up to twenty
units long and may be a new colour or it may remain the same. Each new section must grow in one of
the directions North, South, East, or West. The snake starts from the centre of the window.
Method
At any time while the snake is still on the screen you choose a random length and ink colour easily.
The direction may be selected by a number 1,2,3 or 4 as shown:
Design:
Select PAPER
Set snake to centre of window
REPeat
Choose direction, colour length of growth
FOR unit = 1 to growth
Make snake grow north, south, east or west
IF snake is off window THEN EXIT
END FOR
END REpeat
PRINT end message
Program:
100 REMark Magic Snake
110 PAPER 0 : CLS
120 LET across = 50 : up = 50
130 REPeat snake
140
LET direction = RND(l TO 4) : colour = RND(2 TO 7)
150
LET growth = RND(2 TO 20)
160
INK colour
170
FOR unit = 1 TO growth
180
SELect ON direction
190
200
210
220
230
240
250
260
ON direction = 1
LET up = up + 1
ON direction = 2
LET across = across + 1
ON direction = 3
LET up = up - 1
ON direction = 4
LET across = across - 1

Advertisement

Table of Contents
loading

Table of Contents