summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-08-12 16:09:37 (UTC)
committer cniehaus <cniehaus>2003-08-12 16:09:37 (UTC)
commitd16aa943a04b1e630e913cc55789bb876cd0f42f (patch) (unidiff)
tree1f52c8cf40bbfaab318f7c62f4abbca73b58dfa3
parente7f79ca3acf58aef3ff150a2974f8087189621f5 (diff)
downloadopie-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 (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/oyatzee/config.in4
-rw-r--r--noncore/games/oyatzee/main.cpp13
-rw-r--r--noncore/games/oyatzee/opie-oyatzee.control11
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp214
-rw-r--r--noncore/games/oyatzee/oyatzee.h96
-rw-r--r--noncore/games/oyatzee/oyatzee.pro32
6 files changed, 370 insertions, 0 deletions
diff --git a/noncore/games/oyatzee/config.in b/noncore/games/oyatzee/config.in
new file mode 100644
index 0000000..32b6eac
--- a/dev/null
+++ b/noncore/games/oyatzee/config.in
@@ -0,0 +1,4 @@
1 config WORDGAME
2 boolean "wordgame"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE
diff --git a/noncore/games/oyatzee/main.cpp b/noncore/games/oyatzee/main.cpp
new file mode 100644
index 0000000..6e5002c
--- a/dev/null
+++ b/noncore/games/oyatzee/main.cpp
@@ -0,0 +1,13 @@
1#include "wordgame.h"
2
3#include <qpe/qpeapplication.h>
4
5int main( int argc, char ** argv )
6{
7 QPEApplication a( argc, argv );
8
9 OYatzee mw;
10 a.showMainWidget(&mw);
11
12 return a.exec();
13}
diff --git a/noncore/games/oyatzee/opie-oyatzee.control b/noncore/games/oyatzee/opie-oyatzee.control
new file mode 100644
index 0000000..8249fed
--- a/dev/null
+++ b/noncore/games/oyatzee/opie-oyatzee.control
@@ -0,0 +1,11 @@
1Package: opie-oyatzee
2Files: bin/oyatzee apps/Games/oyatzee.desktop pics/oyatzee
3Priority: optional
4Section: opie/games
5Maintainer: Carsten Niehaus <cniehaus@handhelds.org>
6Architecture: arm
7Depends: task-opie-minimal
8Description: Yatzee-like game
9 A Yatzee game for the Opie environment.
10 Play against the computer or human opponents.
11Version: $QPE_VERSION$EXTRAVERSION
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
35OYatzee::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
55OYatzee::~OYatzee()
56{
57}
58
59void 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
71void OYatzee::setPlayerNumber( const int num )
72{
73 numOfPlayers = num;
74}
75
76void OYatzee::setRoundsNumber( const int num )
77{
78 numOfRounds = num;
79}
80
81void OYatzee::slotStartGame()
82{
83}
84
85void 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 */
100Scoreboard::Scoreboard( QWidget *parent, const char *name ) : QWidget( parent , name )
101{
102}
103
104void 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 */
115Dice::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
123void Dice::slotSelected()
124{
125 qDebug( QString::number( Value ) );
126}
127
128int Dice::hasValue()
129{
130 return Value;
131}
132
133void Dice::roll()
134{
135 Value = rand()%6;
136 Value += 1;
137
138 update();
139}
140
141void Dice::mousePressEvent( QMouseEvent* /*e*/ )
142{
143 emit selected();
144}
145
146void 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
156void 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 */
184DiceWidget::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 */
210Player::Player( QString name )
211{
212 playerName = name;
213}
214
diff --git a/noncore/games/oyatzee/oyatzee.h b/noncore/games/oyatzee/oyatzee.h
new file mode 100644
index 0000000..7be9407
--- a/dev/null
+++ b/noncore/games/oyatzee/oyatzee.h
@@ -0,0 +1,96 @@
1#ifndef WORDGAME_H
2#define WORDGAME_H
3
4#include <qmainwindow.h>
5#include <qlabel.h>
6#include <qlist.h>
7
8#include <stdlib.h> // rand() function
9#include <qdatetime.h> // seed for rand()
10
11class Dice;
12class Game;
13class Scoreboard;
14class DiceWidget;
15
16typedef QList<Dice> dicesList;
17
18class OYatzee : public QMainWindow {
19 Q_OBJECT
20 public:
21 OYatzee( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
22 ~OYatzee();
23
24 Game *g;
25 DiceWidget *dw;
26 Scoreboard *sb;
27
28
29 void setPlayerNumber( const int num );
30 void setRoundsNumber( const int num );
31
32 public slots:
33 void slotStartGame();
34 void slotRollDices();
35
36 private:
37 int numOfPlayers;
38 int numOfRounds;
39
40 void detectPosibilities();
41};
42
43class Dice : public QFrame
44{
45 Q_OBJECT
46 public:
47 Dice( QWidget* parent = 0, const char* name = 0 );
48
49 int Value;
50
51 int hasValue();
52 void roll();
53 virtual void mousePressEvent( QMouseEvent* );
54
55 private slots:
56 void slotSelected();
57
58 signals:
59 void selected();
60
61 protected:
62 void paintEvent( QPaintEvent *e );
63 void paintNumber( QPainter *p );
64};
65
66class DiceWidget : public QWidget
67{
68 Q_OBJECT
69 public:
70 DiceWidget( QWidget *parent = 0, const char* name = 0 );
71
72 QPushButton *rollButton;
73
74 dicesList diceList;
75};
76
77class Scoreboard : public QWidget
78{
79 Q_OBJECT
80 public:
81 Scoreboard( QWidget *parent = 0, const char* name = 0 );
82
83 protected:
84 void paintEvent( QPaintEvent *e );
85};
86
87class Player
88{
89 public:
90 Player( QString name );
91
92 QString playerName;
93 int totalPoints;
94};
95
96#endif // WORDGAME_H
diff --git a/noncore/games/oyatzee/oyatzee.pro b/noncore/games/oyatzee/oyatzee.pro
new file mode 100644
index 0000000..08f842e
--- a/dev/null
+++ b/noncore/games/oyatzee/oyatzee.pro
@@ -0,0 +1,32 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = wordgame.h
5 SOURCES = main.cpp \
6 wordgame.cpp
7 TARGET = oyatzee
8INCLUDEPATH += $(OPIEDIR)/include
9 DEPENDPATH+= $(OPIEDIR)/include
10LIBS += -lqpe
11
12TRANSLATIONS = ../../../i18n/de/oyatzee.ts \
13 ../../../i18n/nl/oyatzee.ts \
14 ../../../i18n/da/oyatzee.ts \
15 ../../../i18n/xx/oyatzee.ts \
16 ../../../i18n/en/oyatzee.ts \
17 ../../../i18n/es/oyatzee.ts \
18 ../../../i18n/fr/oyatzee.ts \
19 ../../../i18n/hu/oyatzee.ts \
20 ../../../i18n/ja/oyatzee.ts \
21 ../../../i18n/ko/oyatzee.ts \
22 ../../../i18n/no/oyatzee.ts \
23 ../../../i18n/pl/oyatzee.ts \
24 ../../../i18n/pt/oyatzee.ts \
25 ../../../i18n/pt_BR/oyatzee.ts \
26 ../../../i18n/sl/oyatzee.ts \
27 ../../../i18n/zh_CN/oyatzee.ts \
28 ../../../i18n/zh_TW/oyatzee.ts
29
30
31
32include ( $(OPIEDIR)/include.pro )