Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 23, 2016
1 parent 3951619 commit 030b40b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion book/mydance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- Make the turtle dance!

print('Hello world!')
for i = 1, 10 do
for i = 1, 8 do
-- turn based on random number
if math.random(1, 2) == 1 then
print('Turn to the left!')
Expand All @@ -14,3 +14,4 @@ for i = 1, 10 do
turtle.turnRight()
end
end
print('Done.')
12 changes: 6 additions & 6 deletions book/mydance2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ isBack = false

print('Hold Ctrl+T to stop dancing.')
while true do
randomNum = math.random(1, 5)
moveType = math.random(1, 5)

if randomNum == 1 then
if moveType == 1 then
-- turn left
print('Turn to the left!')
turtle.turnLeft()

elseif randomNum == 2 then
elseif moveType == 2 then
-- turn right
print('Turn to the right!')
turtle.turnRight()

elseif randomNum == 3 then
elseif moveType == 3 then
-- forward/back moves
if isBack then
print('Move forward!')
Expand All @@ -32,7 +32,7 @@ while true do
isBack = true
end

elseif randomNum == 4 then
elseif moveType == 4 then
-- up/down moves
if isUp then
print('Get up!')
Expand All @@ -44,7 +44,7 @@ while true do
isUp = true
end

elseif randomNum == 5 then
elseif moveType == 5 then
-- spin around
print('Spin!')
for i = 1, 4 do
Expand Down

0 comments on commit 030b40b

Please sign in to comment.