Sure. It's all open-source, so I'll post anything you'd like. I just didn't want to get flamed for making any horrendously long posts...
The main window inherits from the GUI done in QT Designer:
{
Q_OBJECT
public:
Xorbz
( QWidget* parent
= 0, Qt
::WFlags fl
= Qt
::Window );
~Xorbz();
public slots:
virtual void gameNew(); ///< Create a new game (solo or network)
virtual void gameJoin(); ///< Join a network game
virtual void gameExit(); ///< Quit playing XorbZ
virtual void helpIndex(); ///< Open the help index
virtual void helpContents(); ///< Open the help contents
virtual void helpAbout(); ///< Display a dialog with XorbZ info
virtual void helpAboutQt(); ///< Display information about Qt
virtual void toolsExportLevel(); ///< Save a XorbZ level to text format
virtual void toolsImportTextLevel(); ///< Generate a XorbZ level from a text file
void playSound( SoundType s ) { if( sounds[s]) sounds[s]->play(); };
protected:
class Xorbz_Game* currentGame; ///< The current XorbZ game
void sendToServer
( QString message
);
private:
void updateScores();
void initGui(); ///< Initialize the GUI
Xorbz_Sound* sounds[ NumSounds ]; ///< An array of sounds for various events
Xorbz_GameInfo* myGameInfo; ///< A pointer to the game information struct
Xorbz_Board* myBoard; ///< The graphics scene
Xorbz_Level* myLevel; ///< A pointer to the XorbZ level being played
QTcpSocket* tcpSocket;
///< The connection to the game server
void showStatus
( QString msg,
int t
=0 ) { QMainWindow::statusBar()->showMessage
( msg, t
);
};
private slots:
void networkRead();
};
class Xorbz : public QMainWindow, private Ui::XorbzGui
{
Q_OBJECT
public:
Xorbz( QWidget* parent = 0, Qt::WFlags fl = Qt::Window );
~Xorbz();
bool event( QEvent* e );
public slots:
virtual void gameNew(); ///< Create a new game (solo or network)
virtual void gameJoin(); ///< Join a network game
virtual void gameExit(); ///< Quit playing XorbZ
virtual void helpIndex(); ///< Open the help index
virtual void helpContents(); ///< Open the help contents
virtual void helpAbout(); ///< Display a dialog with XorbZ info
virtual void helpAboutQt(); ///< Display information about Qt
virtual void toolsExportLevel(); ///< Save a XorbZ level to text format
virtual void toolsImportTextLevel(); ///< Generate a XorbZ level from a text file
void playSound( SoundType s ) { if( sounds[s]) sounds[s]->play(); };
protected:
class Xorbz_Game* currentGame; ///< The current XorbZ game
void sendToServer( QString message );
private:
void updateScores();
void initGui(); ///< Initialize the GUI
Xorbz_Sound* sounds[ NumSounds ]; ///< An array of sounds for various events
Xorbz_GameInfo* myGameInfo; ///< A pointer to the game information struct
Xorbz_Board* myBoard; ///< The graphics scene
Xorbz_Level* myLevel; ///< A pointer to the XorbZ level being played
QGraphicsView* viewFrame;
QTcpSocket* tcpSocket; ///< The connection to the game server
void networkConnect( QHostAddress server );
void showStatus( QString msg, int t=0 ) { QMainWindow::statusBar()->showMessage( msg, t ); };
private slots:
void networkRead();
void networkError( QAbstractSocket::SocketError e );
};
To copy to clipboard, switch view to plain text mode
The main window initializes like so. Note that viewFrame is the name of the QGraphicsView:
Xorbz
::Xorbz( QWidget* parent, Qt
::WFlags fl
){
// Create a splash screen
s->show();
s->showMessage( "Xorbz is loading...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
currentGame = NULL;
myGameInfo = NULL;
// Initialize the GUI
initGui();
setUpdatesEnabled( true );
// Load the graphics
qDebug( "Loading graphics..." );
s->showMessage("Loading graphics...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
myBoard = new Xorbz_Board( /*this*/ );
// Initialize the sound system
...
// Other initialization
s->showMessage("Finishing up initialization...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
// Seed random numbers
myLevel = new Xorbz_Level();
// Close the splash screen
s->finish( this );
delete s;
}
Xorbz::Xorbz( QWidget* parent, Qt::WFlags fl)
: QMainWindow( parent, fl)
{
// Create a splash screen
QSplashScreen* s = new QSplashScreen( QPixmap::QPixmap( SplashScreenPixmap ) );
s->show();
s->showMessage( "Xorbz is loading...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
currentGame = NULL;
myGameInfo = NULL;
// Initialize the GUI
initGui();
setUpdatesEnabled( true );
// Load the graphics
qDebug( "Loading graphics..." );
s->showMessage("Loading graphics...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
myBoard = new Xorbz_Board( /*this*/ );
viewFrame->setScene( (QGraphicsScene*)myBoard );
// Initialize the sound system
...
// Other initialization
s->showMessage("Finishing up initialization...", Qt::AlignLeft | Qt::AlignBottom, QCOLOR_WHITE );
// Seed random numbers
srand( QTime::QTime().secsTo(QTime::currentTime()) );
tcpSocket = new QTcpSocket(this);
myLevel = new Xorbz_Level();
// Close the splash screen
s->finish( this );
delete s;
}
To copy to clipboard, switch view to plain text mode
The initGui() function referenced is here:
void Xorbz::initGui( void )
{
// First start the UI from the designer
setupUi( this );
// Now add all the components not present
setWindowTitle( "XorbZ" );
// Connect actions to slots
...
}
void Xorbz::initGui( void )
{
// First start the UI from the designer
setupUi( this );
// Now add all the components not present
setWindowTitle( "XorbZ" );
// Connect actions to slots
...
}
To copy to clipboard, switch view to plain text mode
The scene is subclassed into Xorbz_Board:
{
public:
Xorbz_Board
( QObject* parent
= NULL );
~Xorbz_Board( void );
void setLevel( Xorbz_Level* newLevel = NULL );
void setInfo( Xorbz_GameInfo* gameInfo );
Xorbz_Marker* addMarker( Xorbz_Node* node );
Xorbz_Marker* moveMarker( Xorbz_Node* from, Xorbz_Node* to );
private:
QTimer* timer;
///< The animation timer Xorbz_Graphics* graphics; ///< The graphics used to draw the board
Xorbz_Level* level; ///< A pointer to the current level
QList<Xorbz_Marker*> markers; ///< Markers on the board
QList<Xorbz_PlayerDisplay*> players; ///< Player info displays
};
class Xorbz_Board : public QGraphicsScene
{
public:
Xorbz_Board( QObject* parent = NULL );
~Xorbz_Board( void );
void setLevel( Xorbz_Level* newLevel = NULL );
void setInfo( Xorbz_GameInfo* gameInfo );
Xorbz_Marker* addMarker( Xorbz_Node* node );
Xorbz_Marker* moveMarker( Xorbz_Node* from, Xorbz_Node* to );
private:
QTimer* timer; ///< The animation timer
Xorbz_Graphics* graphics; ///< The graphics used to draw the board
Xorbz_Level* level; ///< A pointer to the current level
QList<Xorbz_Marker*> markers; ///< Markers on the board
QList<Xorbz_PlayerDisplay*> players; ///< Player info displays
};
To copy to clipboard, switch view to plain text mode
And the board gets initialized like so:
Xorbz_Board
::Xorbz_Board( QObject* parent
){
// Create the graphics
graphics = new Xorbz_Graphics();
// Set the default background
setBackgroundBrush( QCOLOR_BACKGROUND );
// Setup an animation timer
connect(timer, SIGNAL(timeout()), this, SLOT(advance()));
timer->start( SceneUpdatePeriod );
}
Xorbz_Board::Xorbz_Board( QObject* parent )
: QGraphicsScene( 0, 0, 640, 480, parent )
{
// Create the graphics
graphics = new Xorbz_Graphics();
// Set the default background
setBackgroundBrush( QCOLOR_BACKGROUND );
// Setup an animation timer
timer = new QTimer( this );
connect(timer, SIGNAL(timeout()), this, SLOT(advance()));
timer->start( SceneUpdatePeriod );
}
To copy to clipboard, switch view to plain text mode
Most of the scene items are added by the setLevel function:
void Xorbz_Board::setLevel( Xorbz_Level* newLevel )
{
// Clear the scene of all components
qDeleteAll( items() );
// Store a pointer to the new level
level = newLevel;
// Now reconstruct the board with new level items
if( level )
{
quint8 scale = level->scale;
quint8 width = level->width;
Xorbz_GNode* gn;
int i, x, y;
// Set the graphics, including background
setBackgroundBrush( *level->background );
graphics->scale( scale );
// Create GNodes and Markers
for(i=0; i<(int)(width*level->height); i++)
{
Xorbz_Node* n = level->node(i);
if( n->type() != Xorbz_Node::NodeTypeNone )
{
// Calculate the location for this node
y = level->gridOriginY + scale*(i / width) - scale/2;
x = level->gridOriginX + scale*(i % width) - ( i/width & 1 ? 0 : scale/2 );
// Create the GNode
gn = new Xorbz_GNode( n, graphics );
gn->setPos( x, y );
gn->setAcceptedMouseButtons(0);
addItem( gn );
// If the node is occupied...
if( n->type() >= Xorbz_Node::NodeTypePlayer1 )
{
// ...Create a marker
addMarker( n );
}
}
}
// Create a title
title->setPos( LevelTitleX, LevelTitleY );
title->setZValue( LevelTitleZ );
title->setDefaultTextColor( QCOLOR_LEVEL_TITLE );
title->setVisible( true );
}
// Update the scene
update();
}
void Xorbz_Board::setLevel( Xorbz_Level* newLevel )
{
// Clear the scene of all components
qDeleteAll( items() );
// Store a pointer to the new level
level = newLevel;
// Now reconstruct the board with new level items
if( level )
{
quint8 scale = level->scale;
quint8 width = level->width;
Xorbz_GNode* gn;
int i, x, y;
// Set the graphics, including background
setBackgroundBrush( *level->background );
graphics->scale( scale );
// Create GNodes and Markers
for(i=0; i<(int)(width*level->height); i++)
{
Xorbz_Node* n = level->node(i);
if( n->type() != Xorbz_Node::NodeTypeNone )
{
// Calculate the location for this node
y = level->gridOriginY + scale*(i / width) - scale/2;
x = level->gridOriginX + scale*(i % width) - ( i/width & 1 ? 0 : scale/2 );
// Create the GNode
gn = new Xorbz_GNode( n, graphics );
gn->setPos( x, y );
gn->setAcceptedMouseButtons(0);
addItem( gn );
// If the node is occupied...
if( n->type() >= Xorbz_Node::NodeTypePlayer1 )
{
// ...Create a marker
addMarker( n );
}
}
}
// Create a title
QGraphicsTextItem* title = addText( level->title, QFONT_LEVEL_TITLE );
title->setPos( LevelTitleX, LevelTitleY );
title->setZValue( LevelTitleZ );
title->setDefaultTextColor( QCOLOR_LEVEL_TITLE );
title->setVisible( true );
}
// Update the scene
update();
}
To copy to clipboard, switch view to plain text mode
I think the core of the problem is in there someplace. I can provide the code for the other classes as well (eg Xorbz_GNode, et al) if you think the issue may be there.
Thanks!
Bookmarks