Checking directional moves for a game I am making a 2D Java game at school, and at the movement I use a switch. The code works, however, my teacher won't sign my code until I have removed code duplication.

Short info: My Keyactionlistener sends a String of direction that is used in the switch to move. Inside that very same switch I also check the object in the next field to see if it can be picked up or can move through. However, the code is really long this way and I need to shorten it down somehow.

public void checkAndMove(String direction) {
        switch (direction) {

            case "up":
                if (!field.checkIfBlocked(getfieldX(), getfieldY() - 1)) {
                    if (field.checkIfItem(getfieldX(), getfieldY() - 1).equals("friend")) {
                        showEndMessage = true;
                    }
                    if (field.checkIfItem(getfieldX(), getfieldY() - 1).equals("bazooka")) {
                        plusAmmo();
                        levelmaker.removeBazooka();
                    }
                    if (field.checkIfItem(getfieldX(), getfieldY() - 1).equals("helper")) {
                        showShortestRoute();
                    }
                    move(0, -1);
                    if(showEndMessage == true){
                        endMessage();
                    }
                    levelmaker.scorePlusPlus();
                    changeImage("imgUp");
                    break;
                } else {
                    break;
                }
            case "down":
                if (!field.checkIfBlocked(getfieldX(), getfieldY() + 1)) {
                    if (veld.checkIfItem(getfieldX(), getfieldY() + 1).equals("friend")) {
                        endMessage();
                    }
                    if (field.checkIfItem(getfieldX(), getfieldY() + 1).equals("bazooka")) {
                        plusAmmo();
                        LevelMaker.removeBazooka();
                    }
                    if (field.checkIfItem(getfieldX(), getfieldY() + 1).equals("helper")) {
                        showShortestRoute();
                    }
                    move(0, 1);
                    levelmaker.scorePlusPlus();
                    changeImage("imgDown");
                    break;
                } else {
                    break;
                }
            case "left":
                if (!field.checkIfBlocked(getfieldX() - 1, getfieldY())) {
                    if (field.checkIfItem(getfieldX() - 1, getfieldY()).equals("friend")) {
                        endMessage();
                    }
                    if (field.checkIfItem(getfieldX() - 1, getfieldY()).equals("bazooka")) {
                        plusAmmo();
                        LevelMaker.removeBazooka();
                    }
                    if (field.checkIfItem(getfieldX() - 1, getfieldY()).equals("helper")) {
                        showShortestRoute();
                    }
                    move(-1, 0);
                    levelmaker.scorePlusPlus();
                    changeImage("imgLeft");
                    break;
                } else {
                    break;
                }
            case "right":
                if (!field.checkIfBlocked(getfieldX() + 1, getfieldY())) {
                    if (field.checkIfItem(getfieldX() + 1, getfieldY()).equals("friend")) {
                        endMessage();
                    }
                    if (veld.checkIfItem(getfieldX() + 1, getfieldY()).equals("bazooka")) {
                        plusAmmo();
                        LevelMaker.removeBazooka();
                    }
                    if (field.checkIfItem(getfieldX() + 1, getfieldY()).equals("helper")) {
                        showShortestRoute();
                    }
                    move(1, 0);
                    levelmaker.scorePlusPlus();
                    changeImage("imgRight");
                    break;
                } else {
                    break;
                }
        }
Put these

if (!field.checkIfBlocked(getfieldX() + 1, getfieldY())) {
    if (field.checkIfItem(getfieldX() + 1, getfieldY()).equals("friend")) {
           endMessage();
    }
    if (field.checkIfItem(getfieldX() + 1, getfieldY()).equals("bazooka")) {
        plusAmmo();
        LevelMaker.removeBazooka();
    }
    if (field.checkIfItem(getfieldX() + 1, getfieldY()).equals("helper")) {
        showShortestRoute();
    }


into a function.

Example:

public boolean performActions(int x, int y) {
    if(field.checkIfBlocked(x, y)
        return false;

    String status = field.checkIfItem(x, y);
    if(status.equals("friend")) {
        endMessage();
    } if(status.equals("bazooka")) {
        plusAmmo();
        LevelMaker.removeBazooka();
    } if(status.equals("helper")) {
        showShortestRoute();
    }   
    return true;
}


and checkAndMove() becomes:

public void checkAndMove(String direction) {
    switch (direction) {

        case "up":
            if (performActions(getfieldX(), getfieldY() - 1)) {

                // rest of the stuff
            }
            break;
        case "down":
            if (performActions(getfieldX(), getfieldY() + 1)) {

                // rest of the stuff
            }
            break;
        case "left":
            if (performActions(getfieldX() - 1, getfieldY())) {

                // rest of the stuff            
            }
            break;
        case "right":
            if (performActions(getfieldX() + 1, getfieldY())) {

                // rest of the stuff
            }
            break;
    }
}