GameBoard Class Reference

#include <gameboard.h>

Inheritance diagram for GameBoard:

Inheritance graph
[legend]
Collaboration diagram for GameBoard:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 32 of file gameboard.h.

Public Member Functions

 GameBoard (QWidget *parent=0)
 GameBoard (QWidget *parent=0)

Protected Slots

void fire ()
void hit ()
void missed ()
void newGame ()
void fire ()
void hit ()
void missed ()
void newGame ()

Private Attributes

QLCDNumberhits
QLCDNumbershotsLeft
CannonFieldcannonField
QLCDNumberhits
QLCDNumbershotsLeft
CannonFieldcannonField


Constructor & Destructor Documentation

GameBoard::GameBoard ( QWidget parent = 0  ) 

Definition at line 37 of file gameboard.cpp.

References QGridLayout::addLayout(), QBoxLayout::addStretch(), QGridLayout::addWidget(), QBoxLayout::addWidget(), angle(), QFont::Bold, cannonField, QObject::connect(), QLCDNumber::Filled, fire(), hit(), hits, missed(), newGame(), qApp, QGridLayout::setColumnStretch(), QWidget::setEnabled(), QWidget::setFont(), QWidget::setLayout(), LCDRange::setRange(), QLCDNumber::setSegmentStyle(), LCDRange::setValue(), shotsLeft, SIGNAL, and SLOT.

00038     : QWidget(parent)
00039 {
00040     QPushButton *quit = new QPushButton(tr("&Quit"));
00041     quit->setFont(QFont("Times", 18, QFont::Bold));
00042 
00043     connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
00044 
00045     LCDRange *angle = new LCDRange(tr("ANGLE"));
00046     angle->setRange(5, 70);
00047 
00048     LCDRange *force = new LCDRange(tr("FORCE"));
00049     force->setRange(10, 50);
00050 
00051     cannonField = new CannonField;
00052 
00053     connect(angle, SIGNAL(valueChanged(int)),
00054             cannonField, SLOT(setAngle(int)));
00055     connect(cannonField, SIGNAL(angleChanged(int)),
00056             angle, SLOT(setValue(int)));
00057 
00058     connect(force, SIGNAL(valueChanged(int)),
00059             cannonField, SLOT(setForce(int)));
00060     connect(cannonField, SIGNAL(forceChanged(int)),
00061             force, SLOT(setValue(int)));
00062 
00063     connect(cannonField, SIGNAL(hit()),
00064             this, SLOT(hit()));
00065     connect(cannonField, SIGNAL(missed()),
00066             this, SLOT(missed()));
00067 
00068     QPushButton *shoot = new QPushButton(tr("&Shoot"));
00069     shoot->setFont(QFont("Times", 18, QFont::Bold));
00070 
00071     connect(shoot, SIGNAL(clicked()),
00072             this, SLOT(fire()));
00073     connect(cannonField, SIGNAL(canShoot(bool)),
00074             shoot, SLOT(setEnabled(bool)));
00075 
00076     QPushButton *restart = new QPushButton(tr("&New Game"));
00077     restart->setFont(QFont("Times", 18, QFont::Bold));
00078 
00079     connect(restart, SIGNAL(clicked()), this, SLOT(newGame()));
00080 
00081     hits = new QLCDNumber(2);
00082     hits->setSegmentStyle(QLCDNumber::Filled);
00083 
00084     shotsLeft = new QLCDNumber(2);
00085     shotsLeft->setSegmentStyle(QLCDNumber::Filled);
00086 
00087     QLabel *hitsLabel = new QLabel(tr("HITS"));
00088     QLabel *shotsLeftLabel = new QLabel(tr("SHOTS LEFT"));
00089 
00090     QHBoxLayout *topLayout = new QHBoxLayout;
00091     topLayout->addWidget(shoot);
00092     topLayout->addWidget(hits);
00093     topLayout->addWidget(hitsLabel);
00094     topLayout->addWidget(shotsLeft);
00095     topLayout->addWidget(shotsLeftLabel);
00096     topLayout->addStretch(1);
00097     topLayout->addWidget(restart);
00098 
00099     QVBoxLayout *leftLayout = new QVBoxLayout;
00100     leftLayout->addWidget(angle);
00101     leftLayout->addWidget(force);
00102 
00103     QGridLayout *gridLayout = new QGridLayout;
00104     gridLayout->addWidget(quit, 0, 0);
00105     gridLayout->addLayout(topLayout, 0, 1);
00106     gridLayout->addLayout(leftLayout, 1, 0);
00107     gridLayout->addWidget(cannonField, 1, 1, 2, 1);
00108     gridLayout->setColumnStretch(1, 10);
00109     setLayout(gridLayout);
00110 
00111     angle->setValue(60);
00112     force->setValue(25);
00113     angle->setFocus();
00114 
00115     newGame();
00116 }

Here is the call graph for this function:

GameBoard::GameBoard ( QWidget parent = 0  ) 


Member Function Documentation

void GameBoard::fire (  )  [protected, slot]

Definition at line 118 of file gameboard.cpp.

References cannonField, QLCDNumber::display(), CannonField::gameOver(), QLCDNumber::intValue(), CannonField::isShooting(), CannonField::shoot(), and shotsLeft.

Referenced by GameBoard().

00119 {
00120     if (cannonField->gameOver() || cannonField->isShooting())
00121         return;
00122     shotsLeft->display(shotsLeft->intValue() - 1);
00123     cannonField->shoot();
00124 }

void GameBoard::hit (  )  [protected, slot]

Definition at line 126 of file gameboard.cpp.

References cannonField, QLCDNumber::display(), hits, QLCDNumber::intValue(), CannonField::newTarget(), CannonField::setGameOver(), and shotsLeft.

Referenced by GameBoard().

00127 {
00128     hits->display(hits->intValue() + 1);
00129     if (shotsLeft->intValue() == 0)
00130         cannonField->setGameOver();
00131     else
00132         cannonField->newTarget();
00133 }

void GameBoard::missed (  )  [protected, slot]

Definition at line 135 of file gameboard.cpp.

References cannonField, QLCDNumber::intValue(), CannonField::setGameOver(), and shotsLeft.

Referenced by GameBoard().

00136 {
00137     if (shotsLeft->intValue() == 0)
00138         cannonField->setGameOver();
00139 }

void GameBoard::newGame (  )  [protected, slot]

Definition at line 141 of file gameboard.cpp.

References cannonField, QLCDNumber::display(), hits, CannonField::newTarget(), CannonField::restartGame(), and shotsLeft.

Referenced by GameBoard().

00142 {
00143     shotsLeft->display(15);
00144     hits->display(0);
00145     cannonField->restartGame();
00146     cannonField->newTarget();
00147 }

void GameBoard::fire (  )  [protected, slot]

void GameBoard::hit (  )  [protected, slot]

void GameBoard::missed (  )  [protected, slot]

void GameBoard::newGame (  )  [protected, slot]


Member Data Documentation

QLCDNumber* GameBoard::hits [private]

Definition at line 46 of file gameboard.h.

Referenced by GameBoard(), hit(), and newGame().

QLCDNumber* GameBoard::shotsLeft [private]

Definition at line 47 of file gameboard.h.

Referenced by fire(), GameBoard(), hit(), missed(), and newGame().

CannonField* GameBoard::cannonField [private]

Definition at line 48 of file gameboard.h.

Referenced by fire(), GameBoard(), hit(), missed(), and newGame().

QLCDNumber* GameBoard::hits [private]

Definition at line 46 of file gameboard.h.

QLCDNumber* GameBoard::shotsLeft [private]

Definition at line 47 of file gameboard.h.

CannonField* GameBoard::cannonField [private]

Definition at line 48 of file gameboard.h.


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:01:10 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1