can I replace a 2n2222 transistor with a tip31c
It should work if you get the pinning correct. The TIP31C is generally going to be lower current gain than the 2N2222 so it will require a higher base current for a given load.

If your small motor load is a low current device truly compatible with the ratings of the 2N2222 then I see no reason that would keep you from trying the TIP31C.