File indexing completed on 2024-02-25 04:08:50

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "element.h"
0008 #include "ship.h"
0009 
0010 Element::Element(Type type)
0011 : m_parent(nullptr)
0012 , m_type(type)
0013 {
0014 }
0015 
0016 Element::Element(Ship* parent)
0017 : m_parent(parent)
0018 , m_type(ALIVE)
0019 {
0020 
0021 }
0022 
0023 bool Element::free() const 
0024 { 
0025     return m_type == ALIVE || m_type == WATER;
0026 }
0027 
0028 bool Element::water() const
0029 {
0030     return m_type == WATER;
0031 }
0032 
0033 HitInfo::Type Element::hit()
0034 {
0035     switch (m_type) {
0036     case ALIVE:
0037         m_type = DEAD;
0038         m_parent->decLife();
0039         return HitInfo::HIT;
0040     case WATER:
0041         m_type = MISS;
0042         return HitInfo::MISS;
0043     default:
0044         return HitInfo::INVALID;
0045     }
0046 }
0047