summaryrefslogtreecommitdiff
path: root/noncore/games/oyatzee/oyatzee.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/oyatzee/oyatzee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp
index a55aa73..27c0a9f 100644
--- a/noncore/games/oyatzee/oyatzee.cpp
+++ b/noncore/games/oyatzee/oyatzee.cpp
@@ -1,68 +1,74 @@
#include "oyatzee.h"
+/* OPIE */
+#include <opie2/odebug.h>
+using namespace Opie::Core;
+
+/* QT */
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qpainter.h>
#include <qlayout.h>
+/* STD */
#include <stdlib.h>
OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl )
{
QWidget *thing = new QWidget( this );
setCentralWidget( thing );
setCaption( tr( "OYatzee" ) );
setPlayerNumber( 4 );
setRoundsNumber( 1 );
lastPlayerFinished = false;
currentPlayer = 1;
ps.append( new Player( "Carsten" ) );
ps.append( new Player( "Julia" ) );
ps.append( new Player( "Christine" ) );
ps.append( new Player( "Stephan" ) );
QVBoxLayout *vbox = new QVBoxLayout( thing );
sb = new Scoreboard( ps, thing , "sb" );
connect( sb->pb , SIGNAL( item(int) ), this , SLOT( slotEndRound(int) ) );
dw = new DiceWidget( thing , "dw" );
dw->setMaximumHeight( this->height()/4 );
connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) );
vbox->addWidget( sb );
vbox->addWidget( dw );
}
void OYatzee::slotEndRound( int item )
{
- qDebug( "Der User hat Nummer %d ausgewählt" , item );
+ odebug << "Der User hat Nummer " << item << " ausgewählt" << oendl;
/*
* if the user clicked on Total, Bonus or Score and thus not on a
* selectable item return and do nothing
*/
if ( item == 7 || item == 8 || item == 16 ) return;
/*
* check if the user can really click on that item
*/
if ( posibilities.find( item ) == posibilities.end() ) return;
QValueListInt numbers;
Dice *d = dw->diceList.first();
for ( ; d != 0 ; d = dw->diceList.next() )
{
numbers.append( d->hasValue() );
}
int points = 0;
switch ( item )
{
@@ -88,96 +94,96 @@ void OYatzee::slotEndRound( int item )
points = oakPoints;
break;
case FourOfAKind:
points = oakPoints;
break;
case FullHouse:
points = 25;
break;
case SStraight:
points = 30;
break;
case LStraight:
points = 40;
break;
case Yatzee:
points = 50;
break;
case Chance:
points = getPoints ( Chance , numbers );
}
sb->nextRB(currentPlayer-1)->updateMap( item , points );
nextPlayer();
- qDebug( "Punkte: %d" , points );
+ odebug << "Punkte: " << points << "" << oendl;
}
void OYatzee::nextPlayer()
{
currentPlayer++;
if ( currentPlayer > numOfPlayers )
{
currentPlayer = 1;
}
ps.at(currentPlayer-1)->turn = 0;
}
int OYatzee::getPoints( const int num , QValueListInt l)
{
QValueListInt::Iterator it = l.begin();
int c = 0;
if ( num != Chance )
{
for ( ; it != l.end() ; ++it )
{
if ( *it == num )
c++;
}
return c * num;
}
else
{
for ( ; it != l.end() ; ++it )
{
c += *it;
}
return c;
}
}
OYatzee::~OYatzee()
{
}
void OYatzee::detectPosibilities()
{
posibilities.clear();
- qDebug( "running detectPosibilities()" );
+ odebug << "running detectPosibilities()" << oendl;
Dice *d = dw->diceList.first();
QValueListInt numbers;
for ( ; d != 0 ; d = dw->diceList.next() )
{
numbers.append( d->hasValue() );
}
//the 6 numbers
QValueListInt::Iterator it;
for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6
{
bool cont = false;
it = numbers.begin();
for ( ; it != numbers.end() ; ++it )
{
if ( cont )
continue;
if ( numbers.find( i ) != numbers.end() )
{
@@ -240,179 +246,179 @@ void OYatzee::detectPosibilities()
isLong = true;
}
//1234
if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() )
isShort = true;
//3456
if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() )
isShort = true;
if ( isShort )
posibilities.append( 12 );
if ( isLong )
posibilities.append( 13 );
}
posibilities.append( 13 ); //Chance, well, this is allways possible
displayPossibilites();
}
void OYatzee::displayPossibilites()
{
//X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it )
//X {
-//X qDebug( QString::number( *it ) );
+//X odebug << QString::number( *it ) << oendl;
//X switch ( *it )
//X {
//X case Ones:
-//X qDebug( "1er" );
+//X odebug << "1er" << oendl;
//X break;
//X case Twos:
-//X qDebug( "2er" );
+//X odebug << "2er" << oendl;
//X break;
//X case Threes:
-//X qDebug( "3er" );
+//X odebug << "3er" << oendl;
//X break;
//X case Fours:
-//X qDebug( "4er" );
+//X odebug << "4er" << oendl;
//X break;
//X case Fives:
-//X qDebug( "5er" );
+//X odebug << "5er" << oendl;
//X break;
//X case Sixes:
-//X qDebug( "6er" );
+//X odebug << "6er" << oendl;
//X break;
//X case ThreeOfAKind:
-//X qDebug( "3oaK" );
+//X odebug << "3oaK" << oendl;
//X break;
//X case FourOfAKind:
-//X qDebug( "4oaK" );
+//X odebug << "4oaK" << oendl;
//X break;
//X case FullHouse:
-//X qDebug( "Full House" );
+//X odebug << "Full House" << oendl;
//X break;
//X case SStraight:
-//X qDebug( "Short S" );
+//X odebug << "Short S" << oendl;
//X break;
//X case LStraight:
-//X qDebug( "Long S" );
+//X odebug << "Long S" << oendl;
//X break;
//X case Yatzee:
-//X qDebug( "Yatzee!" );
+//X odebug << "Yatzee!" << oendl;
//X break;
//X case Chance:
-//X qDebug( "Chance" );
+//X odebug << "Chance" << oendl;
//X break;
//X }
//X }
sb->pb->setIntlist( posibilities );
sb->pb->update();
}
void OYatzee::startGame()
{
/*
* TODO
*/
}
void OYatzee::stopGame(){}
void OYatzee::setPlayerNumber( const int num )
{
numOfPlayers = num;
}
void OYatzee::setRoundsNumber( const int num )
{
numOfRounds = num;
}
void OYatzee::slotStartGame()
{
}
void OYatzee::slotRollDices()
{
- qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn );
+ odebug << "Roll nummer: " << ps.at( currentPlayer-1 )->turn << "" << oendl;
if ( ps.at( currentPlayer-1 )->turn == 3 )
{
QMessageBox::information( this,
"OYatzee",
tr( "Only three rolls per turn allowed." ) );
return;
}
Dice *d = dw->diceList.first();
for ( ; d != 0 ; d = dw->diceList.next() )
{
if ( !d->isSelected )
d->roll();
}
-// qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn );
+// odebug << "Roll nummer (vorher): " << ps.at( currentPlayer-1 )->turn << "" << oendl;
ps.at(currentPlayer-1)->turn++;
-// qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn );
+// odebug << "Roll nummer (nachher): " << ps.at( currentPlayer-1 )->turn << "" << oendl;
detectPosibilities();
}
/*
* Scoreboard
*/
Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name )
{
ps_ = ps;
pb = new Possibilityboard( this , "pb" );
createResultboards( 4 );
QHBoxLayout *hbox = new QHBoxLayout( this );
hbox->addWidget( pb );
hbox->addSpacing( 25 );
Resultboard *r = rbList.first();
for ( ; r != 0 ; r = rbList.next() )
{
hbox->addWidget( r );
}
}
Resultboard* Scoreboard::nextRB( int currentPlayer )
{
Resultboard *b;
b = rbList.at( currentPlayer );
- qDebug( "Anzahl: %d" , rbList.count() );
+ odebug << "Anzahl: " << rbList.count() << "" << oendl;
return b;
}
void Scoreboard::createResultboards(const int num)
{
Player *p = ps_.first();
for ( int i = 0 ; i < num ; ++i , p = ps_.next() )
{
QString n = p->playerName;
rbList.append( new Resultboard( n , this ) );
}
}
void Scoreboard::paintEvent( QPaintEvent * )
{
//X QPainter p;
//X p.begin( this );
//X
//X p.drawRect( 0,0, this->width() , this->height() );
}
/*
* Dice
@@ -587,49 +593,49 @@ void Board::mousePressEvent( QMouseEvent *e )
emit clicked( e->pos() );
}
/*
* Resultboard
*/
Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name )
{
pName = playerName;
}
void Resultboard::paintEvent( QPaintEvent* )
{
QPainter p;
p.begin( this );
const int cell_width = this->width();
const int cell_height = this->height()/17;
pointMap::Iterator it = pMap.begin();
for ( ; it != pMap.end() ; ++it )
{
int i = it.key();
- qDebug( "ok: %d , %d" , i , it.data() );
+ odebug << "ok: " << i << " , " << it.data() << "" << oendl;
p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) );
}
p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername
}
void Resultboard::updateMap( int item , int points )
{
pMap.insert( item , points );
update();
}
/*
* Possibilityboard
*/
Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name )
{
begriffe.append( "1er" );
begriffe.append( "2er" );
begriffe.append( "3er" );
begriffe.append( "4er" );