The character flips fine but only in one way.
# private void flip(int x)
# {
# // int flip = 0; (you've already got "x")
# for (int i = 1; i <= 8; i++)
# {
# if(x > 0) // (use x since you chose it)
# {
# setRotation(getRotation() + 45);
# wait(10);
# }
# if (x < 0)
# {
# setRotation(getRotation() - 45);
# wait(10);
# }
# }
# }