public void placeShip ( int row, int column, int shipType, int direction ) {

boolean a = true ;

if ( ( ( shipType > 4 ) || ( shipType < 0 ) ) == false ) {

// **********************************************************************************

// BATTLESHIP

if ( shipType == battleship ) {

if ( ( getCell ( row, column ) == water ) ) {

// UP

if ( direction == up ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 4 ; l ++ , x -- ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row - 1 , column, ship ) ;

editCell ( row - 2 , column, ship ) ;

editCell ( row - 3 , column, ship ) ;

}

// DOWN

} else if ( direction == down ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 4 ; l ++ , x ++ ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row + 1 , column, ship ) ;

editCell ( row + 2 , column, ship ) ;

editCell ( row + 3 , column, ship ) ;

}

// LEFT

} else if ( direction == left ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 4 ; l ++ , y -- ) {

if ( ( getCell ( row, y ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column - 1 , ship ) ;

editCell ( row, column - 2 , ship ) ;

editCell ( row, column - 3 , ship ) ;

}

// RIGHT

} else if ( direction == right ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 4 ; l ++ , y ++ ) {

if ( ( getCell ( row, y ) ) == water ) {

editCell ( row, y, ship ) ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column + 1 , ship ) ;

editCell ( row, column + 2 , ship ) ;

editCell ( row, column + 3 , ship ) ;

}

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

// **********************************************************************************

// AIRCRAFT

} else if ( shipType == aircraft ) {

if ( ( getCell ( row, column ) == water ) ) {

// UP

if ( direction == up ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 5 ; l ++ , x -- ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row - 1 , column, ship ) ;

editCell ( row - 2 , column, ship ) ;

editCell ( row - 3 , column, ship ) ;

editCell ( row - 4 , column, ship ) ;

}

// DOWN

} else if ( direction == down ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 5 ; l ++ , x ++ ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row + 1 , column, ship ) ;

editCell ( row + 2 , column, ship ) ;

editCell ( row + 3 , column, ship ) ;

editCell ( row + 4 , column, ship ) ;

}

// LEFT

} else if ( direction == left ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 5 ; l ++ , y -- ) {

if ( ( getCell ( row, y ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column - 1 , ship ) ;

editCell ( row, column - 2 , ship ) ;

editCell ( row, column - 3 , ship ) ;

editCell ( row, column - 4 , ship ) ;

}

// RIGHT

} else if ( direction == right ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 5 ; l ++ , y ++ ) {

if ( ( getCell ( row, y ) ) == water ) {

editCell ( row, y, ship ) ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column + 1 , ship ) ;

editCell ( row, column + 2 , ship ) ;

editCell ( row, column + 3 , ship ) ;

editCell ( row, column + 4 , ship ) ;

}

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

// **********************************************************************************

// CRUISER

} else if ( shipType == cruiser ) {

if ( ( getCell ( row, column ) == water ) ) {

// UP

if ( direction == up ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 3 ; l ++ , x -- ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row - 1 , column, ship ) ;

editCell ( row - 2 , column, ship ) ;

}

// DOWN

} else if ( direction == down ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 3 ; l ++ , x ++ ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row + 1 , column, ship ) ;

editCell ( row + 2 , column, ship ) ;

}

// LEFT

} else if ( direction == left ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 3 ; l ++ , y -- ) {

if ( ( getCell ( row, y ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column - 1 , ship ) ;

editCell ( row, column - 2 , ship ) ;

}

// RIGHT

} else if ( direction == right ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 3 ; l ++ , y ++ ) {

if ( ( getCell ( row, y ) ) == water ) {

editCell ( row, y, ship ) ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column + 1 , ship ) ;

editCell ( row, column + 2 , ship ) ;

}

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

// **********************************************************************************

// SUBMARINE

} else if ( shipType == submarine ) {

if ( ( getCell ( row, column ) == water ) ) {

// UP

if ( direction == up ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 3 ; l ++ , x -- ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row - 1 , column, ship ) ;

editCell ( row - 2 , column, ship ) ;

}

// DOWN

} else if ( direction == down ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 3 ; l ++ , x ++ ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row + 1 , column, ship ) ;

editCell ( row + 2 , column, ship ) ;

}

// LEFT

} else if ( direction == left ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 3 ; l ++ , y -- ) {

if ( ( getCell ( row, y ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column - 1 , ship ) ;

editCell ( row, column - 2 , ship ) ;

}

// RIGHT

} else if ( direction == right ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 3 ; l ++ , y ++ ) {

if ( ( getCell ( row, y ) ) == water ) {

editCell ( row, y, ship ) ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column + 1 , ship ) ;

editCell ( row, column + 2 , ship ) ;

}

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

// **********************************************************************************

// DESTROYER

} else if ( shipType == destroyer ) {

if ( ( getCell ( row, column ) == water ) ) {

// UP

if ( direction == up ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 2 ; l ++ , x -- ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row - 1 , column, ship ) ;

}

// DOWN

} else if ( direction == down ) {

boolean b = true ;

for ( int x = row, l = 1 ; l < 2 ; l ++ , x ++ ) {

if ( ( getCell ( x, column ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row + 1 , column, ship ) ;

}

// LEFT

} else if ( direction == left ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 2 ; l ++ , y -- ) {

if ( ( getCell ( row, y ) ) != water ) {

b = false ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column - 1 , ship ) ;

}

// RIGHT

} else if ( direction == right ) {

boolean b = true ;

for ( int y = column, l = 1 ; l < 2 ; l ++ , y ++ ) {

if ( ( getCell ( row, y ) ) == water ) {

editCell ( row, y, ship ) ;

}

}

if ( b ) {

editCell ( row, column, ship ) ;

editCell ( row, column + 1 , ship ) ;

}

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

} else { System . err . println ( "Ship cannot be placed there." ) ; a = false ; }

}

}

if ( a ) { this . draw ( ) ; }