• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

granatier

  • sources
  • kde-4.14
  • kdegames
  • granatier
  • src
cell.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
3  * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "cell.h"
20 
21 Cell::Cell() : m_type(Granatier::Cell::WALL)
22 {
23  m_elements.clear();
24 }
25 
26 Cell::~Cell()
27 {
28 }
29 
30 bool Cell::isWalkable(Element* p_element) const
31 {
32 
33  if(m_type == Granatier::Cell::WALL)
34  {
35  return false;
36  }
37  else if(!m_elements.isEmpty())
38  {
39  foreach(Element* element, m_elements)
40  {
41  if(element->getType() == Granatier::Element::BLOCK ||
42  (element->getType() == Granatier::Element::BOMB && (p_element == 0 || p_element != element)) ||
43  (element->getType() == Granatier::Element::PLAYER && (p_element == 0 || p_element->getType() != Granatier::Element::PLAYER)))
44  {
45  return false;
46  }
47  }
48  }
49  return true;
50 }
51 
52 Granatier::Cell::Type Cell::getType() const
53 {
54  return m_type;
55 }
56 
57 void Cell::setType(Granatier::Cell::Type p_type)
58 {
59  m_type = p_type;
60 }
61 
62 QList <Element*> Cell::getElements() const
63 {
64  return m_elements;
65 }
66 
67 QList <Element*> Cell::getElements(Granatier::Element::Type type) const
68 {
69  QList<Element*> elements;
70  foreach(Element* element, m_elements)
71  {
72  if(element->getType() == type)
73  {
74  elements.append(element);
75  }
76  }
77  return elements;
78 }
79 
80 void Cell::setElement(Element* p_element)
81 {
82  if(!m_elements.contains(p_element))
83  {
84  m_elements.append(p_element);
85  }
86 }
87 
88 void Cell::removeElement(Element* p_element)
89 {
90  int index = m_elements.indexOf(p_element);
91  if(index >= 0)
92  {
93  m_elements.removeAt(index);
94  }
95 }
QList::clear
void clear()
Cell::setElement
void setElement(Element *p_element)
Sets the Element that is on the Cell.
Definition: cell.cpp:80
Cell
This class represents a Cell of the Arena.
Definition: cell.h:29
Granatier::Element::PLAYER
Definition: granatierglobals.h:93
Granatier::GraphicItem::WALL
Definition: granatierglobals.h:41
QList::removeAt
void removeAt(int i)
Cell::getElements
QList< Element * > getElements() const
Gets all the Elements that are on the Cell.
Definition: cell.cpp:62
Element::getType
Granatier::Element::Type getType() const
Gets the type of the Element.
Definition: element.cpp:68
QList::indexOf
int indexOf(const T &value, int from) const
cell.h
QList::append
void append(const T &value)
QList::isEmpty
bool isEmpty() const
Granatier::Cell::WALL
Definition: granatierglobals.h:75
QList< Element * >
Cell::~Cell
~Cell()
Deletes the Cell instance.
Definition: cell.cpp:26
Granatier::Element::Type
Type
Definition: granatierglobals.h:89
Element
This class describes the common characteristics and behaviour of any game Element (character or item)...
Definition: element.h:32
Granatier::Element::BOMB
Definition: granatierglobals.h:94
QList::contains
bool contains(const T &value) const
Cell::setType
void setType(Granatier::Cell::Type p_type)
Sets the Cell type.
Definition: cell.cpp:57
Granatier::Cell::Type
Type
Definition: granatierglobals.h:71
Granatier::Element::BLOCK
Definition: granatierglobals.h:92
Cell::isWalkable
bool isWalkable(Element *p_element) const
Returns if it is possible to move into the cell or not, because of a wall, bomb, etc.
Definition: cell.cpp:30
Cell::Cell
Cell()
Creates a new Cell instance.
Definition: cell.cpp:21
Cell::removeElement
void removeElement(Element *p_element)
Removes the Element that is on the Cell.
Definition: cell.cpp:88
Cell::getType
Granatier::Cell::Type getType() const
Gets the Cell type.
Definition: cell.cpp:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

granatier

Skip menu "granatier"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal