Skip to content

Commit

Permalink
solves issue#5 for at least all circular objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kaa-ching committed Aug 11, 2015
1 parent ecffabf commit 1897c8a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpointer-arith -DQT_NO
find_package(Qt4 REQUIRED)
ADD_DEFINITIONS(${QT_DEFINITIONS})

QT4_WRAP_CPP(tbe_HEADERS_MOC ${control_HEADERS} ${view_HEADERS} model/World.h loadsave/Level.h)
QT4_WRAP_CPP(tbe_HEADERS_MOC ${control_HEADERS} ${view_HEADERS} ${model_HEADERS} ${loadsave_HEADERS})
QT4_WRAP_UI(tbe_FORMS_HEADERS ${tbe_UIFORMS})
QT4_ADD_RESOURCES(tbe_RESOURCES_RCC ${view_RESOURCES})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Expand Down
7 changes: 5 additions & 2 deletions src/loadsave/ObjectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "AbstractObjectPtr.h"
#include "Position.h"
#include <QObject>
#include <QList>

/**
Expand All @@ -30,13 +31,15 @@
* There should be a static instance in each Object's cpp file.
* At system start it will announce the type to Level and do the real Object creation.
*/
class ObjectFactory
class ObjectFactory : public QObject
{
Q_OBJECT

// there's nothing public here - nobody should call anything in this class
// directly.
public:
/// empty virtual destructor
virtual ~ObjectFactory() {;}
virtual ~ObjectFactory() {;}

typedef QList<const ObjectFactory*> ObjectFactoryList;

Expand Down
55 changes: 10 additions & 45 deletions src/model/CircleObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,78 +22,43 @@
#include "CircleObjects.h"
//#include "ViewCircleObject.h"
#include "Property.h"
#include "ObjectFactory.h"

/** the CircleObject's ObjectFactory
* note that it is slightly more complex than usual, because it is generalised
* to create any type of ball. Below the declaration, there will be several
* global instances each identifying one ball type
*/
class BallObjectFactory : public ObjectFactory
{
public:
BallObjectFactory(
const QString& anInternalName,
const QString& aDisplayName,
const QString& aTooltip,
const QString& anImageName,
qreal aRadius,
qreal aMass,
qreal aBounciness)
: theDisplayName(aDisplayName), theTooltip(aTooltip),
theImageName(anImageName), theRadius(aRadius),
theMass(aMass), theBounciness(aBounciness)
{ announceObjectType(anInternalName, this); }

virtual AbstractObject* createObject(void) const
{ return fixObject(new CircleObject(theDisplayName, theTooltip, theImageName,
theRadius, theMass, theBounciness)); }
private:
QString theDisplayName;
QString theTooltip;
QString theImageName;
qreal theRadius;
qreal theMass;
qreal theBounciness;
};


// we are lazy and do not model the holes in the ball, nor do we attempt to model
// the non-uniform weight distribution in the ball - we assume it to be uniform
static BallObjectFactory theBBFactory("BowlingBall",
QObject::tr("Bowling Ball"),
QObject::tr("Your average bowling ball - heavy, round and willing to roll"),
QT_TRANSLATE_NOOP("BallObjectFactory", "Bowling Ball"),
QT_TRANSLATE_NOOP("BallObjectFactory", "Your average bowling ball - heavy, round and willing to roll"),
"BowlingBall", 0.11, 6.0, 0.1 );

// we are lazy and do not model the air, we assume it to be uniform in mass
static BallObjectFactory theVBFactory("VolleyBall",
QObject::tr("Volley Ball"),
QObject::tr("A volley ball - you know: light, soft and fairly bouncy."),
QT_TRANSLATE_NOOP("BallObjectFactory", "Volley Ball"),
QT_TRANSLATE_NOOP("BallObjectFactory", "A volley ball - you know: light, soft and fairly bouncy."),
"VolleyBall", 0.105, 0.280, 0.65);


// the official standards say that a tennis ball dropped from 100 inch should bounce 53-58 inch.
// thanks to http://en.wikipedia.org/wiki/Tennis_ball
// we are lazy and do not model the air, we assume it to be uniform in mass
static BallObjectFactory theTBFactory("TennisBall",
QObject::tr("Tennis Ball"),
QObject::tr("A tennis ball is small, fuzzy and known for turning heads."),
QT_TRANSLATE_NOOP("BallObjectFactory", "Tennis Ball"),
QT_TRANSLATE_NOOP("BallObjectFactory", "A tennis ball is small, fuzzy and known for turning heads."),
"TennisBall", 0.034, 0.058, 0.56);

// the official standards say that a soccer is 68-70cm circumference and weighs 410-450 grams
// thanks to http://en.wikipedia.org/wiki/Football_(ball)
// we are lazy and do not model the air, we assume it to be uniform in mass
static BallObjectFactory theSoccerFactory("SoccerBall",
QObject::tr("Soccer Ball"),
QObject::tr("A football (of the spherical persuasion)."),
QT_TRANSLATE_NOOP("BallObjectFactory", "Soccer Ball"),
QT_TRANSLATE_NOOP("BallObjectFactory", "A football (of the spherical persuasion)."),
"SoccerBall", 0.110, 0.430, 0.56);

// there is not much of official standards for a petanque ball, but
// thanks to http://en.wikipedia.org/wiki/Petanque we at least know:
// diameter between 70.5 and 80mm, weight between 650 and 800 grams.
static BallObjectFactory thePetanqueFactory("PetanqueBoule",
QObject::tr("Petanque Boule"), // TODO/FIXME: there should be an accent on the e
QObject::tr("A petanque ball is made of metal and heavy."),
QT_TRANSLATE_NOOP("BallObjectFactory", "Pétanque Boule"),
QT_TRANSLATE_NOOP("BallObjectFactory", "A pétanque ball is made of metal and heavy."),
"PetanqueBoule", 0.038, 0.700, 0.1);

// Constructors/Destructors
Expand Down
40 changes: 40 additions & 0 deletions src/model/CircleObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CIRCLEOBJECTS_H

#include "AbstractObject.h"
#include <QObject>

/**
* class CircleObject
Expand Down Expand Up @@ -94,4 +95,43 @@ class CustomBall : public CircleObject
virtual void parseProperties(void);
};


#include "ObjectFactory.h"

/** the CircleObject's ObjectFactory
* note that it is slightly more complex than usual, because it is generalised
* to create any type of ball. Below the declaration, there will be several
* global instances each identifying one ball type
*/
class BallObjectFactory : public ObjectFactory
{
Q_OBJECT

public:
BallObjectFactory(
const QString& anInternalName,
const char* aDisplayName,
const char* aTooltip,
const QString& anImageName,
qreal aRadius,
qreal aMass,
qreal aBounciness)
: theDisplayName(aDisplayName), theTooltip(aTooltip),
theImageName(anImageName), theRadius(aRadius),
theMass(aMass), theBounciness(aBounciness)
{ announceObjectType(anInternalName, this); }

virtual AbstractObject* createObject(void) const
{ return fixObject(new CircleObject(tr(theDisplayName), tr(theTooltip), theImageName,
theRadius, theMass, theBounciness)); }
private:
const char* theDisplayName;
const char* theTooltip;
QString theImageName;
qreal theRadius;
qreal theMass;
qreal theBounciness;
};


#endif // CIRCLEOBJECTS_H

0 comments on commit 1897c8a

Please sign in to comment.