mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Explain the data format better and give better variable names
This commit is contained in:
@@ -50,21 +50,29 @@ def play():
|
|||||||
# Interpretting a stream of data is a very common software task. We've already intepretted
|
# Interpretting a stream of data is a very common software task. We've already intepretted
|
||||||
# the first 5 numbers as letters of the alphabet (with A being 1). Now, we are going to
|
# the first 5 numbers as letters of the alphabet (with A being 1). Now, we are going to
|
||||||
# combine this with a different interpretation of the following data to draw on the screen.
|
# combine this with a different interpretation of the following data to draw on the screen.
|
||||||
|
# The drawing data is essentially a series of horizontal line segments given as begin and end
|
||||||
|
# offsets.
|
||||||
while True:
|
while True:
|
||||||
x = next(data)
|
command = next(data)
|
||||||
|
|
||||||
if x < 0:
|
if command < 0:
|
||||||
print()
|
print()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if x > 128:
|
if command > 128:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Skip x spaces
|
# If we've reached this portion of the code, 'command' indicates the 'start'
|
||||||
print(tab(x), end="")
|
# position of a line segment.
|
||||||
y = next(data)
|
start = command
|
||||||
|
# Position cursor at start
|
||||||
|
print(tab(start), end="")
|
||||||
|
|
||||||
|
# The following number, indicates the end of the segment.
|
||||||
|
end = next(data)
|
||||||
# Unlike FOR I=X TO Y, the 'stop' argument of 'range' is non-inclusive, so we must add 1
|
# Unlike FOR I=X TO Y, the 'stop' argument of 'range' is non-inclusive, so we must add 1
|
||||||
for i in range(x, y+1, 1):
|
for i in range(start, end+1, 1):
|
||||||
|
# Cycle through the letters in "BUNNY" as we draw this line
|
||||||
j = i - 5 * int(i / 5)
|
j = i - 5 * int(i / 5)
|
||||||
print(chr(L + bunny[j]), end="")
|
print(chr(L + bunny[j]), end="")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user