• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# CC: exercise5_2

hevohevo May 18th, 2016 (edited) 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- exercise5_2
2. --  surround four directions with walls
3.
4. -- ####### Define a function ########
5. function placeSomeBlocks(n)
6.   for i=1,n do
7.     turtle.forward()  -- move to next position
8.     turtle.placeDown()  -- put a block in the ground
9.   end
10. end
11.
12. -- 一辺の長さが nagasa の正方形を作る
13. function makeSquare(nagasa)
14.   -- たとえば一辺7の正方形ならば、6個設置を4回繰り返す
15.   for i=1,4 do
16.     placeSomeBlocks(nagasa - 1)
17.     turtle.turnRight()
18.   end
19. end
20.
21. -- 天井を作る
22. function makeCeiling()
23.   turtle.turnRight()
24.   turtle.forward()
25.   turtle.turnLeft()
26.   turtle.forward()
27.   makeSquare(5)
28.
29.   turtle.turnRight()
30.   turtle.forward()
31.   turtle.turnLeft()
32.   turtle.forward()
33.   makeSquare(3)
34.
35.   turtle.turnRight()
36.   turtle.forward()
37.   turtle.turnLeft()
38.   turtle.forward()
39.   turtle.placeDown()
40. end
41.
42. -- ###### Main ########
43. turtle.select(1) -- the usual phrase
44.
45. turtle.up()  -- move up
46.
47. -- stack six squares
48. for ronoji=1,6 do
49.   -- 1st stage is made with slot 1, 2nd stage is slot 2, ...
50.   turtle.select(ronoji)
51.
52.   -- make 4 sides of a square
53.   makeSquare(7)
54.   turtle.up()  -- move up
55. end
56.
57. turtle.down()
58. makeCeiling()
RAW Paste Data
Top