Simple code moving forward

wrote some complicated code and it did not work at all

Never write complicated code.
Code may become complicated over time but you should never write more than about ten lines without testing. Only by building up the code and function can you ever hope to get it working. Debugging is easy as well because the fault is almost always in the code you have written since the last time you tested.
So concentrate on individual functions of the robot, write these as code functions and only then string them together.
Use of delay is fine as long as you know you can do nothing else until it is over. Most of the time however that is not the case.