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

kapman

  • sources
  • kde-4.14
  • kdegames
  • kapman
kapmanparser.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2007-2008 Nathalie Liesse <nathalie.liesse@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "kapmanparser.h"
19 #include "element.h"
20 #include "pill.h"
21 #include "energizer.h"
22 
23 KapmanParser::KapmanParser(Game* p_game) {
24  m_game = p_game;
25  m_counterRows = 0;
26 }
27 
28 KapmanParser::~KapmanParser() {
29 
30 }
31 
32 bool KapmanParser::characters(const QString & ch ){
33  m_buffer = ch;
34  return true;
35 }
36 
37 bool KapmanParser::startElement(const QString&, const QString&, const QString& p_qName, const QXmlAttributes& p_atts) {
38  qreal x_position = 0.0;
39  qreal y_position = 0.0;
40 
41  if (p_qName == "Maze") {
42  int nbRows = 0;
43  int nbColumns = 0;
44  // Initialize the number of rows and columns
45  for (int i = 0; i < p_atts.count(); ++i) {
46  if (p_atts.qName(i) == "rowCount") {
47  nbRows = p_atts.value(i).toInt();
48  }
49  if (p_atts.qName(i) == "colCount") {
50  nbColumns = p_atts.value(i).toInt();
51  }
52  }
53  // Create the Maze matrix
54  m_game->getMaze()->init(nbRows, nbColumns);
55  }
56  else if (p_qName == "Bonus") {
57  // Initialize the number of rows and columns
58  for (int i = 0; i < p_atts.count(); ++i) {
59  if (p_atts.qName(i) == "rowIndex") {
60  y_position = p_atts.value(i).toInt();
61  }
62  if (p_atts.qName(i) == "colIndex") {
63  x_position = p_atts.value(i).toInt();
64  }
65  if (p_atts.qName(i) == "x-align") {
66  if(p_atts.value(i) == "center"){
67  x_position += 0.5;
68  }
69  }
70  if (p_atts.qName(i) == "y-align") {
71  if(p_atts.value(i) == "center"){
72  y_position += 0.5;
73  }
74  }
75  }
76  m_game->createBonus(QPointF(x_position, y_position));
77  }
78  else if (p_qName == "Kapman") {
79  // Initialize the number of rows and columns
80  for (int i = 0; i < p_atts.count(); ++i) {
81  if (p_atts.qName(i) == "rowIndex") {
82  y_position = p_atts.value(i).toInt();
83  }
84  if (p_atts.qName(i) == "colIndex") {
85  x_position = p_atts.value(i).toInt();
86  }
87  if (p_atts.qName(i) == "x-align") {
88  if(p_atts.value(i) == "center"){
89  x_position += 0.5;
90  }
91  }
92  if (p_atts.qName(i) == "y-align") {
93  if(p_atts.value(i) == "center"){
94  y_position += 0.5;
95  }
96  }
97  }
98  m_game->createKapman(QPointF(x_position, y_position));
99  }
100  else if (p_qName == "Ghost") {
101  QString imageId = "";
102  // Initialize the number of rows and columns
103  for (int i = 0; i < p_atts.count(); ++i) {
104  if (p_atts.qName(i) == "rowIndex") {
105  y_position = p_atts.value(i).toInt();
106  }
107  if (p_atts.qName(i) == "colIndex") {
108  x_position = p_atts.value(i).toInt();
109  }
110  if (p_atts.qName(i) == "x-align") {
111  if(p_atts.value(i) == "center"){
112  x_position += 0.5;
113  }
114  }
115  if (p_atts.qName(i) == "y-align") {
116  if(p_atts.value(i) == "center"){
117  y_position += 0.5;
118  }
119  }
120  if (p_atts.qName(i) == "imageId") {
121  imageId = p_atts.value(i);
122  }
123  }
124  m_game->createGhost(QPointF(x_position, y_position),imageId);
125  }
126 
127 
128  return true;
129 }
130 
131 bool KapmanParser::endElement(const QString &, const QString &, const QString & p_qName ){
132  if(p_qName == "Row")
133  {
134  for (int i=0; i<m_buffer.length();++i)
135  {
136  switch(m_buffer.at(i).toAscii()){
137  case '|':
138  case '=': m_game->getMaze()->setCellType(m_counterRows,i,Cell::WALL);
139  break;
140  case ' ': m_game->getMaze()->setCellType(m_counterRows,i,Cell::CORRIDOR);
141  break;
142  case '.': m_game->getMaze()->setCellType(m_counterRows,i,Cell::CORRIDOR);
143  m_game->getMaze()->setCellElement(m_counterRows, i,
144  new Pill(m_counterRows, i, m_game->getMaze(), "pill"));
145  break;
146  case 'o':m_game->getMaze()->setCellType(m_counterRows,i,Cell::CORRIDOR);
147  m_game->getMaze()->setCellElement(m_counterRows, i,
148  new Energizer(m_counterRows, i, m_game->getMaze(), "energizer"));
149  break;
150  case 'x':m_game->getMaze()->setCellType(m_counterRows,i,Cell::GHOSTCAMP);
151  break;
152  case 'X':m_game->getMaze()->setCellType(m_counterRows,i,Cell::GHOSTCAMP);
153  m_game->getMaze()->setResurrectionCell(QPoint(m_counterRows, i));
154  break;
155  }
156  }
157  m_counterRows ++;
158  }
159  return true;
160 }
161 
162 
163 
KapmanParser::characters
bool characters(const QString &ch)
Implement QXmlDefaultHandler::characters.
Definition: kapmanparser.cpp:32
Maze::init
void init(const int p_nbRows, const int p_nbColumns)
Creates the Maze matrix.
Definition: maze.cpp:36
Cell::WALL
Definition: cell.h:37
element.h
KapmanParser::~KapmanParser
~KapmanParser()
Deletes the GameParser instance.
Definition: kapmanparser.cpp:28
QChar::toAscii
char toAscii() const
KapmanParser::endElement
bool endElement(const QString &, const QString &, const QString &p_qName)
Implements QXmlDefaultHandler::endElement()
Definition: kapmanparser.cpp:131
QPoint
Game::createBonus
void createBonus(QPointF p_position)
Create the new Bonus.
Definition: game.cpp:232
KapmanParser::startElement
bool startElement(const QString &, const QString &, const QString &p_qName, const QXmlAttributes &p_atts)
Implements QXmlDefaultHandler::startElement()
Definition: kapmanparser.cpp:37
QPointF
Maze::setCellElement
void setCellElement(const int p_row, const int p_column, Element *p_element)
Sets the Element that is on the Cell whose coordinates are given in parameters.
Definition: maze.cpp:52
QXmlAttributes::count
int count() const
KapmanParser::KapmanParser
KapmanParser(Game *p_game)
Creates a new GameParser.
Definition: kapmanparser.cpp:23
Maze::setResurrectionCell
void setResurrectionCell(QPoint p_resurrectionCell)
Sets the cell on witch the ghosts resurrect from prey state.
Definition: maze.cpp:63
pill.h
QString::toInt
int toInt(bool *ok, int base) const
Game
This class manages the game main loop : it regularly checks the key press events, computes the charac...
Definition: game.h:35
Game::createKapman
void createKapman(QPointF p_position)
Create the new Kapman.
Definition: game.cpp:236
Cell::CORRIDOR
Definition: cell.h:38
Game::createGhost
void createGhost(QPointF p_position, const QString &p_imageId)
Create the new Ghost.
Definition: game.cpp:240
QString
Maze::setCellType
void setCellType(const int p_row, const int p_column, const Cell::Type p_type)
Sets the CellType of the Cell whose coordinates are given in parameters.
Definition: maze.cpp:45
energizer.h
QXmlAttributes::qName
QString qName(int index) const
Energizer
This class represents an energizer enabling to eat Ghosts.
Definition: energizer.h:29
Cell::GHOSTCAMP
Definition: cell.h:39
QXmlAttributes
QString::at
const QChar at(int position) const
Pill
This class represents a Pill enabling to earn points.
Definition: pill.h:28
QString::length
int length() const
QXmlAttributes::value
QString value(int index) const
kapmanparser.h
Game::getMaze
Maze * getMaze() const
Definition: game.cpp:180
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapman

Skip menu "kapman"
  • Main Page
  • 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