diff --git a/bonus.h b/bonus.h index bc69416..7c5c236 100644 --- a/bonus.h +++ b/bonus.h @@ -1,62 +1,62 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Gaël Courcelle * Copyright 2007-2008 Alexia Allanic * Copyright 2007-2008 Johann Hingue * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef BONUS_H #define BONUS_H #include "element.h" /** * @brief This class represents a Bonus for Kapman. */ class Bonus : public Element { - + Q_OBJECT public: /** * Creates a new Bonus instance. * @param p_x the initial x-coordinate * @param p_y the initial y-coordinate * @param p_maze a reference to the Maze the Bonus will be on * @param p_points the value of the Bonus */ Bonus(qreal p_x, qreal p_y, Maze *p_maze, int p_points); /** * Deletes the Bonus instance. */ ~Bonus(); /** * Computes an action on a collision with the Kapman. * @param p_kapman the Kapman instance that collides with the Bonus */ void doActionOnCollision(Kapman *p_kapman) override; /** * Sets the given value to the Bonus. * @param p_points the value of the Bonus */ void setPoints(const int p_points); }; #endif diff --git a/character.cpp b/character.cpp index 32af623..198d4d5 100644 --- a/character.cpp +++ b/character.cpp @@ -1,250 +1,250 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Pierre-Benoît Besse * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "character.h" #include const qreal Character::LOW_SPEED = 3.75; const qreal Character::MEDIUM_SPEED = 4.5; const qreal Character::HIGH_SPEED = 5.25; const qreal Character::LOW_SPEED_INC = 0.005; const qreal Character::MEDIUM_SPEED_INC = 0.01; const qreal Character::HIGH_SPEED_INC = 0.02; Character::Character(qreal p_x, qreal p_y, Maze *p_maze) : Element(p_x, p_y, p_maze), m_xSpeed(0), m_ySpeed(0) { initSpeed(); m_maxSpeed = m_normalSpeed; // To avoid bugs, but will be overridden in the Ghost and Kapman constructors } Character::~Character() { } void Character::move() { // Take care of the Maze borders if (m_maze->getColFromX(m_x + m_xSpeed) == 0) { // First column m_x = (m_maze->getNbColumns() - 1.5) * Cell::SIZE; } else if (m_maze->getColFromX(m_x + m_xSpeed) == m_maze->getNbColumns() - 1) { // Last column m_x = 1.5 * Cell::SIZE; } else if (m_maze->getRowFromY(m_y + m_ySpeed) == 0) { // First row m_y = (m_maze->getNbRows() - 1.5) * Cell::SIZE; } else if (m_maze->getRowFromY(m_y + m_ySpeed) == m_maze->getNbRows() - 1) { // Last row m_y = 1.5 * Cell::SIZE; } // Move the Character m_x += m_xSpeed; m_y += m_ySpeed; - emit(moved(m_x, m_y)); + Q_EMIT moved(m_x, m_y); } void Character::die() { - emit(eaten()); + Q_EMIT eaten(); } qreal Character::getXSpeed() const { return m_xSpeed; } qreal Character::getYSpeed() const { return m_ySpeed; } qreal Character::getSpeed() const { return m_speed; } qreal Character::getNormalSpeed() const { return m_normalSpeed; } void Character::setXSpeed(qreal p_xSpeed) { m_xSpeed = p_xSpeed; } void Character::setYSpeed(qreal p_ySpeed) { m_ySpeed = p_ySpeed; } void Character::initSpeed() { // Kapman speed increase when level up switch ((int) Kg::difficultyLevel()) { case KgDifficultyLevel::Easy: m_normalSpeed = Character::LOW_SPEED; break; case KgDifficultyLevel::Medium: m_normalSpeed = Character::MEDIUM_SPEED; break; case KgDifficultyLevel::Hard: m_normalSpeed = Character::HIGH_SPEED; break; } m_speed = m_normalSpeed; } void Character::increaseCharactersSpeed() { m_normalSpeed += m_normalSpeed * m_speedIncrease; // Do not have a speed over the max allowed speed if (m_normalSpeed > m_maxSpeed) { m_normalSpeed = m_maxSpeed; } m_speed = m_normalSpeed; } bool Character::isInLineSight(Character *p_character) { int curCallerRow; // The current row of the Character int curCallerCol; // The current column of the Character int curCharacterRow; // The current row of the other Character int curCharacterCol; // The current column of the other Character curCallerRow = m_maze->getRowFromY(m_y); curCallerCol = m_maze->getColFromX(m_x); curCharacterRow = m_maze->getRowFromY(p_character->getY()); curCharacterCol = m_maze->getColFromX(p_character->getX()); // If the two Characters are on the same row if (curCallerRow == curCharacterRow) { // If The Character is on the right of the other one and goes to the left if (curCallerCol > curCharacterCol && m_xSpeed < 0) { // Check there is a wall between them for (int i = curCharacterCol; i < curCallerCol; ++i) { if (m_maze->getCell(curCallerRow, i).getType() != Cell::CORRIDOR) { return false; } } // If not, the other Character is in the line sight return true; // If the Character is on the left of the other one and goes to the right } else if (curCallerCol < curCharacterCol && m_xSpeed > 0) { // Check there is a wall between them for (int i = curCallerCol; i < curCharacterCol; ++i) { if (m_maze->getCell(curCallerRow, i).getType() != Cell::CORRIDOR) { return false; } } // If not, the other Character is in the line sight return true; } // If the two Characters are on the same column } else if (curCallerCol == curCharacterCol) { // If The Character is on the bottom of the other one and goes up if (curCallerRow > curCharacterRow && m_ySpeed < 0) { // Check there is a wall between them for (int i = curCharacterRow; i < curCallerRow; ++i) { if (m_maze->getCell(i, curCallerCol).getType() != Cell::CORRIDOR) { return false; } } // If not, the other Character is in the line sight return true; // If the Character is on the top of the other one and goes down } else if (curCallerRow < curCharacterRow && m_ySpeed > 0) { // Check there is a wall between them for (int i = curCallerRow; i < curCharacterRow; ++i) { if (m_maze->getCell(i, curCallerCol).getType() != Cell::CORRIDOR) { return false; } } // If not, the other Character is in the line sight return true; } } // If the two Characters are not on the same row or column, they are not in the line of sight return false; } Cell Character::getNextCell() { Cell nextCell; // Get the current cell coordinates from the character coordinates int curCellRow = m_maze->getRowFromY(m_y); int curCellCol = m_maze->getColFromX(m_x); // Get the next cell function of the character direction if (m_xSpeed > 0) { nextCell = m_maze->getCell(curCellRow, curCellCol + 1); } else if (m_xSpeed < 0) { nextCell = m_maze->getCell(curCellRow, curCellCol - 1); } else if (m_ySpeed > 0) { nextCell = m_maze->getCell(curCellRow + 1, curCellCol); } else if (m_ySpeed < 0) { nextCell = m_maze->getCell(curCellRow - 1, curCellCol); } return nextCell; } bool Character::onCenter() { // Get the current cell center coordinates qreal centerX = (m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE; qreal centerY = (m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE; bool willGoPast = false; // Will the character go past the center of the cell it's on ? // If goes right if (m_xSpeed > 0) { willGoPast = (m_x <= centerX && m_x + m_xSpeed >= centerX); } // If goes left else if (m_xSpeed < 0) { willGoPast = (m_x >= centerX && m_x + m_xSpeed <= centerX); } // If goes down else if (m_ySpeed > 0) { willGoPast = (m_y <= centerY && m_y + m_ySpeed >= centerY); } // If goes up else if (m_ySpeed < 0) { willGoPast = (m_y >= centerY && m_y + m_ySpeed <= centerY); } // If does not moe else { willGoPast = (m_x == centerX && m_y == centerY); } return willGoPast; } bool Character::isOnCenter() { // Get the current cell center coordinates qreal centerX = (m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE; qreal centerY = (m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE; return m_x == centerX && m_y == centerY; } void Character::moveOnCenter() { setX((m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE); setY((m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE); } diff --git a/element.cpp b/element.cpp index 694aa04..a571b1f 100644 --- a/element.cpp +++ b/element.cpp @@ -1,81 +1,81 @@ /* * Copyright 2007-2008 Thomas Gallinari * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "element.h" Element::Element(qreal p_x, qreal p_y, Maze *p_maze) : m_xInit(p_x), m_yInit(p_y), m_maze(p_maze) { m_points = 0; initCoordinate(); } Element::~Element() { } void Element::doActionOnCollision(Kapman *) { // Do nothing by default : will be redefined within the subclasses } qreal Element::getX() const { return m_x; } qreal Element::getY() const { return m_y; } void Element::setX(qreal p_x) { m_x = p_x; - emit(moved(m_x, m_y)); + Q_EMIT moved(m_x, m_y); } void Element::setY(qreal p_y) { m_y = p_y; - emit(moved(m_x, m_y)); + Q_EMIT moved(m_x, m_y); } int Element::getPoints() const { return m_points; } Element::Type Element::getType() const { return m_type; } QString Element::getImageId() const { return m_imageId; } void Element::setImageId(const QString &p_imageId) { m_imageId = p_imageId; } void Element::initCoordinate() { setX(m_xInit); setY(m_yInit); } diff --git a/game.cpp b/game.cpp index 4e228bf..6ad87dd 100644 --- a/game.cpp +++ b/game.cpp @@ -1,549 +1,549 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Pierre-Benoit Besse * Copyright 2007-2008 Alexandre Galinier * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "game.h" #include "kapmanparser.h" #include "settings.h" #include #include const int Game::FPS = 40; int Game::s_bonusDuration; int Game::s_preyStateDuration; qreal Game::s_durationRatio; Game::Game() : m_isCheater(false), m_lives(3), m_points(0), m_level(1), m_nbEatenGhosts(0), m_soundGameOver(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/gameover.ogg"))), m_soundGhost(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/ghost.ogg"))), m_soundGainLife(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/life.ogg"))), m_soundEnergizer(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/energizer.ogg"))), m_soundBonus(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/bonus.ogg"))), m_soundPill(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/pill.ogg"))), m_soundLevelUp(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/kapman/levelup.ogg"))) { // Initialize the sound state setSoundsEnabled(Settings::sounds()); // Timers for medium difficulty s_bonusDuration = 7000; s_preyStateDuration = 10000; // Difference ratio between low/high and medium speed s_durationRatio = 1.0; // Tells the KgDifficulty singleton that the game is not running Kg::difficulty()->setGameRunning(false); // Create the Maze instance m_maze = new Maze(); connect(m_maze, &Maze::allElementsEaten, this, &Game::nextLevel); // Create the parser that will parse the XML file in order to initialize the Maze instance // This also creates all the characters KapmanParser kapmanParser(this); // Set the XML file as input source for the parser QFile mazeXmlFile(QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("defaultmaze.xml"))); mazeXmlFile.open(QIODevice::ReadOnly); kapmanParser.parse(&mazeXmlFile); connect(m_kapman, &Kapman::sWinPoints, this, &Game::winPoints); // Initialize the characters speed timers duration considering the difficulty level switch (Kg::difficultyLevel()) { case KgDifficultyLevel::Easy: // Ratio low/medium speed s_durationRatio = Character::MEDIUM_SPEED / Character::LOW_SPEED; break; case KgDifficultyLevel::Medium: s_durationRatio = 1; break; case KgDifficultyLevel::Hard: // Ratio high/medium speed s_durationRatio = Character::MEDIUM_SPEED / Character::HIGH_SPEED; break; default: break; } for (int i = 0; i < m_ghosts.size(); ++i) { connect(m_ghosts[i], &Ghost::lifeLost, this, &Game::kapmanDeath); connect(m_ghosts[i], &Ghost::ghostEaten, this, &Game::ghostDeath); // Initialize the ghosts speed and the ghost speed increase considering the characters speed m_ghosts[i]->initSpeedInc(); } m_kapman->initSpeedInc(); // Initialize Bonus timer from the difficulty level m_bonusTimer = new QTimer(this); m_bonusTimer->setInterval((int)(s_bonusDuration * s_durationRatio)); m_bonusTimer->setSingleShot(true); connect(m_bonusTimer, &QTimer::timeout, this, &Game::hideBonus); // Initialize the Preys timer from the difficulty level m_preyTimer = new QTimer(this); m_preyTimer->setInterval((int)(s_preyStateDuration * s_durationRatio)); m_preyTimer->setSingleShot(true); connect(m_preyTimer, &QTimer::timeout, this, &Game::endPreyState); // Start the Game timer m_timer = new QTimer(this); m_timer->setInterval(int(1000 / Game::FPS)); connect(m_timer, &QTimer::timeout, this, &Game::update); m_timer->start(); m_state = RUNNING; // Init the characters coordinates on the Maze initCharactersPosition(); } Game::~Game() { delete m_timer; delete m_bonusTimer; delete m_maze; delete m_kapman; for (int i = 0; i < m_ghosts.size(); ++i) { delete m_ghosts[i]; } delete m_bonus; } void Game::start() { // Restart the Game timer m_timer->start(); m_state = RUNNING; - emit(pauseChanged(false, false)); + Q_EMIT pauseChanged(false, false); } void Game::pause(bool p_locked) { // Stop the Game timer m_timer->stop(); if (p_locked) { m_state = PAUSED_LOCKED; } else { m_state = PAUSED_UNLOCKED; } - emit(pauseChanged(true, false)); + Q_EMIT pauseChanged(true, false); } void Game::switchPause(bool p_locked) { // If the Game is not already paused if (m_state == RUNNING) { // Pause the Game pause(p_locked); - emit(pauseChanged(true, true)); + Q_EMIT pauseChanged(true, true); } // If the Game is already paused else { // Resume the Game start(); - emit(pauseChanged(false, true)); + Q_EMIT pauseChanged(false, true); } } Kapman *Game::getKapman() const { return m_kapman; } QList Game::getGhosts() const { return m_ghosts; } QTimer *Game::getTimer() const { return m_timer; } Maze *Game::getMaze() const { return m_maze; } bool Game::isPaused() const { return (m_state != RUNNING); } bool Game::isCheater() const { return m_isCheater; } int Game::getScore() const { return m_points; } int Game::getLives() const { return m_lives; } int Game::getLevel() const { return m_level; } void Game::setLevel(int p_level) { m_isCheater = true; m_level = p_level; m_maze->resetNbElem(); m_timer->start(); // Needed to reinit character positions initCharactersPosition(); for (int i = 0; i < m_ghosts.size(); ++i) { m_ghosts[i]->initSpeed(); } m_kapman->initSpeed(); for (int i = 0; i < m_level; ++i) { for (int j = 0; j < m_ghosts.size(); ++j) { m_ghosts[j]->increaseCharactersSpeed(); } m_kapman->increaseCharactersSpeed(); } setTimersDuration(); m_bonus->setPoints(m_level * 100); - emit(scoreChanged(m_points)); - emit(livesChanged(m_lives)); - emit(levelChanged(m_level)); - emit(pauseChanged(false, true)); - emit(levelStarted(true)); + Q_EMIT scoreChanged(m_points); + Q_EMIT livesChanged(m_lives); + Q_EMIT levelChanged(m_level); + Q_EMIT pauseChanged(false, true); + Q_EMIT levelStarted(true); } Bonus *Game::getBonus() const { return m_bonus; } void Game::createBonus(QPointF p_position) { m_bonus = new Bonus(qreal(Cell::SIZE * p_position.x()), qreal(Cell::SIZE * p_position.y()), m_maze, 100); } void Game::createKapman(QPointF p_position) { m_kapman = new Kapman(qreal(Cell::SIZE * p_position.x()), qreal(Cell::SIZE * p_position.y()), m_maze); } void Game::createGhost(QPointF p_position, const QString &p_imageId) { m_ghosts.append(new Ghost(qreal(Cell::SIZE * p_position.x()), qreal(Cell::SIZE * p_position.y()), p_imageId, m_maze)); } void Game::initMaze(const int p_nbRows, const int p_nbColumns) { m_maze->init(p_nbRows, p_nbColumns); } void Game::setSoundsEnabled(bool p_enabled) { m_soundEnabled = p_enabled; Settings::setSounds(p_enabled); Settings::self()->save(); } void Game::initCharactersPosition() { // If the timer is stopped, it means that collisions are already being handled if (m_timer->isActive()) { // At the beginning, the timer is stopped but the Game isn't paused (to allow keyPressedEvent detection) m_timer->stop(); m_state = RUNNING; // Initialize Ghost coordinates and state m_ghosts[0]->initCoordinate(); m_ghosts[1]->initCoordinate(); m_ghosts[2]->initCoordinate(); m_ghosts[3]->initCoordinate(); m_kapman->initCoordinate(); m_ghosts[0]->setState(Ghost::HUNTER); m_ghosts[1]->setState(Ghost::HUNTER); m_ghosts[2]->setState(Ghost::HUNTER); m_ghosts[3]->setState(Ghost::HUNTER); m_kapman->init(); // Initialize the Pills & Energizers coordinates for (int i = 0; i < m_maze->getNbRows(); ++i) { for (int j = 0; j < m_maze->getNbColumns(); ++j) { if (m_maze->getCell(i, j).getElement() != NULL) { m_maze->getCell(i, j).getElement()->setX(Cell::SIZE * (j + 0.5)); m_maze->getCell(i, j).getElement()->setY(Cell::SIZE * (i + 0.5)); } } } } } void Game::setTimersDuration() { // Updates the timers duration ratio with the ghosts speed s_durationRatio = Character::MEDIUM_SPEED / m_ghosts[0]->getNormalSpeed(); // Updates the timers duration m_bonusTimer->setInterval((int)(s_bonusDuration * s_durationRatio)); m_preyTimer->setInterval((int)(s_preyStateDuration * s_durationRatio)); } void Game::keyPressEvent(QKeyEvent *p_event) { // At the beginning or when paused, we start the timer when an arrow key is pressed if ((p_event->key() == Qt::Key_Up || p_event->key() == Qt::Key_Down || p_event->key() == Qt::Key_Left || p_event->key() == Qt::Key_Right) && !m_timer->isActive()) { // If paused if (m_state == PAUSED_UNLOCKED) { switchPause(); } else if (m_state == RUNNING) { // At the game beginning // Start the game m_timer->start(); - emit(gameStarted()); + Q_EMIT gameStarted(); } // Tells the KgDifficulty singleton that the game now runs Kg::difficulty()->setGameRunning(true); } // Behaviour when the game has begun switch (p_event->key()) { case Qt::Key_Up: if (m_state == RUNNING) { m_kapman->goUp(); } break; case Qt::Key_Down: if (m_state == RUNNING) { m_kapman->goDown(); } break; case Qt::Key_Right: if (m_state == RUNNING) { m_kapman->goRight(); } break; case Qt::Key_Left: if (m_state == RUNNING) { m_kapman->goLeft(); } break; case Qt::Key_P: case Qt::Key_Escape: switchPause(); break; case Qt::Key_K: // Cheat code to get one more life if (p_event->modifiers() == (Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier)) { m_lives++; m_isCheater = true; - emit(livesChanged(m_lives)); + Q_EMIT livesChanged(m_lives); } break; case Qt::Key_L: // Cheat code to go to the next level if (p_event->modifiers() == (Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier)) { m_isCheater = true; nextLevel(); } break; default: break; } } void Game::update() { int curKapmanRow, curKapmanCol; // Check if the kapman is in the line of sight of a ghost curKapmanRow = m_maze->getRowFromY(m_kapman->getY()); curKapmanCol = m_maze->getColFromX(m_kapman->getX()); for (int i = 0; i < m_ghosts.size(); ++i) { if (m_ghosts[i]->getState() == Ghost::HUNTER && m_ghosts[i]->isInLineSight(m_kapman)) { m_ghosts[i]->updateMove(curKapmanRow, curKapmanCol); } else { m_ghosts[i]->updateMove(); } } m_kapman->updateMove(); m_kapman->emitGameUpdated(); } void Game::kapmanDeath() { if (m_soundEnabled) { m_soundGameOver.start(); } m_lives--; m_kapman->die(); // Make a 2 seconds pause while the kapman is blinking pause(true); QTimer::singleShot(2500, this, &Game::resumeAfterKapmanDeath); } void Game::resumeAfterKapmanDeath() { - emit(livesChanged(m_lives)); + Q_EMIT livesChanged(m_lives); // Start the timer start(); // Remove a possible bonus - emit(bonusOff()); + Q_EMIT bonusOff(); // If their is no lives left, we start a new game if (m_lives <= 0) { - emit(gameOver(true)); + Q_EMIT gameOver(true); } else { - emit(levelStarted(false)); + Q_EMIT levelStarted(false); // Move all characters to their initial positions initCharactersPosition(); } } void Game::ghostDeath(Ghost *p_ghost) { m_nbEatenGhosts++; p_ghost->setState(Ghost::EATEN); winPoints(p_ghost); } void Game::winPoints(Element *p_element) { // The value of won Points long wonPoints; // If the eaten element is a ghost, win 200 * number of eaten ghosts since the energizer was eaten if (p_element->getType() == Element::GHOST) { if (m_soundEnabled) { m_soundGhost.start(); } // Get the position of the ghost qreal xPos = p_element->getX(); qreal yPos = p_element->getY(); // Add points to the score wonPoints = p_element->getPoints() * m_nbEatenGhosts; // Send to the scene the number of points to display and its position - emit(pointsToDisplay(wonPoints, xPos, yPos)); + Q_EMIT pointsToDisplay(wonPoints, xPos, yPos); } // Else you just win the value of the element else { wonPoints = p_element->getPoints(); } // Update of the points value m_points += wonPoints; // For each 10000 points we get a life more if (m_points / 10000 > (m_points - wonPoints) / 10000) { if (m_soundEnabled) { m_soundGainLife.start(); } m_lives++; - emit(livesChanged(m_lives)); + Q_EMIT livesChanged(m_lives); } // If the eaten element is an energyzer we change the ghosts state if (p_element->getType() == Element::ENERGYZER) { // We start the prey timer m_preyTimer->start(); if (m_soundEnabled) { m_soundEnergizer.start(); } for (int i = 0; i < m_ghosts.size(); ++i) { if (m_ghosts[i]->getState() != Ghost::EATEN) { m_ghosts[i]->setState(Ghost::PREY); } } // Reset the number of eaten ghosts m_nbEatenGhosts = 0; - emit(elementEaten(p_element->getX(), p_element->getY())); + Q_EMIT elementEaten(p_element->getX(), p_element->getY()); } else if (p_element->getType() == Element::PILL) { if (m_soundEnabled) { m_soundPill.start(); } - emit(elementEaten(p_element->getX(), p_element->getY())); + Q_EMIT elementEaten(p_element->getX(), p_element->getY()); } else if (p_element->getType() == Element::BONUS) { if (m_soundEnabled) { m_soundBonus.start(); } // Get the position of the Bonus qreal xPos = p_element->getX(); qreal yPos = p_element->getY(); // Sends to the scene the number of points to display and its position - emit(pointsToDisplay(wonPoints, xPos, yPos)); + Q_EMIT pointsToDisplay(wonPoints, xPos, yPos); - emit(bonusOff()); + Q_EMIT bonusOff(); } // If 1/3 or 2/3 of the pills are eaten if (m_maze->getNbElem() == m_maze->getTotalNbElem() / 3 || m_maze->getNbElem() == (m_maze->getTotalNbElem() * 2 / 3)) { // Display the Bonus - emit(bonusOn()); + Q_EMIT bonusOn(); m_bonusTimer->start(); } - emit(scoreChanged(m_points)); + Q_EMIT scoreChanged(m_points); } void Game::nextLevel() { if (m_soundEnabled) { m_soundLevelUp.start(); } // Increment the level m_level++; // Initialize the maze items m_maze->resetNbElem(); // Update Bonus m_bonus->setPoints(m_level * 100); // Move all characters to their initial positions initCharactersPosition(); // Increase the ghosts speed for (int i = 0; i < m_ghosts.size(); ++i) { // Increase the ghosts speed increase m_ghosts[i]->increaseCharactersSpeed(); } m_kapman->increaseCharactersSpeed(); // Update the timers duration with the new speed setTimersDuration(); // Update the score, level and lives labels - emit(scoreChanged(m_points)); - emit(livesChanged(m_lives)); - emit(levelChanged(m_level)); + Q_EMIT scoreChanged(m_points); + Q_EMIT livesChanged(m_lives); + Q_EMIT levelChanged(m_level); // Update the view - emit(levelStarted(true)); + Q_EMIT levelStarted(true); } void Game::hideBonus() { - emit(bonusOff()); + Q_EMIT bonusOff(); } void Game::endPreyState() { for (int i = 0; i < m_ghosts.size(); ++i) { if (m_ghosts[i]->getState() != Ghost::EATEN) { m_ghosts[i]->setState(Ghost::HUNTER); } } } diff --git a/gameview.cpp b/gameview.cpp index 9139908..206c60e 100644 --- a/gameview.cpp +++ b/gameview.cpp @@ -1,51 +1,51 @@ /* * Copyright 2007-2008 Thomas Gallinari * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "gameview.h" #include "gamescene.h" GameView::GameView(Game *p_game) : QGraphicsView(new GameScene(p_game)) { setFrameStyle(QFrame::NoFrame); setFocusPolicy(Qt::StrongFocus); // Forward the key press events to the Game instance connect(this, &GameView::keyPressed, p_game, &Game::keyPressEvent); } GameView::~GameView() { } void GameView::resizeEvent(QResizeEvent *) { fitInView(sceneRect(), Qt::KeepAspectRatio); } void GameView::focusOutEvent(QFocusEvent *) { // Pause the game if it is not already paused if (((GameScene *)scene())->getGame()->getTimer()->isActive()) { ((GameScene *)scene())->getGame()->switchPause(); } } void GameView::keyPressEvent(QKeyEvent *p_event) { - emit(keyPressed(p_event)); + Q_EMIT keyPressed(p_event); } diff --git a/ghost.cpp b/ghost.cpp index 9c1331a..77afc6b 100644 --- a/ghost.cpp +++ b/ghost.cpp @@ -1,244 +1,244 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Alexandre Galinier * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "ghost.h" #include #include #include #include #include const qreal Ghost::MAX_SPEED_RATIO = 2.0; const int Ghost::POINTS = 200; Ghost::Ghost(qreal p_x, qreal p_y, const QString &p_imageId, Maze *p_maze) : Character(p_x, p_y, p_maze) { // Initialize the ghost attributes m_imageId = p_imageId; m_points = Ghost::POINTS; m_type = Element::GHOST; m_state = Ghost::HUNTER; m_maxSpeed = m_normalSpeed * MAX_SPEED_RATIO; // Makes the ghost move as soon as the game is created goLeft(); } Ghost::~Ghost() { } void Ghost::goUp() { m_xSpeed = 0; m_ySpeed = -m_speed; } void Ghost::goDown() { m_xSpeed = 0; m_ySpeed = m_speed; } void Ghost::goRight() { m_xSpeed = m_speed; m_ySpeed = 0; } void Ghost::goLeft() { m_xSpeed = -m_speed; m_ySpeed = 0; } void Ghost::updateMove() { // Get the current cell coordinates from the character coordinates int curCellRow = m_maze->getRowFromY(m_y); int curCellCol = m_maze->getColFromX(m_x); // Contains the different directions a ghost can choose when on a cell center QList directionsList; int nb = 0; // If the ghost is not "eaten" if (m_state != Ghost::EATEN) { // If the ghost gets on a Cell center if (onCenter()) { // We retrieve all the directions the ghost can choose (save the turning back) if (m_maze->getCell(curCellRow, curCellCol + 1).getType() == Cell::CORRIDOR || (m_maze->getCell(curCellRow, curCellCol).getType() == Cell::GHOSTCAMP && m_maze->getCell(curCellRow, curCellCol + 1).getType() == Cell::GHOSTCAMP)) { if (m_xSpeed >= 0) { directionsList.append(QPointF(m_speed, 0.0)); } } if (m_maze->getCell(curCellRow + 1, curCellCol).getType() == Cell::CORRIDOR || (m_maze->getCell(curCellRow, curCellCol).getType() == Cell::GHOSTCAMP && m_maze->getCell(curCellRow + 1, curCellCol).getType() == Cell::GHOSTCAMP)) { if (m_ySpeed >= 0) { directionsList.append(QPointF(0.0, m_speed)); } } if (m_maze->getCell(curCellRow - 1, curCellCol).getType() == Cell::CORRIDOR || (m_maze->getCell(curCellRow, curCellCol).getType() == Cell::GHOSTCAMP && m_maze->getCell(curCellRow - 1, curCellCol).getType() == Cell::GHOSTCAMP)) { if (m_ySpeed <= 0) { directionsList.append(QPointF(0.0, -m_speed)); } } if (m_maze->getCell(curCellRow, curCellCol - 1).getType() == Cell::CORRIDOR || (m_maze->getCell(curCellRow, curCellCol).getType() == Cell::GHOSTCAMP && m_maze->getCell(curCellRow, curCellCol - 1).getType() == Cell::GHOSTCAMP)) { if (m_xSpeed <= 0) { directionsList.append(QPointF(-m_speed, 0.0)); } } // Random number generation to choose one of the directions nb = int(double(QRandomGenerator::global()->bounded(RAND_MAX)) / (double(RAND_MAX) + 1) * directionsList.size()); // If there is no directions in the list, the character goes backward if (directionsList.size() == 0) { m_xSpeed = -m_xSpeed; m_ySpeed = -m_ySpeed; } else if ((m_xSpeed != 0 && m_xSpeed != directionsList[nb].x()) || (m_ySpeed != 0 && m_ySpeed != directionsList[nb].y())) { // If the chosen direction isn't forward // We move the ghost on the center of the cell and update the directions moveOnCenter(); m_xSpeed = directionsList[nb].x(); m_ySpeed = directionsList[nb].y(); } } // We move the ghost move(); } else { // If the ghost has been eaten if (onCenter()) { // If the ghost has not reached the camp yet if (m_pathToCamp.size() != 0) { // Go to the next cell to the camp updateMove(m_pathToCamp.first().y(), m_pathToCamp.first().x()); // Remove the cell the ghost has reached from the path m_pathToCamp.removeFirst(); } else { // If the ghost is not at home (that means it has just been eaten) if (curCellRow != m_maze->getResurrectionCell().y() || curCellCol != m_maze->getResurrectionCell().x()) { // Compute the path to go back to the camp m_pathToCamp = m_maze->getPathToGhostCamp(curCellRow, curCellCol); if (!m_pathToCamp.isEmpty()) { updateMove(m_pathToCamp.first().y(), m_pathToCamp.first().x()); } else { // Set the ghost at home m_x = m_maze->getResurrectionCell().x() * Cell::SIZE + Cell::SIZE / 2; m_y = m_maze->getResurrectionCell().y() * Cell::SIZE + Cell::SIZE / 2; setState(Ghost::HUNTER); } } else { // The ghost has reached the ghost camp setState(Ghost::HUNTER); } } } move(); } } void Ghost::updateMove(int p_row, int p_col) { // Get the current cell coordinates from the ghost coordinates int curGhostRow = m_maze->getRowFromY(m_y); int curGhostCol = m_maze->getColFromX(m_x); if (onCenter()) { if (curGhostRow == p_row) { if (p_col > curGhostCol) { m_xSpeed = m_speed; m_ySpeed = 0; } else { m_xSpeed = -m_speed; m_ySpeed = 0; } } else { if (p_row > curGhostRow) { m_xSpeed = 0; m_ySpeed = m_speed; } else { m_xSpeed = 0; m_ySpeed = -m_speed; } } } // We move the ghost move(); } QString Ghost::getImageId() const { return m_imageId; } Ghost::State Ghost::getState() const { return m_state; } void Ghost::setState(Ghost::State p_state) { // Change the state m_state = p_state; switch (m_state) { case Ghost::PREY: m_speed = m_normalSpeed / 2; break; case HUNTER: case EATEN: m_speed = m_normalSpeed; break; } - emit(stateChanged()); + Q_EMIT stateChanged(); } void Ghost::doActionOnCollision(Kapman *) { switch (m_state) { case Ghost::HUNTER: - emit(lifeLost()); + Q_EMIT lifeLost(); break; case Ghost::PREY: - emit(ghostEaten(this)); + Q_EMIT ghostEaten(this); break; case Ghost::EATEN: // Do nothing break; } } void Ghost::initSpeedInc() { // Ghosts speed increase when level up switch ((int) Kg::difficultyLevel()) { case KgDifficultyLevel::Easy: m_speedIncrease = Character::LOW_SPEED_INC; break; case KgDifficultyLevel::Medium: m_speedIncrease = Character::MEDIUM_SPEED_INC; break; case KgDifficultyLevel::Hard: m_speedIncrease = Character::HIGH_SPEED_INC; break; } } diff --git a/kapman.cpp b/kapman.cpp index 9c6ba13..0cf5bd7 100644 --- a/kapman.cpp +++ b/kapman.cpp @@ -1,207 +1,207 @@ /* * Copyright 2007-2008 Thomas Gallinari * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "kapman.h" #include const qreal Kapman::MAX_SPEED_RATIO = 1.5; Kapman::Kapman(qreal p_x, qreal p_y, Maze *p_maze) : Character(p_x, p_y, p_maze) { m_type = Element::KAPMAN; m_maxSpeed = m_normalSpeed * MAX_SPEED_RATIO; } Kapman::~Kapman() { } void Kapman::init() { goRight(); updateDirection(); // Stop animation - emit(stopped()); + Q_EMIT stopped(); } void Kapman::goUp() { m_askedXSpeed = 0; m_askedYSpeed = -m_speed; } void Kapman::goDown() { m_askedXSpeed = 0; m_askedYSpeed = m_speed; } void Kapman::goRight() { m_askedXSpeed = m_speed; m_askedYSpeed = 0; } void Kapman::goLeft() { m_askedXSpeed = -m_speed; m_askedYSpeed = 0; } void Kapman::updateDirection() { setXSpeed(m_askedXSpeed); setYSpeed(m_askedYSpeed); m_askedXSpeed = 0; m_askedYSpeed = 0; // Signal to the kapman item that the direction changed - emit(directionChanged()); + Q_EMIT directionChanged(); } void Kapman::updateMove() { // If the kapman does not move if (m_xSpeed == 0 && m_ySpeed == 0) { // If the user asks for moving if (m_askedXSpeed != 0 || m_askedYSpeed != 0) { // Check the next cell with the asked direction if (getAskedNextCell().getType() == Cell::CORRIDOR) { // Update the direction updateDirection(); // Move the kapman move(); } } } // If the kapman is already moving else { // If the kapman wants to go back it does not wait to be on a center if ((m_xSpeed != 0 && m_askedXSpeed == -m_xSpeed) || (m_ySpeed != 0 && m_askedYSpeed == -m_ySpeed)) { // Go back updateDirection(); // If the kapman just turned at a corner and instantly makes a half-turn, do not run into a wall if (isOnCenter() && getNextCell().getType() != Cell::CORRIDOR) { // Stop moving stopMoving(); } else { // Move the kapman move(); } } else { // If the kapman gets on a cell center if (onCenter()) { // If there is an asked direction (not a half-turn) and the corresponding next cell is accessible if ((m_askedXSpeed != 0 || m_askedYSpeed != 0) && (m_askedXSpeed != m_xSpeed || m_askedYSpeed != m_ySpeed) && (getAskedNextCell().getType() == Cell::CORRIDOR)) { // Move the kapman on the cell center moveOnCenter(); // Update the direction updateDirection(); } else { // Check the next cell with the kapman current direction if (getNextCell().getType() != Cell::CORRIDOR) { // Move the kapman on the cell center moveOnCenter(); // Stop moving stopMoving(); } else { // Move the kapman move(); } } } else { // Move the kapman move(); } } } } void Kapman::winPoints(Element *p_element) { // Emits a signal to the game - emit(sWinPoints(p_element)); + Q_EMIT sWinPoints(p_element); } void Kapman::die() { - emit(eaten()); + Q_EMIT eaten(); } void Kapman::emitGameUpdated() { - emit(gameUpdated()); + Q_EMIT gameUpdated(); } qreal Kapman::getAskedXSpeed() const { return m_askedXSpeed; } qreal Kapman::getAskedYSpeed() const { return m_askedYSpeed; } Cell Kapman::getAskedNextCell() { // Get the current cell coordinates from the character coordinates int curCellRow = m_maze->getRowFromY(m_y); int curCellCol = m_maze->getColFromX(m_x); Cell nextCell; // Get the next cell function of the character asked direction if (m_askedXSpeed > 0) { nextCell = m_maze->getCell(curCellRow, curCellCol + 1); } else if (m_askedXSpeed < 0) { nextCell = m_maze->getCell(curCellRow, curCellCol - 1); } else if (m_askedYSpeed > 0) { nextCell = m_maze->getCell(curCellRow + 1, curCellCol); } else if (m_askedYSpeed < 0) { nextCell = m_maze->getCell(curCellRow - 1, curCellCol); } return nextCell; } void Kapman::stopMoving() { setXSpeed(0); setYSpeed(0); m_askedXSpeed = 0; m_askedYSpeed = 0; - emit(stopped()); + Q_EMIT stopped(); } void Kapman::initSpeedInc() { // Kapman speed increase when level up switch ((int) Kg::difficultyLevel()) { case KgDifficultyLevel::Easy: m_speedIncrease = Character::LOW_SPEED_INC / 2; break; case KgDifficultyLevel::Medium: m_speedIncrease = Character::MEDIUM_SPEED_INC / 2; break; case KgDifficultyLevel::Hard: m_speedIncrease = Character::HIGH_SPEED_INC / 2; break; } } diff --git a/maze.cpp b/maze.cpp index 917cc05..0729036 100644 --- a/maze.cpp +++ b/maze.cpp @@ -1,242 +1,242 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Pierre-Benoît Besse * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "maze.h" #include #include Maze::Maze() : m_totalNbElem(0), m_nbElem(0) { } Maze::~Maze() { for (int i = 0 ; i < m_nbRows; ++i) { delete[] m_cells[i]; } delete[] m_cells; } void Maze::init(const int p_nbRows, const int p_nbColumns) { m_nbRows = p_nbRows; m_nbColumns = p_nbColumns; m_cells = new Cell*[m_nbRows]; for (int i = 0; i < m_nbRows; ++i) { m_cells[i] = new Cell[m_nbColumns]; } } void Maze::setCellType(const int p_row, const int p_column, const Cell::Type p_type) { if (p_row < 0 || p_row >= m_nbRows || p_column < 0 || p_column >= m_nbColumns) { qCritical() << "Bad maze coordinates"; } m_cells[p_row][p_column].setType(p_type); } void Maze::setCellElement(const int p_row, const int p_column, Element *p_element) { if (p_row < 0 || p_row >= m_nbRows || p_column < 0 || p_column >= m_nbColumns) { qCritical() << "Bad maze coordinates"; } m_cells[p_row][p_column].setElement(p_element); if (p_element != NULL) { m_totalNbElem++; m_nbElem++; } } void Maze::setResurrectionCell(QPoint p_resurrectionCell) { // TODO : COORDINATES INVERTED, NEED TO CORRECT IT in the findPAth algorithm m_resurrectionCell.setX(p_resurrectionCell.y()); m_resurrectionCell.setY(p_resurrectionCell.x()); } void Maze::decrementNbElem() { m_nbElem--; if (m_nbElem == 0) { - emit(allElementsEaten()); + Q_EMIT allElementsEaten(); } } void Maze::resetNbElem() { m_nbElem = m_totalNbElem; } QList Maze::getPathToGhostCamp(const int p_row, const int p_column) const { QList path; QList openList; QList closedList; QPoint currentCell; QPoint tmpCell; int lowestCost; int icurrent = 0; int oldSize = 0; // Initialize the starting cell m_cells[p_row][p_column].setCost(abs(m_resurrectionCell.y() - p_row) + abs(m_resurrectionCell.x() - p_column)); // Add the starting cell to the openList openList.append(QPoint(p_column, p_row)); // While the closed list does not contain the target cell while (!closedList.contains(QPoint(m_resurrectionCell.x(), m_resurrectionCell.y())) && openList.size() != oldSize) { // Look for the lowest cost cell on the open list lowestCost = 1000; for (int i = 0; i < openList.size(); ++i) { if (m_cells[openList[i].y()][openList[i].x()].getCost() < lowestCost) { lowestCost = m_cells[openList[i].y()][openList[i].x()].getCost(); currentCell = openList[i]; icurrent = i; } } // Switch this cell to the closed list closedList.append(currentCell); openList.removeAt(icurrent); oldSize = openList.size(); // For each of the 4 cells adjacent to the current node // Left tmpCell.setX(currentCell.x() - 1); tmpCell.setY(currentCell.y()); if (m_cells[tmpCell.y()][tmpCell.x()].getType() != Cell::WALL) { // If the cell is not in the closed list or the open list if (!closedList.contains(tmpCell) && !openList.contains(tmpCell)) { // Initialize the cell m_cells[tmpCell.y()][tmpCell.x()].setCost( abs(m_resurrectionCell.y() - tmpCell.y()) + abs(m_resurrectionCell.x() - (tmpCell.x()))); m_cells[tmpCell.y()][tmpCell.x()].setParent(&m_cells[currentCell.y()][currentCell.x()]); // Add it to the open list openList.append(tmpCell); } } // Right tmpCell.setX(currentCell.x() + 1); tmpCell.setY(currentCell.y()); if (m_cells[tmpCell.y()][tmpCell.x()].getType() != Cell::WALL) { // If the cell is not in the closed list or the open list if (!closedList.contains(tmpCell) && !openList.contains(tmpCell)) { // Initialize the cell m_cells[tmpCell.y()][tmpCell.x()].setCost( abs(m_resurrectionCell.y() - tmpCell.y()) + abs(m_resurrectionCell.x() - (tmpCell.x()))); m_cells[tmpCell.y()][tmpCell.x()].setParent(&m_cells[currentCell.y()][currentCell.x()]); // Add it to the open list openList.append(tmpCell); } } // Top tmpCell.setX(currentCell.x()); tmpCell.setY(currentCell.y() - 1); if (m_cells[tmpCell.y()][tmpCell.x()].getType() != Cell::WALL) { // If the cell is not in the closed list or the open list if (!closedList.contains(tmpCell) && !openList.contains(tmpCell)) { // Initialize the cell m_cells[tmpCell.y()][tmpCell.x()].setCost( abs(m_resurrectionCell.y() - tmpCell.y()) + abs(m_resurrectionCell.x() - (tmpCell.x()))); m_cells[tmpCell.y()][tmpCell.x()].setParent(&m_cells[currentCell.y()][currentCell.x()]); // Add it to the open list openList.append(tmpCell); } } // Bottom tmpCell.setX(currentCell.x()); tmpCell.setY(currentCell.y() + 1); if (m_cells[tmpCell.y()][tmpCell.x()].getType() != Cell::WALL) { // If the cell is not in the closed list or the open list if (!closedList.contains(tmpCell) && !openList.contains(tmpCell)) { // Initialize the cell m_cells[tmpCell.y()][tmpCell.x()].setCost( abs(m_resurrectionCell.y() - tmpCell.y()) + abs(m_resurrectionCell.x() - (tmpCell.x()))); m_cells[tmpCell.y()][tmpCell.x()].setParent(&m_cells[currentCell.y()][currentCell.x()]); // Add it to the open list openList.append(tmpCell); } } } if (oldSize == openList.size()) { qCritical() << "Path to ghost home not found"; return QList(); } // Save the path : from the target cell, go from each cell to its parent cell until reaching the starting cell for (Cell *cell = &m_cells[m_resurrectionCell.y()][m_resurrectionCell.x()]; cell->getParent() != &m_cells[p_row][p_column]; cell = cell->getParent()) { path.prepend(getCoords(cell)); } return path; } Cell Maze::getCell(const int p_row, const int p_column) const { if (p_row < 0 || p_row >= m_nbRows || p_column < 0 || p_column >= m_nbColumns) { qCritical() << "Bad maze coordinates"; } return m_cells[p_row][p_column]; } QPoint Maze::getCoords(Cell *p_cell) const { for (int i = 0; i < m_nbRows; ++i) { for (int j = 0; j < m_nbColumns; ++j) { if (&m_cells[i][j] == p_cell) { return QPoint(j, i); } } } return QPoint(); } int Maze::getRowFromY(const qreal p_y) const { return (int)(p_y / Cell::SIZE); } int Maze::getColFromX(const qreal p_x) const { return (int)(p_x / Cell::SIZE); } int Maze::getNbColumns() const { return m_nbColumns; } int Maze::getNbRows() const { return m_nbRows; } int Maze::getNbElem() const { return m_nbElem; } int Maze::getTotalNbElem() const { return m_totalNbElem; } QPoint Maze::getResurrectionCell() const { return m_resurrectionCell; } diff --git a/pill.h b/pill.h index 401b5e3..1879c15 100644 --- a/pill.h +++ b/pill.h @@ -1,56 +1,56 @@ /* * Copyright 2007-2008 Thomas Gallinari * Copyright 2007-2008 Gaël Courcelle * Copyright 2007-2008 Alexia Allanic * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef PILL_H #define PILL_H #include "element.h" /** * @brief This class represents a Pill enabling to earn points. */ class Pill : public Element { - + Q_OBJECT public: /** The Pill value */ static const int POINTS; public: /** * Creates a new Pill instance. */ Pill(qreal p_x, qreal p_y, Maze *p_maze, const QString &p_imageId); /** * Deletes the Pill instance. */ ~Pill(); /** * Computes an action on a collision with the Kapman. * @param p_kapman the instance of Kapman which collides with the Pill */ void doActionOnCollision(Kapman *p_kapman) override; }; #endif