Processing player's move in an ASCII rogue-like game
point playerPos = player.get_position();
point moveTilePos;

moveTilePos.setX(playerPos.getX());
moveTilePos.setY(playerPos.getY()-1);
processPlayerMove(player, moveTilePos);


Well, of course you shouldn't do that. Declaring an "uninitialized" variable to be initialized later via mutation is one of the cardinal sins of modern C++ programming. One reasonable way to write this code would be

point playerPos = player.get_position();
processPlayerMove(
    Point(playerPos.getX(), playerPos.getY() - 1)
);


But if you find yourself writing Point(p.getX(), p.getY()-1) often enough, then you should factor it out into a function:

point playerPos = player.get_position();
processPlayerMove(playerPos.upward(1));


And then you can eliminate that pesky helper variable:

processPlayerMove(player.get_position().upward(1));


There, that looks clean enough!



Next, look at your switch statement and refactor it to be clearer.

switch (input) {
    case MOVE_UP:
        processPlayerMove(player.get_position().upward(1));
        break;
    case MOVE_DOWN:
        processPlayerMove(player.get_position().downward(1));
        break;
    case MOVE_LEFT:
        processPlayerMove(player.get_position().leftward(1));
        break;
    case MOVE_RIGHT:
        processPlayerMove(player.get_position().rightward(1));
        break;
}


Can you think of a similar way to simplify this code? What would it look like?