All pastes #924250 Raw Edit

Mine

public cpp v1 · immutable
·published 2008-03-01 04:42 UTC
rendered paste body
//---------------------------------------------------------//---------------------------------------------------------// game.h#ifndef GAME_H#define GAME_H#include <QList>#include <QObject>#include <QString>#include <QTimer>#include "faction.h"#include "map.h"#include "projectile.h"class Game : public QObject{    Q_OBJECTpublic:    Game(QString name, bool multiplayer, QString mapName);    ~Game();    bool loadMap(QString mapName);    void unloadMap();    void start();    void finish();    Map *getMap() { return map; };    bool isActive() { return active; };public slots:    void fastTimerEvent(QTimerEvent *);    void mediumTimerEvent(QTimerEvent *);    void slowTimerEvent(QTimerEvent *);protected:    QString name;    bool multiplayer;    Map *map;    bool active;    QTimer fastTimer, mediumTimer, slowTimer;    QList<Faction *> factions;    QList<Projectile *> projectiles;};#endif//---------------------------------------------------------//---------------------------------------------------------// game.cpp#include <QDebug>#include "game.h"Game::Game(QString name, bool multiplayer, QString mapName)  : QObject(),    name(name),    multiplayer(multiplayer),    map(0),    active(false),    fastTimer(),    mediumTimer(),    slowTimer(){    loadMap(mapName);    connect(&fastTimer, SIGNAL(timeout()), this, SLOT(fastTimerEvent()));    connect(&mediumTimer, SIGNAL(timeout()), this, SLOT(mediumTimerEvent()));    connect(&slowTimer, SIGNAL(timeout()), this, SLOT(slowTimerEvent()));    // Testing data    factions.append(new Faction(1, this));    factions.append(new Faction(2, this));}Game::~Game(){    finish();    unloadMap();}bool Game::loadMap(QString mapName){    map = Map::getMap(mapName);    if(!map)        return false;    return true;}void Game::unloadMap(){    if(!map)        return;    map->notUsed();    map = 0;}void Game::start(){    if(active)        return;    fastTimer.start(20);    mediumTimer.start(500);    slowTimer.start(1000);    active = true;}void Game::finish(){    if(!active)        return;    fastTimer.stop();    mediumTimer.stop();    slowTimer.stop();    active = false;}void Game::fastTimerEvent(QTimerEvent *){    qDebug() << "Fast";}void Game::mediumTimerEvent(QTimerEvent *){    qDebug() << "Medium";}void Game::slowTimerEvent(QTimerEvent *){    qDebug() << "Slow";}