-(*Path) find_horizontal_path_x: (int) newx and_y: (int) newy { // Where the piece is currently. // Piece wants to goto: (newx, newy). int oldx = [self x]; int oldy = [self y]; // Create a Path object, see Path.h for description. Path *path = [[path alloc] init]; // dx, dy are the differences between newx and oldx, etc. int dx = 0; int dy = 0; // Some variables int px = 0; int py = 0; // Try to establish which direction (horizontally) the piece is moving. if ( oldy == newy ) { // Check there is no vertical movement if ( oldx > newx ) { // Must be moving to left px = oldx; py = oldy; dx = oldx - newx; while ( dx > 0 ) { px--; dx--; [path add_coordinate_x: px and_y: py]; } return path; } else { if ( oldx < newx ) { // Must be moving to the right px = oldx; py = oldy; dx = newx - oldx; while ( dx > 0 ) { px++; dx--; [path add_coordinate_x: px and_y: py]; } return path; } else { // oldx == newx ? NSLog ( @"There must be an error." ); break; } } } else { // Seems to be vertical movement NSLog ( @"There must be an error." ); break; } // If this code is being executed it's because there's an error. return nil;