Diffstat (limited to 'noncore/games/oyatzee/oyatzee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/oyatzee/oyatzee.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp index 86318db..a55aa73 100644 --- a/noncore/games/oyatzee/oyatzee.cpp +++ b/noncore/games/oyatzee/oyatzee.cpp | |||
@@ -1,128 +1,128 @@ | |||
1 | #include "oyatzee.h" | 1 | #include "oyatzee.h" |
2 | 2 | ||
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
5 | #include <qpainter.h> | 5 | #include <qpainter.h> |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | 9 | ||
10 | OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) | 10 | OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) |
11 | { | 11 | { |
12 | QWidget *thing = new QWidget( this ); | 12 | QWidget *thing = new QWidget( this ); |
13 | setCentralWidget( thing ); | 13 | setCentralWidget( thing ); |
14 | 14 | ||
15 | setCaption( tr( "OYatzee" ) ); | 15 | setCaption( tr( "OYatzee" ) ); |
16 | 16 | ||
17 | setPlayerNumber( 4 ); | 17 | setPlayerNumber( 4 ); |
18 | setRoundsNumber( 1 ); | 18 | setRoundsNumber( 1 ); |
19 | 19 | ||
20 | lastPlayerFinished = false; | 20 | lastPlayerFinished = false; |
21 | currentPlayer = 1; | 21 | currentPlayer = 1; |
22 | 22 | ||
23 | ps.append( new Player( "Carsten" ) ); | 23 | ps.append( new Player( "Carsten" ) ); |
24 | ps.append( new Player( "Julia" ) ); | 24 | ps.append( new Player( "Julia" ) ); |
25 | ps.append( new Player( "Christine" ) ); | 25 | ps.append( new Player( "Christine" ) ); |
26 | ps.append( new Player( "Stephan" ) ); | 26 | ps.append( new Player( "Stephan" ) ); |
27 | 27 | ||
28 | 28 | ||
29 | QVBoxLayout *vbox = new QVBoxLayout( thing ); | 29 | QVBoxLayout *vbox = new QVBoxLayout( thing ); |
30 | 30 | ||
31 | sb = new Scoreboard( ps, thing , "sb" ); | 31 | sb = new Scoreboard( ps, thing , "sb" ); |
32 | connect( sb->pb , SIGNAL( item( int ) ), this , SLOT( slotEndRound( int ) ) ); | 32 | connect( sb->pb , SIGNAL( item(int) ), this , SLOT( slotEndRound(int) ) ); |
33 | 33 | ||
34 | dw = new DiceWidget( thing , "dw" ); | 34 | dw = new DiceWidget( thing , "dw" ); |
35 | dw->setMaximumHeight( this->height()/4 ); | 35 | dw->setMaximumHeight( this->height()/4 ); |
36 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); | 36 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); |
37 | 37 | ||
38 | vbox->addWidget( sb ); | 38 | vbox->addWidget( sb ); |
39 | vbox->addWidget( dw ); | 39 | vbox->addWidget( dw ); |
40 | } | 40 | } |
41 | 41 | ||
42 | void OYatzee::slotEndRound( int item ) | 42 | void OYatzee::slotEndRound( int item ) |
43 | { | 43 | { |
44 | qDebug( "Der User hat Nummer %d ausgewählt" , item ); | 44 | qDebug( "Der User hat Nummer %d ausgewählt" , item ); |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * if the user clicked on Total, Bonus or Score and thus not on a | 47 | * if the user clicked on Total, Bonus or Score and thus not on a |
48 | * selectable item return and do nothing | 48 | * selectable item return and do nothing |
49 | */ | 49 | */ |
50 | if ( item == 7 || item == 8 || item == 16 ) return; | 50 | if ( item == 7 || item == 8 || item == 16 ) return; |
51 | 51 | ||
52 | /* | 52 | /* |
53 | * check if the user can really click on that item | 53 | * check if the user can really click on that item |
54 | */ | 54 | */ |
55 | if ( posibilities.find( item ) == posibilities.end() ) return; | 55 | if ( posibilities.find( item ) == posibilities.end() ) return; |
56 | 56 | ||
57 | QValueListInt numbers; | 57 | QValueListInt numbers; |
58 | 58 | ||
59 | Dice *d = dw->diceList.first(); | 59 | Dice *d = dw->diceList.first(); |
60 | for ( ; d != 0 ; d = dw->diceList.next() ) | 60 | for ( ; d != 0 ; d = dw->diceList.next() ) |
61 | { | 61 | { |
62 | numbers.append( d->hasValue() ); | 62 | numbers.append( d->hasValue() ); |
63 | } | 63 | } |
64 | 64 | ||
65 | int points = 0; | 65 | int points = 0; |
66 | 66 | ||
67 | switch ( item ) | 67 | switch ( item ) |
68 | { | 68 | { |
69 | case Ones: | 69 | case Ones: |
70 | points = getPoints( 1 , numbers ); | 70 | points = getPoints( 1 , numbers ); |
71 | break; | 71 | break; |
72 | case Twos: | 72 | case Twos: |
73 | points = getPoints( 2 , numbers ); | 73 | points = getPoints( 2 , numbers ); |
74 | break; | 74 | break; |
75 | case Threes: | 75 | case Threes: |
76 | points = getPoints( 3 , numbers ); | 76 | points = getPoints( 3 , numbers ); |
77 | break; | 77 | break; |
78 | case Fours: | 78 | case Fours: |
79 | points = getPoints( 4 , numbers ); | 79 | points = getPoints( 4 , numbers ); |
80 | break; | 80 | break; |
81 | case Fives: | 81 | case Fives: |
82 | points = getPoints( 5 , numbers ); | 82 | points = getPoints( 5 , numbers ); |
83 | break; | 83 | break; |
84 | case Sixes: | 84 | case Sixes: |
85 | points = getPoints( 6 , numbers ); | 85 | points = getPoints( 6 , numbers ); |
86 | break; | 86 | break; |
87 | case ThreeOfAKind: | 87 | case ThreeOfAKind: |
88 | points = oakPoints; | 88 | points = oakPoints; |
89 | break; | 89 | break; |
90 | case FourOfAKind: | 90 | case FourOfAKind: |
91 | points = oakPoints; | 91 | points = oakPoints; |
92 | break; | 92 | break; |
93 | case FullHouse: | 93 | case FullHouse: |
94 | points = 25; | 94 | points = 25; |
95 | break; | 95 | break; |
96 | case SStraight: | 96 | case SStraight: |
97 | points = 30; | 97 | points = 30; |
98 | break; | 98 | break; |
99 | case LStraight: | 99 | case LStraight: |
100 | points = 40; | 100 | points = 40; |
101 | break; | 101 | break; |
102 | case Yatzee: | 102 | case Yatzee: |
103 | points = 50; | 103 | points = 50; |
104 | break; | 104 | break; |
105 | case Chance: | 105 | case Chance: |
106 | points = getPoints ( Chance , numbers ); | 106 | points = getPoints ( Chance , numbers ); |
107 | } | 107 | } |
108 | 108 | ||
109 | sb->nextRB(currentPlayer-1)->updateMap( item , points ); | 109 | sb->nextRB(currentPlayer-1)->updateMap( item , points ); |
110 | nextPlayer(); | 110 | nextPlayer(); |
111 | 111 | ||
112 | qDebug( "Punkte: %d" , points ); | 112 | qDebug( "Punkte: %d" , points ); |
113 | } | 113 | } |
114 | 114 | ||
115 | void OYatzee::nextPlayer() | 115 | void OYatzee::nextPlayer() |
116 | { | 116 | { |
117 | currentPlayer++; | 117 | currentPlayer++; |
118 | 118 | ||
119 | if ( currentPlayer > numOfPlayers ) | 119 | if ( currentPlayer > numOfPlayers ) |
120 | { | 120 | { |
121 | currentPlayer = 1; | 121 | currentPlayer = 1; |
122 | } | 122 | } |
123 | 123 | ||
124 | ps.at(currentPlayer-1)->turn = 0; | 124 | ps.at(currentPlayer-1)->turn = 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | int OYatzee::getPoints( const int num , QValueListInt l) | 127 | int OYatzee::getPoints( const int num , QValueListInt l) |
128 | { | 128 | { |
@@ -553,135 +553,135 @@ void Player::setupResultList() | |||
553 | { | 553 | { |
554 | pResults.append( 0 ); | 554 | pResults.append( 0 ); |
555 | } | 555 | } |
556 | } | 556 | } |
557 | 557 | ||
558 | /* | 558 | /* |
559 | * TODO: muss noch genutzt werden | 559 | * TODO: muss noch genutzt werden |
560 | */ | 560 | */ |
561 | void Player::updateTotalPoints( pointMap m ) | 561 | void Player::updateTotalPoints( pointMap m ) |
562 | { | 562 | { |
563 | pointMap::Iterator it = m.begin(); | 563 | pointMap::Iterator it = m.begin(); |
564 | for ( ; it != m.end() ; ++it ) | 564 | for ( ; it != m.end() ; ++it ) |
565 | { | 565 | { |
566 | totalPoints += it.data(); | 566 | totalPoints += it.data(); |
567 | } | 567 | } |
568 | 568 | ||
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | void Player::setResults( const int cat , const int points ) | 572 | void Player::setResults( const int cat , const int points ) |
573 | { | 573 | { |
574 | QValueListInt::Iterator it = pResults.at( cat ); | 574 | QValueListInt::Iterator it = pResults.at( cat ); |
575 | *it = points; | 575 | *it = points; |
576 | } | 576 | } |
577 | 577 | ||
578 | /* | 578 | /* |
579 | * Board | 579 | * Board |
580 | */ | 580 | */ |
581 | Board::Board( QWidget *parent , const char* name ) : QWidget ( parent , name ) | 581 | Board::Board( QWidget *parent , const char* name ) : QWidget ( parent , name ) |
582 | { | 582 | { |
583 | } | 583 | } |
584 | 584 | ||
585 | void Board::mousePressEvent( QMouseEvent *e ) | 585 | void Board::mousePressEvent( QMouseEvent *e ) |
586 | { | 586 | { |
587 | emit clicked( e->pos() ); | 587 | emit clicked( e->pos() ); |
588 | } | 588 | } |
589 | 589 | ||
590 | /* | 590 | /* |
591 | * Resultboard | 591 | * Resultboard |
592 | */ | 592 | */ |
593 | 593 | ||
594 | Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name ) | 594 | Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name ) |
595 | { | 595 | { |
596 | pName = playerName; | 596 | pName = playerName; |
597 | } | 597 | } |
598 | 598 | ||
599 | void Resultboard::paintEvent( QPaintEvent* ) | 599 | void Resultboard::paintEvent( QPaintEvent* ) |
600 | { | 600 | { |
601 | QPainter p; | 601 | QPainter p; |
602 | p.begin( this ); | 602 | p.begin( this ); |
603 | 603 | ||
604 | const int cell_width = this->width(); | 604 | const int cell_width = this->width(); |
605 | const int cell_height = this->height()/17; | 605 | const int cell_height = this->height()/17; |
606 | 606 | ||
607 | pointMap::Iterator it = pMap.begin(); | 607 | pointMap::Iterator it = pMap.begin(); |
608 | for ( ; it != pMap.end() ; ++it ) | 608 | for ( ; it != pMap.end() ; ++it ) |
609 | { | 609 | { |
610 | int i = it.key(); | 610 | int i = it.key(); |
611 | qDebug( "ok: %d , %d" , i , it.data() ); | 611 | qDebug( "ok: %d , %d" , i , it.data() ); |
612 | p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) ); | 612 | p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) ); |
613 | } | 613 | } |
614 | 614 | ||
615 | p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername | 615 | p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername |
616 | } | 616 | } |
617 | 617 | ||
618 | 618 | ||
619 | void Resultboard::updateMap( int item , int points ) | 619 | void Resultboard::updateMap( int item , int points ) |
620 | { | 620 | { |
621 | pMap.insert( item , points ); | 621 | pMap.insert( item , points ); |
622 | 622 | ||
623 | update(); | 623 | update(); |
624 | } | 624 | } |
625 | 625 | ||
626 | /* | 626 | /* |
627 | * Possibilityboard | 627 | * Possibilityboard |
628 | */ | 628 | */ |
629 | 629 | ||
630 | Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) | 630 | Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) |
631 | { | 631 | { |
632 | begriffe.append( "1er" ); | 632 | begriffe.append( "1er" ); |
633 | begriffe.append( "2er" ); | 633 | begriffe.append( "2er" ); |
634 | begriffe.append( "3er" ); | 634 | begriffe.append( "3er" ); |
635 | begriffe.append( "4er" ); | 635 | begriffe.append( "4er" ); |
636 | begriffe.append( "5er" ); | 636 | begriffe.append( "5er" ); |
637 | begriffe.append( "6er" ); | 637 | begriffe.append( "6er" ); |
638 | begriffe.append( "Total" ); | 638 | begriffe.append( "Total" ); |
639 | begriffe.append( "Bonus" ); | 639 | begriffe.append( "Bonus" ); |
640 | begriffe.append( "3oaK" ); | 640 | begriffe.append( "3oaK" ); |
641 | begriffe.append( "4oaK" ); | 641 | begriffe.append( "4oaK" ); |
642 | begriffe.append( "Full House" ); | 642 | begriffe.append( "Full House" ); |
643 | begriffe.append( "Short S" ); | 643 | begriffe.append( "Short S" ); |
644 | begriffe.append( "Long S" ); | 644 | begriffe.append( "Long S" ); |
645 | begriffe.append( "Yatzee!" ); | 645 | begriffe.append( "Yatzee!" ); |
646 | begriffe.append( "Chance" ); | 646 | begriffe.append( "Chance" ); |
647 | begriffe.append( "Score" ); | 647 | begriffe.append( "Score" ); |
648 | 648 | ||
649 | connect( this , SIGNAL( clicked( QPoint ) ), this , SLOT( slotClicked( QPoint ) ) ); | 649 | connect( this , SIGNAL( clicked(QPoint) ), this , SLOT( slotClicked(QPoint) ) ); |
650 | } | 650 | } |
651 | 651 | ||
652 | void Possibilityboard::slotClicked( QPoint p) | 652 | void Possibilityboard::slotClicked( QPoint p) |
653 | { | 653 | { |
654 | emit item( p.y()/(this->height()/17) ); | 654 | emit item( p.y()/(this->height()/17) ); |
655 | } | 655 | } |
656 | 656 | ||
657 | void Possibilityboard::paintEvent( QPaintEvent* ) | 657 | void Possibilityboard::paintEvent( QPaintEvent* ) |
658 | { | 658 | { |
659 | QPainter p; | 659 | QPainter p; |
660 | p.begin( this ); | 660 | p.begin( this ); |
661 | 661 | ||
662 | const int cell_width = this->width(); | 662 | const int cell_width = this->width(); |
663 | const int cell_height = this->height()/17; | 663 | const int cell_height = this->height()/17; |
664 | 664 | ||
665 | p.setBrush( Qt::blue ); | 665 | p.setBrush( Qt::blue ); |
666 | 666 | ||
667 | QValueListInt::Iterator listIt = list.begin(); | 667 | QValueListInt::Iterator listIt = list.begin(); |
668 | for ( ; listIt != list.end() ; ++listIt ) | 668 | for ( ; listIt != list.end() ; ++listIt ) |
669 | { | 669 | { |
670 | p.drawRect( 0 , (*listIt) * cell_height , cell_width , cell_height ); | 670 | p.drawRect( 0 , (*listIt) * cell_height , cell_width , cell_height ); |
671 | } | 671 | } |
672 | 672 | ||
673 | p.setBrush( Qt::black ); | 673 | p.setBrush( Qt::black ); |
674 | p.setBrush( Qt::NoBrush ); | 674 | p.setBrush( Qt::NoBrush ); |
675 | QStringList::Iterator begriffeIt = begriffe.begin(); | 675 | QStringList::Iterator begriffeIt = begriffe.begin(); |
676 | for ( int i = 1 ; i < 18 ; ++i ) | 676 | for ( int i = 1 ; i < 18 ; ++i ) |
677 | { | 677 | { |
678 | p.drawText( 0 , i*cell_height , cell_width , cell_height , Qt::AlignCenter , *begriffeIt ); | 678 | p.drawText( 0 , i*cell_height , cell_width , cell_height , Qt::AlignCenter , *begriffeIt ); |
679 | ++begriffeIt; | 679 | ++begriffeIt; |
680 | } | 680 | } |
681 | } | 681 | } |
682 | 682 | ||
683 | void Possibilityboard::setIntlist( QValueListInt &l ) | 683 | void Possibilityboard::setIntlist( QValueListInt &l ) |
684 | { | 684 | { |
685 | list = l; | 685 | list = l; |
686 | } | 686 | } |
687 | 687 | ||