Processing player's move in an ASCII rogue-like game I'm making an ASCII roguelike game and while writing the code for processing the player's move I can't decide between these two options. I have defined a class named point to handle positions in the game, like this. I would also like to know if this is a good idea or if I should use a structure instead.

Should I pass an object as a parameter to a function or create it inside?

class point {
public:
    point();
    point(int x, int y);

    int getX() const;
    int getY() const;;

    void setX(int x);
    void setY(int y);

private:
    int x;
    int y;
};


OPTION 1

I define the target point object before calling the function.

point playerPos = player.get_position();
point moveTilePos;


switch (input) {
    case MOVE_UP:
        moveTilePos.setX(playerPos.getX());
        moveTilePos.setY(playerPos.getY()-1);
        processPlayerMove(player, moveTilePos);


which is defined as follows:

void Level::processPlayerMove(Player &amp;player, point target) {

    char moveTileSymbol;

    moveTileSymbol = getTile(target);
    switch(moveTileSymbol){
        case WALL_SYMBOL:
            break;
        case GROUND_SYMBOL:
            setTile(player.get_position(), GROUND_SYMBOL);
            player.set_position(target);
            setTile(target, PLAYER_SYMBOL);
            break;
    }
}


I think this is more readable overall but requires a setup that maybe should be part of the function. 

Option 2

Everything is handled by the function:

point playerPos = player.get_position();

switch (input) {
    case MOVE_UP:
        processPlayerMove2(player, playerPos.getX(), playerPos.getY() -1)


Which is defined like this:

void Level::processPlayerMove2(Player &amp;player, int targetX, int targetY) {

    char moveTileSymbol;
    point target;

    target.setX(targetX);
    target.setY(targetY);

    moveTileSymbol = getTile(target);
    switch(moveTileSymbol){
        case WALL_SYMBOL:
            break;
        case GROUND_SYMBOL:
            setTile(player.get_position(), GROUND_SYMBOL);
            player.set_position(target);
            setTile(target, PLAYER_SYMBOL);
            break;
    }
}


This case is more succinct, as the function handles everything.
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?