
Electronic Games • Chapter 22 435
Wait(100);
n++;
}
The variable error goes to 1 when check_sequence detects a mistake in the
user’s input, thus forcing the termination of the program, while n represents the
length of the sequence. MAX is a constant corresponding to the dimension of
the array, representing the maximum length of the sequence.
The generate sequence routine fills the array with random values in the range
0 to 2. In our example, we associated values of 0, 1, or 2 to the colors green, blue,
and red, respectively.
void generate_sequence()
{
int i;
for (i=0;i<MAX;i++)
{
seq[i]=Random(2);
}
}
The play_sequence subroutine needs little explanation. It plays ...