Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Main Program
- print("running Program !")
- CycleSquareRoom()
- --Functions
- function CycleSquareRoom() --spirals through a n*n square room
- print("please define the length of your Square rooms sides")
- local sides = read()
- print("please define a turning direction [left or right]")
- local dir=read()
- print("turning" ..dir)
- local turns=sides-2
- local mov=sides-1
- local reqFuel = 0
- reqMoves(mov)
- if turtle.getFuelLevel()>reqFuel then
- while turns>0 and mov>1 do
- for i =0, turns do
- moveNForward(mov)
- turns = turns-1
- mov = mov-1
- turn(dir)
- print("turned " ..dir)
- end
- inturn(dir)
- end
- else
- print("Not enough Fuel !")
- end
- end
- function turn(turndir) --turns the defined way
- if turndir == "right" then turtle.turnRight()
- else turtle.turnLeft() end
- end
- function invturn(turndir) --turns the other way
- if turndir == "left" then turtle.turnRight()
- else turtle.turnLeft() end
- end
- function moveNForward(n) --moves n blocks forward
- print("moving " ..n.. " blocks")
- if n~=nil then
- n = tonumber(n)
- for i = 0, n do
- turtle.forward()
- end
- else
- print("no input specified")
- end
- end
- function reqMoves(n) --calculates the amount of moves and fuel required
- while n>0 do
- reqFuel = reqFuel+(n-1)*n
- n = (n-1)
- end
- print(reqFuel.." moves are required")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement