Why sum the floors on the plus operator?

Does it make sense to sum and substract the floors on the sum and substract operatios, on the GridPosition class?

public static GridPosition operator +(GridPosition a, GridPosition b)
{
    return new GridPosition(a.x + b.x, a.z + b.z, a.floor + b.floor);
}

I mean, it doesnt make sense for me to sum or substract grid positions in different floors, so I would check if the floor is the same, just return that; if the floor is different, maybe throw an exception or an error.

What do you think?

Hi Nachiten,

In which course and lecture are you?

@Nina I believe it’s the turn based strategy course’s new section about having different floors

@Nachiten It does make some sense. If I am checking the neighbours of a grid position, I may want to check above and below me too. Throwing an exception wouldn’t help with that, but adding and subtracting 1 from the floor I’m on, will.

Privacy & Terms