File indexing completed on 2024-02-18 04:04:55

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef Ship_H
0008 #define Ship_H
0009 
0010 #include "coord.h"
0011 #include "element.h"
0012 
0013 class Ship
0014 {
0015 public:
0016     enum Direction
0017     {
0018         TOP_DOWN,
0019         LEFT_TO_RIGHT
0020     };
0021 private:
0022     unsigned int m_size;
0023     Coord m_position;
0024     Direction m_direction;
0025     int m_life;
0026 public:
0027     Ship(unsigned int size, Direction direction, Coord position);
0028 
0029     void decLife();
0030     void setPosition(const Coord & position);
0031     void changeDirection();
0032 
0033     const Coord position() const;
0034     Coord increment() const;
0035     Coord decrement() const;
0036     Coord incrementPerpendicular() const;
0037     Coord decrementPerpendicular() const;
0038 
0039     static Coord increment(Direction);
0040     static Coord decrement(Direction);
0041     static Coord incrementPerpendicular(Direction);
0042     static Coord decrementPerpendicular(Direction);
0043 
0044     inline unsigned int size() const { return m_size; }
0045     inline Direction direction() const { return m_direction; }
0046 
0047     bool alive() const;
0048 };
0049 
0050 #endif // Ship_H