author | cniehaus <cniehaus> | 2003-08-12 16:09:37 (UTC) |
---|---|---|
committer | cniehaus <cniehaus> | 2003-08-12 16:09:37 (UTC) |
commit | d16aa943a04b1e630e913cc55789bb876cd0f42f (patch) (unidiff) | |
tree | 1f52c8cf40bbfaab318f7c62f4abbca73b58dfa3 /noncore/games/oyatzee/oyatzee.cpp | |
parent | e7f79ca3acf58aef3ff150a2974f8087189621f5 (diff) | |
download | opie-d16aa943a04b1e630e913cc55789bb876cd0f42f.zip opie-d16aa943a04b1e630e913cc55789bb876cd0f42f.tar.gz opie-d16aa943a04b1e630e913cc55789bb876cd0f42f.tar.bz2 |
A new Game: OYatzee. It is similar to Kniffel or Yatzee and not yet ready.
Diffstat (limited to 'noncore/games/oyatzee/oyatzee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/oyatzee/oyatzee.cpp | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp new file mode 100644 index 0000000..7940b89 --- a/dev/null +++ b/noncore/games/oyatzee/oyatzee.cpp | |||
@@ -0,0 +1,214 @@ | |||
1 | #include "oyatzee.h" | ||
2 | |||
3 | #include <qpe/applnk.h> | ||
4 | #include <qpe/global.h> | ||
5 | #include <qpe/filemanager.h> | ||
6 | #include <qpe/resource.h> | ||
7 | #include <qpe/config.h> | ||
8 | |||
9 | #include <qapplication.h> | ||
10 | #include <qmessagebox.h> | ||
11 | #include <qcombobox.h> | ||
12 | #include <qdatetime.h> | ||
13 | #include <qfileinfo.h> | ||
14 | #include <qfile.h> | ||
15 | #include <qdir.h> | ||
16 | #include <qiconset.h> | ||
17 | #include <qlabel.h> | ||
18 | #include <qlineedit.h> | ||
19 | #include <qpushbutton.h> | ||
20 | #include <qtextstream.h> | ||
21 | #include <qtimer.h> | ||
22 | #include <qpe/qpetoolbar.h> | ||
23 | #include <qtoolbutton.h> | ||
24 | #include <qvbox.h> | ||
25 | #include <qwidgetstack.h> | ||
26 | #include <qpainter.h> | ||
27 | #include <qlayout.h> | ||
28 | #include <qregexp.h> | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | #include <unistd.h> | ||
32 | #include <pwd.h> | ||
33 | #include <sys/types.h> | ||
34 | |||
35 | OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) | ||
36 | { | ||
37 | QWidget *thing = new QWidget( this ); | ||
38 | setCentralWidget( thing ); | ||
39 | |||
40 | QVBoxLayout *vbox = new QVBoxLayout( thing ); | ||
41 | |||
42 | sb = new Scoreboard( thing , "sb" ); | ||
43 | dw = new DiceWidget( thing , "dw" ); | ||
44 | |||
45 | |||
46 | vbox->addWidget( sb ); | ||
47 | vbox->addWidget( dw ); | ||
48 | |||
49 | setPlayerNumber( 2 ); | ||
50 | setRoundsNumber( 1 ); | ||
51 | |||
52 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); | ||
53 | } | ||
54 | |||
55 | OYatzee::~OYatzee() | ||
56 | { | ||
57 | } | ||
58 | |||
59 | void OYatzee::detectPosibilities() | ||
60 | { | ||
61 | Dice *d = dw->diceList.first(); | ||
62 | |||
63 | QValueList<int> numbers; | ||
64 | |||
65 | for ( ; d != 0 ; d = dw->diceList.next() ) | ||
66 | { | ||
67 | numbers.append( d->Value ); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | void OYatzee::setPlayerNumber( const int num ) | ||
72 | { | ||
73 | numOfPlayers = num; | ||
74 | } | ||
75 | |||
76 | void OYatzee::setRoundsNumber( const int num ) | ||
77 | { | ||
78 | numOfRounds = num; | ||
79 | } | ||
80 | |||
81 | void OYatzee::slotStartGame() | ||
82 | { | ||
83 | } | ||
84 | |||
85 | void OYatzee::slotRollDices() | ||
86 | { | ||
87 | Dice *d = dw->diceList.first(); | ||
88 | |||
89 | for ( ; d != 0 ; d = dw->diceList.next() ) | ||
90 | { | ||
91 | d->roll(); | ||
92 | } | ||
93 | |||
94 | detectPosibilities(); | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Scoreboard | ||
99 | */ | ||
100 | Scoreboard::Scoreboard( QWidget *parent, const char *name ) : QWidget( parent , name ) | ||
101 | { | ||
102 | } | ||
103 | |||
104 | void Scoreboard::paintEvent( QPaintEvent * ) | ||
105 | { | ||
106 | QPainter p; | ||
107 | p.begin( this ); | ||
108 | |||
109 | p.drawRect( 0,0, this->width() , this->height() ); | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * Dice | ||
114 | */ | ||
115 | Dice::Dice( QWidget *parent , const char *name ) : QFrame( parent , name ) | ||
116 | { | ||
117 | QTime t = QTime::currentTime(); // set random seed | ||
118 | srand(t.hour()*12+t.minute()*60+t.second()*60); | ||
119 | |||
120 | connect( this , SIGNAL( selected() ), this , SLOT( slotSelected() ) ); | ||
121 | } | ||
122 | |||
123 | void Dice::slotSelected() | ||
124 | { | ||
125 | qDebug( QString::number( Value ) ); | ||
126 | } | ||
127 | |||
128 | int Dice::hasValue() | ||
129 | { | ||
130 | return Value; | ||
131 | } | ||
132 | |||
133 | void Dice::roll() | ||
134 | { | ||
135 | Value = rand()%6; | ||
136 | Value += 1; | ||
137 | |||
138 | update(); | ||
139 | } | ||
140 | |||
141 | void Dice::mousePressEvent( QMouseEvent* /*e*/ ) | ||
142 | { | ||
143 | emit selected(); | ||
144 | } | ||
145 | |||
146 | void Dice::paintEvent( QPaintEvent * ) | ||
147 | { | ||
148 | QPainter p; | ||
149 | p.begin( this ); | ||
150 | |||
151 | p.drawRect( 0,0, this->width() , this->height() ); | ||
152 | |||
153 | paintNumber( &p ); | ||
154 | } | ||
155 | |||
156 | void Dice::paintNumber( QPainter *p ) | ||
157 | { | ||
158 | switch ( Value ) | ||
159 | { | ||
160 | case 1: | ||
161 | p->drawText( 10,10,"1"); | ||
162 | break; | ||
163 | case 2: | ||
164 | p->drawText( 10,10,"2"); | ||
165 | break; | ||
166 | case 3: | ||
167 | p->drawText( 10,10,"3"); | ||
168 | break; | ||
169 | case 4: | ||
170 | p->drawText( 10,10,"4"); | ||
171 | break; | ||
172 | case 5: | ||
173 | p->drawText( 10,10,"5"); | ||
174 | break; | ||
175 | case 6: | ||
176 | p->drawText( 10,10,"6"); | ||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * DiceWidget | ||
183 | */ | ||
184 | DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent , name ) | ||
185 | { | ||
186 | rollButton = new QPushButton( tr( "Roll" ) , this ) ; | ||
187 | |||
188 | for ( int i = 0 ; i < 5 ; i++ ) | ||
189 | { | ||
190 | //appending the 5 dices of the game | ||
191 | diceList.append( new Dice( this, "wuerfel" ) ); | ||
192 | } | ||
193 | |||
194 | QHBoxLayout *hbox = new QHBoxLayout( this ); | ||
195 | |||
196 | Dice *d = diceList.first(); | ||
197 | |||
198 | for ( ; d != 0 ; d = diceList.next() ) | ||
199 | { | ||
200 | d->roll(); | ||
201 | hbox->addWidget( d ); | ||
202 | } | ||
203 | |||
204 | hbox->addWidget( rollButton ); | ||
205 | } | ||
206 | |||
207 | /* | ||
208 | * Player | ||
209 | */ | ||
210 | Player::Player( QString name ) | ||
211 | { | ||
212 | playerName = name; | ||
213 | } | ||
214 | |||