How can I design a finite state machine that counts according to this sequence?
I'm going to try to answer your question as you asked it rather than suggest something completely different than what you want to do. I will outline a general design approach for this kind of sequential circuit.

You will need one truth table for each flip-flop. The inputs to the truth table are the outputs of all flip-flops as well as the X input. The entries in the truth table cells are the desired next state for the given flip-flop. The output of the combinational block that you design with this truth table will be connected to the D input of the flip-flop.

Analyze each flip-flop separately and design the combinational logic for each flip-flop's D input independently. Once you become more comfortable with this technique you will start to see simplifications, but you should begin with the basic brute-force technique.