1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| class Move {
// Or maybe typedef struct s_Move {
// Constructors
// public:
// s_Move(...) ... { ... }
//
// ...
// } Move;
// Constructors
public:
Move() : horizontal_move(0), vertical_move(0), inverse(MOVE_DEFAULT) {}
// Or
// Move() { clean(); }
Move(int init_horizontal_move, int init_vertical_move, unsigned char init_inverse) : horizontal_move(init_horizontal_move), vertical_move(init_vertical_move) {
inverse = ((init_inverse < NB_MOVES)? init_inverse: MOVE_NOT_INIT /*or MOVE_DEFAULT or MOVE_ERROR*/ );
}
// Or
// Move(int init_horizontal_move, int init_vertical_move, unsigned char init_inverse) { init(init_horizontal_move, init_vertical_move, init_inverse); }
Move(const Move& other) { horizontal_move = other.horizontal_move; vertical_move = other.vertical_move; }
// Setters-Getters only if attributes are either private or protected
public:
int get_horizontal_move() { return horizontal_move; }
int get_inverse() { return inverse; }
int get_vertical_move() { return vertical_move; }
void set_inverse(unsigned char new_inverse) { if (new_inverse < NB_MOVES) { inverse = new_inverse; }}
// Public Interface
public:
// XXX Warning: the method init checks if this is a move: so we cannot pass MOVE_NOT_INIT or MOVE_ERROR
void clean() { init(0, 0, MOVE_DEFAULT); }
int get_next_column(int current_row) { return (current_row + horizontal_move); }
int get_next_row(int current_row) { return (current_row + vertical_move); }
void init(int init_horizontal_move, int init_vertical_move, unsigned char init_inverse) {
horizontal_move = init_horizontal_move;
vertical_move = init_vertical_move;
inverse = ((init_inverse < NB_MOVES)? init_inverse: MOVE_NOT_INIT /*or MOVE_DEFAULT or MOVE_ERROR*/ );
}
// Attributes
public: // or private: or protected:
int horizontal_move;
int vertical_move;
unsigned char inverse;
}; |
Partager