Keep an active record of what state the door is in: closed, opening, open, and closing. Then, when you hit the navy control line, you just need to examine the state, and change it if necessary. Exact source code would depend on your implementation and idea. ^^