author | drw <drw> | 2005-05-21 20:11:55 (UTC) |
---|---|---|
committer | drw <drw> | 2005-05-21 20:11:55 (UTC) |
commit | afb929e7fd04ecdfec2799a5cf9cf298d1af77c6 (patch) (unidiff) | |
tree | 5db439fca569cf1349220f3fbbf155405d13a80d | |
parent | d56ca82c22c3ac6b7dfb0bb7b4d5a0e5ad1ff4f1 (diff) | |
download | opie-afb929e7fd04ecdfec2799a5cf9cf298d1af77c6.zip opie-afb929e7fd04ecdfec2799a5cf9cf298d1af77c6.tar.gz opie-afb929e7fd04ecdfec2799a5cf9cf298d1af77c6.tar.bz2 |
Resource -> OResource
-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 34 | ||||
-rw-r--r-- | noncore/games/fifteen/fifteen.cpp | 16 | ||||
-rw-r--r-- | noncore/games/mindbreaker/config.in | 2 | ||||
-rw-r--r-- | noncore/games/mindbreaker/mindbreaker.cpp | 15 | ||||
-rw-r--r-- | noncore/games/mindbreaker/opie-mindbreaker.control | 2 | ||||
-rw-r--r-- | noncore/games/minesweep/minesweep.cpp | 5 | ||||
-rw-r--r-- | noncore/games/parashoot/base.cpp | 5 | ||||
-rw-r--r-- | noncore/games/parashoot/bullet.cpp | 5 | ||||
-rw-r--r-- | noncore/games/parashoot/cannon.cpp | 5 | ||||
-rw-r--r-- | noncore/games/parashoot/helicopter.cpp | 4 | ||||
-rw-r--r-- | noncore/games/parashoot/interface.cpp | 10 | ||||
-rw-r--r-- | noncore/games/parashoot/man.cpp | 7 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascard.cpp | 51 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardgame.h | 1 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardwindow.cpp | 7 | ||||
-rw-r--r-- | noncore/games/tetrix/qtetrix.cpp | 4 | ||||
-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 22 | ||||
-rw-r--r-- | noncore/games/zlines/ballpainter.cpp | 4 |
18 files changed, 97 insertions, 102 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index c286a36..31835f8 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp | |||
@@ -1,975 +1,975 @@ | |||
1 | #include "backgammon.h" | 1 | #include "backgammon.h" |
2 | #include "aidialog.h" | 2 | #include "aidialog.h" |
3 | #include "filedialog.h" | 3 | #include "filedialog.h" |
4 | #include "playerdialog.h" | 4 | #include "playerdialog.h" |
5 | #include "rulesdialog.h" | 5 | #include "rulesdialog.h" |
6 | #include "themedialog.h" | 6 | #include "themedialog.h" |
7 | 7 | ||
8 | /* OPIE */ | 8 | /* OPIE */ |
9 | #include <opie2/odebug.h> | 9 | #include <opie2/odebug.h> |
10 | #include <opie2/oresource.h> | ||
10 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
12 | #include <qpe/resource.h> | ||
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | 14 | ||
15 | /* QT */ | 15 | /* QT */ |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qlayout.h> | 17 | #include <qlayout.h> |
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | #include <qtimer.h> | 19 | #include <qtimer.h> |
20 | #include <qmenubar.h> | 20 | #include <qmenubar.h> |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | 24 | ||
25 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) | 25 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) |
26 | : QMainWindow(parent, name, fl) | 26 | : QMainWindow(parent, name, fl) |
27 | { | 27 | { |
28 | if (!name) setName("BackGammon"); | 28 | if (!name) setName("BackGammon"); |
29 | setCaption(tr( "Backgammon") ); | 29 | setCaption(tr( "Backgammon") ); |
30 | setIcon( Resource::loadPixmap( "backgammon" ) ); | 30 | setIcon( Opie::Core::OResource::loadPixmap( "backgammon" ) ); |
31 | //general counter varaible | 31 | //general counter varaible |
32 | int a=0; | 32 | int a=0; |
33 | //the game engine | 33 | //the game engine |
34 | move=new MoveEngine(); | 34 | move=new MoveEngine(); |
35 | 35 | ||
36 | //load the default theme | 36 | //load the default theme |
37 | Config conf("backgammon"); | 37 | Config conf("backgammon"); |
38 | if(!conf.isValid()) | 38 | if(!conf.isValid()) |
39 | { | 39 | { |
40 | odebug << "config file does not exist" << oendl; | 40 | odebug << "config file does not exist" << oendl; |
41 | conf.setGroup("general"); | 41 | conf.setGroup("general"); |
42 | conf.writeEntry("theme","default"); | 42 | conf.writeEntry("theme","default"); |
43 | conf.setGroup("rules"); | 43 | conf.setGroup("rules"); |
44 | conf.writeEntry("move_with_pieces_out",false); | 44 | conf.writeEntry("move_with_pieces_out",false); |
45 | conf.writeEntry("nice_dice",false); | 45 | conf.writeEntry("nice_dice",false); |
46 | conf.setGroup("display"); | 46 | conf.setGroup("display"); |
47 | conf.writeEntry("small",false); | 47 | conf.writeEntry("small",false); |
48 | conf.writeEntry("warning",true); | 48 | conf.writeEntry("warning",true); |
49 | conf.setGroup("ai"); | 49 | conf.setGroup("ai"); |
50 | conf.writeEntry("rescue",6); | 50 | conf.writeEntry("rescue",6); |
51 | conf.writeEntry("eliminate",4); | 51 | conf.writeEntry("eliminate",4); |
52 | conf.writeEntry("expose",1); | 52 | conf.writeEntry("expose",1); |
53 | conf.writeEntry("protect",5); | 53 | conf.writeEntry("protect",5); |
54 | conf.writeEntry("safe",3); | 54 | conf.writeEntry("safe",3); |
55 | conf.writeEntry("empty",2); | 55 | conf.writeEntry("empty",2); |
56 | 56 | ||
57 | } | 57 | } |
58 | conf.setGroup("general"); | 58 | conf.setGroup("general"); |
59 | theme_name=conf.readEntry("theme","default"); | 59 | theme_name=conf.readEntry("theme","default"); |
60 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; | 60 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; |
61 | 61 | ||
62 | //the rules | 62 | //the rules |
63 | conf.setGroup("rules"); | 63 | conf.setGroup("rules"); |
64 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); | 64 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); |
65 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); | 65 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); |
66 | 66 | ||
67 | move->setRules(rules); | 67 | move->setRules(rules); |
68 | 68 | ||
69 | //get the AI settings | 69 | //get the AI settings |
70 | AISettings ai; | 70 | AISettings ai; |
71 | conf.setGroup("ai"); | 71 | conf.setGroup("ai"); |
72 | ai.rescue=conf.readNumEntry("rescue",6); | 72 | ai.rescue=conf.readNumEntry("rescue",6); |
73 | ai.eliminate=conf.readNumEntry("eliminate",4); | 73 | ai.eliminate=conf.readNumEntry("eliminate",4); |
74 | ai.expose=conf.readNumEntry("expose",1); | 74 | ai.expose=conf.readNumEntry("expose",1); |
75 | ai.protect=conf.readNumEntry("protect",5); | 75 | ai.protect=conf.readNumEntry("protect",5); |
76 | ai.safe=conf.readNumEntry("safe",3); | 76 | ai.safe=conf.readNumEntry("safe",3); |
77 | ai.empty=conf.readNumEntry("empty",2); | 77 | ai.empty=conf.readNumEntry("empty",2); |
78 | move->setAISettings(ai); | 78 | move->setAISettings(ai); |
79 | 79 | ||
80 | 80 | ||
81 | //get the theme component names | 81 | //get the theme component names |
82 | Config theme(theme_file,Config::File); | 82 | Config theme(theme_file,Config::File); |
83 | if(!theme.isValid()) | 83 | if(!theme.isValid()) |
84 | { | 84 | { |
85 | odebug << "theme file does not exist" << oendl; | 85 | odebug << "theme file does not exist" << oendl; |
86 | theme.setGroup("theme"); | 86 | theme.setGroup("theme"); |
87 | theme.writeEntry("board","casino_board_1"); | 87 | theme.writeEntry("board","casino_board_1"); |
88 | theme.writeEntry("pieces1","casino_pieces_blue"); | 88 | theme.writeEntry("pieces1","casino_pieces_blue"); |
89 | theme.writeEntry("pieces2","casino_pieces_white"); | 89 | theme.writeEntry("pieces2","casino_pieces_white"); |
90 | theme.writeEntry("dice1","casino_dice"); | 90 | theme.writeEntry("dice1","casino_dice"); |
91 | theme.writeEntry("dice2","casino_dice"); | 91 | theme.writeEntry("dice2","casino_dice"); |
92 | theme.writeEntry("table","casino_table_green"); | 92 | theme.writeEntry("table","casino_table_green"); |
93 | theme.writeEntry("odds","casino_odds"); | 93 | theme.writeEntry("odds","casino_odds"); |
94 | } | 94 | } |
95 | theme.setGroup("theme"); | 95 | theme.setGroup("theme"); |
96 | board_name=theme.readEntry("board","casino_board_1"); | 96 | board_name=theme.readEntry("board","casino_board_1"); |
97 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); | 97 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); |
98 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); | 98 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); |
99 | diceA_name=theme.readEntry("dice1","casino_dice"); | 99 | diceA_name=theme.readEntry("dice1","casino_dice"); |
100 | diceB_name=theme.readEntry("dice2","casino_dice"); | 100 | diceB_name=theme.readEntry("dice2","casino_dice"); |
101 | table_name=theme.readEntry("table","casino_table_green"); | 101 | table_name=theme.readEntry("table","casino_table_green"); |
102 | odds_name=theme.readEntry("odds","casino_odds"); | 102 | odds_name=theme.readEntry("odds","casino_odds"); |
103 | 103 | ||
104 | 104 | ||
105 | //the menu | 105 | //the menu |
106 | QMenuBar* menuBar = new QMenuBar(this); | 106 | QMenuBar* menuBar = new QMenuBar(this); |
107 | 107 | ||
108 | QPopupMenu* gamemenu= new QPopupMenu(this); | 108 | QPopupMenu* gamemenu= new QPopupMenu(this); |
109 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); | 109 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); |
110 | gamemenu->insertSeparator(); | 110 | gamemenu->insertSeparator(); |
111 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); | 111 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); |
112 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); | 112 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); |
113 | gamemenu->insertSeparator(); | 113 | gamemenu->insertSeparator(); |
114 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); | 114 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); |
115 | menuBar->insertItem(tr( "Game" ),gamemenu); | 115 | menuBar->insertItem(tr( "Game" ),gamemenu); |
116 | 116 | ||
117 | QPopupMenu* thememenu= new QPopupMenu(this); | 117 | QPopupMenu* thememenu= new QPopupMenu(this); |
118 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); | 118 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); |
119 | thememenu->insertSeparator(); | 119 | thememenu->insertSeparator(); |
120 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); | 120 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); |
121 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); | 121 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); |
122 | thememenu->insertSeparator(); | 122 | thememenu->insertSeparator(); |
123 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); | 123 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); |
124 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); | 124 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); |
125 | menuBar->insertItem(tr( "Theme" ),thememenu); | 125 | menuBar->insertItem(tr( "Theme" ),thememenu); |
126 | 126 | ||
127 | QPopupMenu* optionmenu=new QPopupMenu(this); | 127 | QPopupMenu* optionmenu=new QPopupMenu(this); |
128 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); | 128 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); |
129 | optionmenu->insertSeparator(); | 129 | optionmenu->insertSeparator(); |
130 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); | 130 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); |
131 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); | 131 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); |
132 | menuBar->insertItem(tr( "Options"),optionmenu); | 132 | menuBar->insertItem(tr( "Options"),optionmenu); |
133 | 133 | ||
134 | QWidget* mainarea=new QWidget(this); | 134 | QWidget* mainarea=new QWidget(this); |
135 | setCentralWidget(mainarea); | 135 | setCentralWidget(mainarea); |
136 | //the main area | 136 | //the main area |
137 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); | 137 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); |
138 | area=new QCanvas(235,235); | 138 | area=new QCanvas(235,235); |
139 | boardview=new BackGammonView(area,mainarea); | 139 | boardview=new BackGammonView(area,mainarea); |
140 | boardview->setMaximumHeight(240); | 140 | boardview->setMaximumHeight(240); |
141 | layout->addWidget(boardview); | 141 | layout->addWidget(boardview); |
142 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); | 142 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); |
143 | //status bar | 143 | //status bar |
144 | message=new QLabel("<b>Backgammon</b>",mainarea); | 144 | message=new QLabel("<b>Backgammon</b>",mainarea); |
145 | message->setAlignment(AlignHCenter); | 145 | message->setAlignment(AlignHCenter); |
146 | layout->addWidget(message); | 146 | layout->addWidget(message); |
147 | 147 | ||
148 | //the marker | 148 | //the marker |
149 | marker_current=new QCanvasRectangle(area); | 149 | marker_current=new QCanvasRectangle(area); |
150 | marker_current->setBrush(QColor(0,0,255)); | 150 | marker_current->setBrush(QColor(0,0,255)); |
151 | marker_current->setSize(15,5); | 151 | marker_current->setSize(15,5); |
152 | marker_current->setZ(1); | 152 | marker_current->setZ(1); |
153 | 153 | ||
154 | for(a=0;a<4;a++) | 154 | for(a=0;a<4;a++) |
155 | { | 155 | { |
156 | marker_next[a]=new QCanvasRectangle(area); | 156 | marker_next[a]=new QCanvasRectangle(area); |
157 | marker_next[a]->setBrush(QColor(0,255,0)); | 157 | marker_next[a]->setBrush(QColor(0,255,0)); |
158 | marker_next[a]->setSize(15,5); | 158 | marker_next[a]->setSize(15,5); |
159 | marker_next[a]->setZ(1); | 159 | marker_next[a]->setZ(1); |
160 | } | 160 | } |
161 | 161 | ||
162 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); | 162 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); |
163 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); | 163 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); |
164 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); | 164 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); |
165 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); | 165 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); |
166 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); | 166 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); |
167 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); | 167 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); |
168 | 168 | ||
169 | //the pieces | 169 | //the pieces |
170 | p1=new CanvasImageItem*[15]; | 170 | p1=new CanvasImageItem*[15]; |
171 | p1_side=new CanvasImageItem*[15]; | 171 | p1_side=new CanvasImageItem*[15]; |
172 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 172 | QImage piece_1_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesA_name)); |
173 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 173 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
174 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 174 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
175 | 175 | ||
176 | p2=new CanvasImageItem*[15]; | 176 | p2=new CanvasImageItem*[15]; |
177 | p2_side=new CanvasImageItem*[15]; | 177 | p2_side=new CanvasImageItem*[15]; |
178 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 178 | QImage piece_2_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesB_name)); |
179 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 179 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
180 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 180 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
181 | 181 | ||
182 | 182 | ||
183 | for(a=0;a<15;a++) | 183 | for(a=0;a<15;a++) |
184 | { | 184 | { |
185 | p1[a]=new CanvasImageItem(piece_1_front,area); | 185 | p1[a]=new CanvasImageItem(piece_1_front,area); |
186 | p1[a]->setSize(15,15); | 186 | p1[a]->setSize(15,15); |
187 | p1_side[a]=new CanvasImageItem(piece_1_side,area); | 187 | p1_side[a]=new CanvasImageItem(piece_1_side,area); |
188 | p1_side[a]->setSize(15,5); | 188 | p1_side[a]->setSize(15,5); |
189 | 189 | ||
190 | p2[a]=new CanvasImageItem(piece_2_front,area); | 190 | p2[a]=new CanvasImageItem(piece_2_front,area); |
191 | p2[a]->setSize(15,15); | 191 | p2[a]->setSize(15,15); |
192 | p2_side[a]=new CanvasImageItem(piece_2_side,area); | 192 | p2_side[a]=new CanvasImageItem(piece_2_side,area); |
193 | p2_side[a]->setSize(15,5); | 193 | p2_side[a]->setSize(15,5); |
194 | } | 194 | } |
195 | draw(); | 195 | draw(); |
196 | 196 | ||
197 | //the dice | 197 | //the dice |
198 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 198 | QImage dicebgA_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceA_name)); |
199 | diceA1=new CanvasImageItem*[7]; | 199 | diceA1=new CanvasImageItem*[7]; |
200 | diceA2=new CanvasImageItem*[7]; | 200 | diceA2=new CanvasImageItem*[7]; |
201 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 201 | QImage dicebgB_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceB_name)); |
202 | diceB1=new CanvasImageItem*[7]; | 202 | diceB1=new CanvasImageItem*[7]; |
203 | diceB2=new CanvasImageItem*[7]; | 203 | diceB2=new CanvasImageItem*[7]; |
204 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 204 | QImage oddsbg_all=(Opie::Core::OResource::loadImage("backgammon/odds/"+odds_name)); |
205 | //oddsDice=new CanvasImageItem*[6]; | 205 | //oddsDice=new CanvasImageItem*[6]; |
206 | 206 | ||
207 | 207 | ||
208 | for(a=0;a<7;a++) | 208 | for(a=0;a<7;a++) |
209 | { | 209 | { |
210 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 210 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
211 | diceA1[a]=new CanvasImageItem(dicebgA,area); | 211 | diceA1[a]=new CanvasImageItem(dicebgA,area); |
212 | diceA1[a]->setX(5); | 212 | diceA1[a]->setX(5); |
213 | diceA1[a]->setY(205-2); | 213 | diceA1[a]->setY(205-2); |
214 | diceA1[a]->setZ(1); | 214 | diceA1[a]->setZ(1); |
215 | diceA1[a]->setSize(25,25); | 215 | diceA1[a]->setSize(25,25); |
216 | diceA2[a]=new CanvasImageItem(dicebgA,area); | 216 | diceA2[a]=new CanvasImageItem(dicebgA,area); |
217 | diceA2[a]->setX(35); | 217 | diceA2[a]->setX(35); |
218 | diceA2[a]->setY(205-2); | 218 | diceA2[a]->setY(205-2); |
219 | diceA2[a]->setZ(1); | 219 | diceA2[a]->setZ(1); |
220 | diceA2[a]->setSize(25,25); | 220 | diceA2[a]->setSize(25,25); |
221 | 221 | ||
222 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 222 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
223 | diceB1[a]=new CanvasImageItem(dicebgB,area); | 223 | diceB1[a]=new CanvasImageItem(dicebgB,area); |
224 | diceB1[a]->setX(175); | 224 | diceB1[a]->setX(175); |
225 | diceB1[a]->setY(205-2); | 225 | diceB1[a]->setY(205-2); |
226 | diceB1[a]->setZ(1); | 226 | diceB1[a]->setZ(1); |
227 | diceB1[a]->setSize(25,25); | 227 | diceB1[a]->setSize(25,25); |
228 | diceB2[a]=new CanvasImageItem(dicebgB,area); | 228 | diceB2[a]=new CanvasImageItem(dicebgB,area); |
229 | diceB2[a]->setX(205); | 229 | diceB2[a]->setX(205); |
230 | diceB2[a]->setY(205-2); | 230 | diceB2[a]->setY(205-2); |
231 | diceB2[a]->setZ(1); | 231 | diceB2[a]->setZ(1); |
232 | diceB2[a]->setSize(25,25); | 232 | diceB2[a]->setSize(25,25); |
233 | 233 | ||
234 | /* | 234 | /* |
235 | if(a<6) | 235 | if(a<6) |
236 | { | 236 | { |
237 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 237 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
238 | oddsDice[a]=new CanvasImageItem(oddsbg,area); | 238 | oddsDice[a]=new CanvasImageItem(oddsbg,area); |
239 | oddsDice[a]->setX(110); | 239 | oddsDice[a]->setX(110); |
240 | oddsDice[a]->setY(210-2); | 240 | oddsDice[a]->setY(210-2); |
241 | oddsDice[a]->setZ(1); | 241 | oddsDice[a]->setZ(1); |
242 | oddsDice[a]->setSize(15,15); | 242 | oddsDice[a]->setSize(15,15); |
243 | oddsDice[a]->hide(); | 243 | oddsDice[a]->hide(); |
244 | } | 244 | } |
245 | */ | 245 | */ |
246 | } | 246 | } |
247 | //oddsDice[0]->show(); | 247 | //oddsDice[0]->show(); |
248 | 248 | ||
249 | //set the board | 249 | //set the board |
250 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 250 | QImage boardbg(Opie::Core::OResource::loadImage("backgammon/boards/"+board_name)); |
251 | board=new CanvasImageItem(boardbg,area); | 251 | board=new CanvasImageItem(boardbg,area); |
252 | board->setX(0); | 252 | board->setX(0); |
253 | board->setY(0); | 253 | board->setY(0); |
254 | board->setZ(0); | 254 | board->setZ(0); |
255 | board->setSize(235-2,200-2); | 255 | board->setSize(235-2,200-2); |
256 | board->show(); | 256 | board->show(); |
257 | 257 | ||
258 | //the table | 258 | //the table |
259 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 259 | QImage tablebg(Opie::Core::OResource::loadImage("backgammon/table/"+table_name)); |
260 | table=new CanvasImageItem(tablebg,area); | 260 | table=new CanvasImageItem(tablebg,area); |
261 | table->setX(0); | 261 | table->setX(0); |
262 | table->setY(200-2); | 262 | table->setY(200-2); |
263 | table->setZ(0); | 263 | table->setZ(0); |
264 | table->setSize(235-2,20); | 264 | table->setSize(235-2,20); |
265 | table->show(); | 265 | table->show(); |
266 | 266 | ||
267 | //the no move marker | 267 | //the no move marker |
268 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); | 268 | QImage nomovebg(Opie::Core::OResource::loadImage("backgammon/no_move")); |
269 | nomove_marker=new CanvasImageItem(nomovebg,area); | 269 | nomove_marker=new CanvasImageItem(nomovebg,area); |
270 | nomove_marker->setX(0); | 270 | nomove_marker->setX(0); |
271 | nomove_marker->setY(200); | 271 | nomove_marker->setY(200); |
272 | nomove_marker->setZ(2); | 272 | nomove_marker->setZ(2); |
273 | nomove_marker->hide(); | 273 | nomove_marker->hide(); |
274 | 274 | ||
275 | //default human against computer | 275 | //default human against computer |
276 | player1_auto=false; | 276 | player1_auto=false; |
277 | player2_auto=true; | 277 | player2_auto=true; |
278 | //start new game | 278 | //start new game |
279 | newgame(); | 279 | newgame(); |
280 | } | 280 | } |
281 | 281 | ||
282 | BackGammon::~BackGammon() | 282 | BackGammon::~BackGammon() |
283 | { | 283 | { |
284 | //DESTRUCTOR | 284 | //DESTRUCTOR |
285 | } | 285 | } |
286 | 286 | ||
287 | void BackGammon::newgame() | 287 | void BackGammon::newgame() |
288 | { | 288 | { |
289 | gameFinished=false; | 289 | gameFinished=false; |
290 | QDateTime now=QDateTime::currentDateTime(); | 290 | QDateTime now=QDateTime::currentDateTime(); |
291 | game_name=now.date().toString()+"_"+now.time().toString(); | 291 | game_name=now.date().toString()+"_"+now.time().toString(); |
292 | move->reset(); | 292 | move->reset(); |
293 | draw(); | 293 | draw(); |
294 | diceA1_value=7; | 294 | diceA1_value=7; |
295 | diceA2_value=7; | 295 | diceA2_value=7; |
296 | diceA3_value=7; | 296 | diceA3_value=7; |
297 | diceA4_value=7; | 297 | diceA4_value=7; |
298 | diceB1_value=7; | 298 | diceB1_value=7; |
299 | diceB2_value=7; | 299 | diceB2_value=7; |
300 | diceB3_value=7; | 300 | diceB3_value=7; |
301 | diceB4_value=7; | 301 | diceB4_value=7; |
302 | showdice(); | 302 | showdice(); |
303 | player=2; | 303 | player=2; |
304 | dice1_played=true; | 304 | dice1_played=true; |
305 | dice2_played=true; | 305 | dice2_played=true; |
306 | dice3_played=true; | 306 | dice3_played=true; |
307 | dice4_played=true; | 307 | dice4_played=true; |
308 | dice_rolled=false; | 308 | dice_rolled=false; |
309 | setplayer(); | 309 | setplayer(); |
310 | area->update(); | 310 | area->update(); |
311 | } | 311 | } |
312 | 312 | ||
313 | void BackGammon::playerselect() | 313 | void BackGammon::playerselect() |
314 | { | 314 | { |
315 | PlayerDialog* playerdialog=new PlayerDialog(this); | 315 | PlayerDialog* playerdialog=new PlayerDialog(this); |
316 | playerdialog->setAuto1(player1_auto); | 316 | playerdialog->setAuto1(player1_auto); |
317 | playerdialog->setAuto2(player2_auto); | 317 | playerdialog->setAuto2(player2_auto); |
318 | if(!playerdialog->exec()) | 318 | if(!playerdialog->exec()) |
319 | return; | 319 | return; |
320 | player1_auto=playerdialog->getAuto1(); | 320 | player1_auto=playerdialog->getAuto1(); |
321 | player2_auto=playerdialog->getAuto2(); | 321 | player2_auto=playerdialog->getAuto2(); |
322 | } | 322 | } |
323 | 323 | ||
324 | void BackGammon::loadgame() | 324 | void BackGammon::loadgame() |
325 | { | 325 | { |
326 | FileDialog* file=new FileDialog(this,"Load Game",".game"); | 326 | FileDialog* file=new FileDialog(this,"Load Game",".game"); |
327 | if(!file->exec()) | 327 | if(!file->exec()) |
328 | return; | 328 | return; |
329 | 329 | ||
330 | game_name=file->filename(); | 330 | game_name=file->filename(); |
331 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; | 331 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; |
332 | 332 | ||
333 | Config game(game_file,Config::File); | 333 | Config game(game_file,Config::File); |
334 | game.setGroup("dice"); | 334 | game.setGroup("dice"); |
335 | diceA1_value=game.readNumEntry("diceA1_value"); | 335 | diceA1_value=game.readNumEntry("diceA1_value"); |
336 | diceA2_value=game.readNumEntry("diceA2_value"); | 336 | diceA2_value=game.readNumEntry("diceA2_value"); |
337 | diceA3_value=game.readNumEntry("diceA3_value"); | 337 | diceA3_value=game.readNumEntry("diceA3_value"); |
338 | diceA4_value=game.readNumEntry("diceA4_value"); | 338 | diceA4_value=game.readNumEntry("diceA4_value"); |
339 | diceB1_value=game.readNumEntry("diceB1_value"); | 339 | diceB1_value=game.readNumEntry("diceB1_value"); |
340 | diceB2_value=game.readNumEntry("diceB2_value"); | 340 | diceB2_value=game.readNumEntry("diceB2_value"); |
341 | diceB3_value=game.readNumEntry("diceB3_value"); | 341 | diceB3_value=game.readNumEntry("diceB3_value"); |
342 | diceB4_value=game.readNumEntry("diceB4_value"); | 342 | diceB4_value=game.readNumEntry("diceB4_value"); |
343 | player=game.readNumEntry("player"); | 343 | player=game.readNumEntry("player"); |
344 | dice1_played=game.readBoolEntry("dice1_played"); | 344 | dice1_played=game.readBoolEntry("dice1_played"); |
345 | dice2_played=game.readBoolEntry("dice2_played"); | 345 | dice2_played=game.readBoolEntry("dice2_played"); |
346 | dice3_played=game.readBoolEntry("dice3_played"); | 346 | dice3_played=game.readBoolEntry("dice3_played"); |
347 | dice4_played=game.readBoolEntry("dice4_played"); | 347 | dice4_played=game.readBoolEntry("dice4_played"); |
348 | dice_rolled=game.readBoolEntry("dice_rolled"); | 348 | dice_rolled=game.readBoolEntry("dice_rolled"); |
349 | player1_auto=game.readBoolEntry("player1_auto"); | 349 | player1_auto=game.readBoolEntry("player1_auto"); |
350 | player2_auto=game.readBoolEntry("player2_auto"); | 350 | player2_auto=game.readBoolEntry("player2_auto"); |
351 | 351 | ||
352 | game.setGroup("pieces"); | 352 | game.setGroup("pieces"); |
353 | QString label; | 353 | QString label; |
354 | LoadSave load; | 354 | LoadSave load; |
355 | for(int a=0;a<28;a++) | 355 | for(int a=0;a<28;a++) |
356 | { | 356 | { |
357 | label.setNum(a); | 357 | label.setNum(a); |
358 | load.pop[a].total = game.readNumEntry(label,0); | 358 | load.pop[a].total = game.readNumEntry(label,0); |
359 | } | 359 | } |
360 | 360 | ||
361 | move->loadGame(load); | 361 | move->loadGame(load); |
362 | setplayer(); | 362 | setplayer(); |
363 | showdice(); | 363 | showdice(); |
364 | draw(); | 364 | draw(); |
365 | area->update(); | 365 | area->update(); |
366 | } | 366 | } |
367 | 367 | ||
368 | void BackGammon::savegame() | 368 | void BackGammon::savegame() |
369 | { | 369 | { |
370 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; | 370 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; |
371 | 371 | ||
372 | Config game(game_file,Config::File); | 372 | Config game(game_file,Config::File); |
373 | game.setGroup("dice"); | 373 | game.setGroup("dice"); |
374 | game.writeEntry("diceA1_value",diceA1_value); | 374 | game.writeEntry("diceA1_value",diceA1_value); |
375 | game.writeEntry("diceA2_value",diceA2_value); | 375 | game.writeEntry("diceA2_value",diceA2_value); |
376 | game.writeEntry("diceA3_value",diceA3_value); | 376 | game.writeEntry("diceA3_value",diceA3_value); |
377 | game.writeEntry("diceA4_value",diceA4_value); | 377 | game.writeEntry("diceA4_value",diceA4_value); |
378 | game.writeEntry("diceB1_value",diceB1_value); | 378 | game.writeEntry("diceB1_value",diceB1_value); |
379 | game.writeEntry("diceB2_value",diceB3_value); | 379 | game.writeEntry("diceB2_value",diceB3_value); |
380 | game.writeEntry("diceB3_value",diceB4_value); | 380 | game.writeEntry("diceB3_value",diceB4_value); |
381 | game.writeEntry("diceB4_value",diceB4_value); | 381 | game.writeEntry("diceB4_value",diceB4_value); |
382 | game.writeEntry("player",player); | 382 | game.writeEntry("player",player); |
383 | game.writeEntry("dice1_played",dice1_played); | 383 | game.writeEntry("dice1_played",dice1_played); |
384 | game.writeEntry("dice2_played",dice2_played); | 384 | game.writeEntry("dice2_played",dice2_played); |
385 | game.writeEntry("dice3_played",dice3_played); | 385 | game.writeEntry("dice3_played",dice3_played); |
386 | game.writeEntry("dice4_played",dice4_played); | 386 | game.writeEntry("dice4_played",dice4_played); |
387 | game.writeEntry("dice_rolled",dice_rolled); | 387 | game.writeEntry("dice_rolled",dice_rolled); |
388 | game.writeEntry("player1_auto",player1_auto); | 388 | game.writeEntry("player1_auto",player1_auto); |
389 | game.writeEntry("player2_auto",player2_auto); | 389 | game.writeEntry("player2_auto",player2_auto); |
390 | 390 | ||
391 | game.setGroup("pieces"); | 391 | game.setGroup("pieces"); |
392 | QString label; | 392 | QString label; |
393 | LoadSave save=move->saveGame(); | 393 | LoadSave save=move->saveGame(); |
394 | for(int a=0;a<28;a++) | 394 | for(int a=0;a<28;a++) |
395 | { | 395 | { |
396 | label.setNum(a); | 396 | label.setNum(a); |
397 | game.writeEntry(label,save.pop[a].total); | 397 | game.writeEntry(label,save.pop[a].total); |
398 | } | 398 | } |
399 | QMessageBox::information(this,"Backgammon","Game saved","OK"); | 399 | QMessageBox::information(this,"Backgammon","Game saved","OK"); |
400 | } | 400 | } |
401 | 401 | ||
402 | void BackGammon::deletegame() | 402 | void BackGammon::deletegame() |
403 | { | 403 | { |
404 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); | 404 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); |
405 | if(!file->exec()) | 405 | if(!file->exec()) |
406 | return; | 406 | return; |
407 | 407 | ||
408 | game_name=file->filename(); | 408 | game_name=file->filename(); |
409 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; | 409 | QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game"; |
410 | 410 | ||
411 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) | 411 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) |
412 | { | 412 | { |
413 | QFile(game_file).remove(); | 413 | QFile(game_file).remove(); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | void BackGammon::newtheme() | 418 | void BackGammon::newtheme() |
419 | { | 419 | { |
420 | ThemeDialog* theme=new ThemeDialog(this); | 420 | ThemeDialog* theme=new ThemeDialog(this); |
421 | 421 | ||
422 | ImageNames names; | 422 | ImageNames names; |
423 | names.theme=theme_name; | 423 | names.theme=theme_name; |
424 | names.board=board_name; | 424 | names.board=board_name; |
425 | names.pieces1=piecesA_name; | 425 | names.pieces1=piecesA_name; |
426 | names.pieces2=piecesB_name; | 426 | names.pieces2=piecesB_name; |
427 | names.dice1=diceA_name; | 427 | names.dice1=diceA_name; |
428 | names.dice2=diceB_name; | 428 | names.dice2=diceB_name; |
429 | names.odds=odds_name; | 429 | names.odds=odds_name; |
430 | names.table=table_name; | 430 | names.table=table_name; |
431 | 431 | ||
432 | theme->setCurrent(names); | 432 | theme->setCurrent(names); |
433 | if(!theme->exec()) | 433 | if(!theme->exec()) |
434 | return; | 434 | return; |
435 | 435 | ||
436 | names=theme->getNames(); | 436 | names=theme->getNames(); |
437 | theme_name=names.theme; | 437 | theme_name=names.theme; |
438 | board_name=names.board; | 438 | board_name=names.board; |
439 | piecesA_name=names.pieces1; | 439 | piecesA_name=names.pieces1; |
440 | piecesB_name=names.pieces2; | 440 | piecesB_name=names.pieces2; |
441 | diceA_name=names.dice1; | 441 | diceA_name=names.dice1; |
442 | diceB_name=names.dice2; | 442 | diceB_name=names.dice2; |
443 | odds_name=names.odds; | 443 | odds_name=names.odds; |
444 | table_name=names.table; | 444 | table_name=names.table; |
445 | 445 | ||
446 | applytheme(); | 446 | applytheme(); |
447 | } | 447 | } |
448 | 448 | ||
449 | void BackGammon::loadtheme() | 449 | void BackGammon::loadtheme() |
450 | { | 450 | { |
451 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); | 451 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); |
452 | if(!file->exec()) | 452 | if(!file->exec()) |
453 | return; | 453 | return; |
454 | 454 | ||
455 | theme_name=file->filename(); | 455 | theme_name=file->filename(); |
456 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; | 456 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; |
457 | 457 | ||
458 | Config theme(theme_file,Config::File); | 458 | Config theme(theme_file,Config::File); |
459 | theme.setGroup("theme"); | 459 | theme.setGroup("theme"); |
460 | board_name=theme.readEntry("board","board_1"); | 460 | board_name=theme.readEntry("board","board_1"); |
461 | piecesA_name=theme.readEntry("pieces1","pieces_1"); | 461 | piecesA_name=theme.readEntry("pieces1","pieces_1"); |
462 | piecesB_name=theme.readEntry("pieces2","pieces_2"); | 462 | piecesB_name=theme.readEntry("pieces2","pieces_2"); |
463 | diceA_name=theme.readEntry("dice1","dice_1"); | 463 | diceA_name=theme.readEntry("dice1","dice_1"); |
464 | diceB_name=theme.readEntry("dice2","dice_2"); | 464 | diceB_name=theme.readEntry("dice2","dice_2"); |
465 | table_name=theme.readEntry("table","table_1"); | 465 | table_name=theme.readEntry("table","table_1"); |
466 | odds_name=theme.readEntry("odds","odds_1"); | 466 | odds_name=theme.readEntry("odds","odds_1"); |
467 | 467 | ||
468 | applytheme(); | 468 | applytheme(); |
469 | 469 | ||
470 | } | 470 | } |
471 | 471 | ||
472 | void BackGammon::savetheme() | 472 | void BackGammon::savetheme() |
473 | { | 473 | { |
474 | if(theme_name=="default") | 474 | if(theme_name=="default") |
475 | { | 475 | { |
476 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); | 476 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); |
477 | return; | 477 | return; |
478 | } | 478 | } |
479 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; | 479 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; |
480 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) | 480 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) |
481 | return; | 481 | return; |
482 | 482 | ||
483 | Config theme(theme_file,Config::File); | 483 | Config theme(theme_file,Config::File); |
484 | theme.setGroup("theme"); | 484 | theme.setGroup("theme"); |
485 | theme.writeEntry("board",board_name); | 485 | theme.writeEntry("board",board_name); |
486 | theme.writeEntry("pieces1",piecesA_name); | 486 | theme.writeEntry("pieces1",piecesA_name); |
487 | theme.writeEntry("pieces2",piecesB_name); | 487 | theme.writeEntry("pieces2",piecesB_name); |
488 | theme.writeEntry("dice1",diceA_name); | 488 | theme.writeEntry("dice1",diceA_name); |
489 | theme.writeEntry("dice2",diceB_name); | 489 | theme.writeEntry("dice2",diceB_name); |
490 | theme.writeEntry("table",table_name); | 490 | theme.writeEntry("table",table_name); |
491 | theme.writeEntry("odds",odds_name); | 491 | theme.writeEntry("odds",odds_name); |
492 | 492 | ||
493 | } | 493 | } |
494 | 494 | ||
495 | void BackGammon::themedefault() | 495 | void BackGammon::themedefault() |
496 | { | 496 | { |
497 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) | 497 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) |
498 | return; | 498 | return; |
499 | 499 | ||
500 | Config conf("backgammon"); | 500 | Config conf("backgammon"); |
501 | conf.setGroup("general"); | 501 | conf.setGroup("general"); |
502 | conf.writeEntry("theme",theme_name); | 502 | conf.writeEntry("theme",theme_name); |
503 | } | 503 | } |
504 | 504 | ||
505 | void BackGammon::deletetheme() | 505 | void BackGammon::deletetheme() |
506 | { | 506 | { |
507 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); | 507 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); |
508 | if(!file->exec()) | 508 | if(!file->exec()) |
509 | return; | 509 | return; |
510 | 510 | ||
511 | theme_name=file->filename(); | 511 | theme_name=file->filename(); |
512 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; | 512 | QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme"; |
513 | 513 | ||
514 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) | 514 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) |
515 | { | 515 | { |
516 | QFile(theme_file).remove(); | 516 | QFile(theme_file).remove(); |
517 | } | 517 | } |
518 | } | 518 | } |
519 | 519 | ||
520 | void BackGammon::modify_AI() | 520 | void BackGammon::modify_AI() |
521 | { | 521 | { |
522 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); | 522 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); |
523 | ai_mod->setAISettings(move->getAISettings()); | 523 | ai_mod->setAISettings(move->getAISettings()); |
524 | if(!ai_mod->exec()) | 524 | if(!ai_mod->exec()) |
525 | return; | 525 | return; |
526 | 526 | ||
527 | //get the AI settings | 527 | //get the AI settings |
528 | AISettings ai=ai_mod->getAISettings(); | 528 | AISettings ai=ai_mod->getAISettings(); |
529 | move->setAISettings(ai); | 529 | move->setAISettings(ai); |
530 | //write new settings to conf file | 530 | //write new settings to conf file |
531 | Config conf("backgammon"); | 531 | Config conf("backgammon"); |
532 | conf.setGroup("ai"); | 532 | conf.setGroup("ai"); |
533 | conf.writeEntry("rescue",ai.rescue); | 533 | conf.writeEntry("rescue",ai.rescue); |
534 | conf.writeEntry("eliminate",ai.eliminate); | 534 | conf.writeEntry("eliminate",ai.eliminate); |
535 | conf.writeEntry("expose",ai.expose); | 535 | conf.writeEntry("expose",ai.expose); |
536 | conf.writeEntry("protect",ai.protect); | 536 | conf.writeEntry("protect",ai.protect); |
537 | conf.writeEntry("safe",ai.safe); | 537 | conf.writeEntry("safe",ai.safe); |
538 | conf.writeEntry("empty",ai.empty); | 538 | conf.writeEntry("empty",ai.empty); |
539 | } | 539 | } |
540 | 540 | ||
541 | void BackGammon::setrules() | 541 | void BackGammon::setrules() |
542 | { | 542 | { |
543 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); | 543 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); |
544 | rulesdialog->setRules(rules); | 544 | rulesdialog->setRules(rules); |
545 | if(!rulesdialog->exec()) | 545 | if(!rulesdialog->exec()) |
546 | return; | 546 | return; |
547 | rules=rulesdialog->getRules(); | 547 | rules=rulesdialog->getRules(); |
548 | Config conf("backgammon"); | 548 | Config conf("backgammon"); |
549 | conf.setGroup("rules"); | 549 | conf.setGroup("rules"); |
550 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); | 550 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); |
551 | conf.writeEntry("nice_dice",rules.generous_dice); | 551 | conf.writeEntry("nice_dice",rules.generous_dice); |
552 | move->setRules(rules); | 552 | move->setRules(rules); |
553 | } | 553 | } |
554 | 554 | ||
555 | 555 | ||
556 | void BackGammon::draw() | 556 | void BackGammon::draw() |
557 | { | 557 | { |
558 | Pieces pieces; | 558 | Pieces pieces; |
559 | move->position(pieces); | 559 | move->position(pieces); |
560 | for(int a=0;a<15;a++) | 560 | for(int a=0;a<15;a++) |
561 | { | 561 | { |
562 | if(!pieces.player1[a].side) | 562 | if(!pieces.player1[a].side) |
563 | { | 563 | { |
564 | p1[a]->setX(pieces.player1[a].x); | 564 | p1[a]->setX(pieces.player1[a].x); |
565 | p1[a]->setY(pieces.player1[a].y); | 565 | p1[a]->setY(pieces.player1[a].y); |
566 | p1[a]->setZ(pieces.player1[a].z); | 566 | p1[a]->setZ(pieces.player1[a].z); |
567 | p1[a]->show(); | 567 | p1[a]->show(); |
568 | p1_side[a]->hide(); | 568 | p1_side[a]->hide(); |
569 | } | 569 | } |
570 | else | 570 | else |
571 | { | 571 | { |
572 | p1_side[a]->setX(pieces.player1[a].x); | 572 | p1_side[a]->setX(pieces.player1[a].x); |
573 | p1_side[a]->setY(pieces.player1[a].y); | 573 | p1_side[a]->setY(pieces.player1[a].y); |
574 | p1_side[a]->setZ(pieces.player1[a].z); | 574 | p1_side[a]->setZ(pieces.player1[a].z); |
575 | p1_side[a]->show(); | 575 | p1_side[a]->show(); |
576 | p1[a]->hide(); | 576 | p1[a]->hide(); |
577 | } | 577 | } |
578 | 578 | ||
579 | if(!pieces.player2[a].side) | 579 | if(!pieces.player2[a].side) |
580 | { | 580 | { |
581 | p2[a]->setX(pieces.player2[a].x); | 581 | p2[a]->setX(pieces.player2[a].x); |
582 | p2[a]->setY(pieces.player2[a].y); | 582 | p2[a]->setY(pieces.player2[a].y); |
583 | p2[a]->setZ(pieces.player2[a].z); | 583 | p2[a]->setZ(pieces.player2[a].z); |
584 | p2[a]->show(); | 584 | p2[a]->show(); |
585 | p2_side[a]->hide(); | 585 | p2_side[a]->hide(); |
586 | } | 586 | } |
587 | else | 587 | else |
588 | { | 588 | { |
589 | p2_side[a]->setX(pieces.player2[a].x); | 589 | p2_side[a]->setX(pieces.player2[a].x); |
590 | p2_side[a]->setY(pieces.player2[a].y); | 590 | p2_side[a]->setY(pieces.player2[a].y); |
591 | p2_side[a]->setZ(pieces.player2[a].z); | 591 | p2_side[a]->setZ(pieces.player2[a].z); |
592 | p2_side[a]->show(); | 592 | p2_side[a]->show(); |
593 | p2[a]->hide(); | 593 | p2[a]->hide(); |
594 | } | 594 | } |
595 | } | 595 | } |
596 | } | 596 | } |
597 | 597 | ||
598 | void BackGammon::mouse(int x,int y) | 598 | void BackGammon::mouse(int x,int y) |
599 | { | 599 | { |
600 | if(gameFinished) | 600 | if(gameFinished) |
601 | { | 601 | { |
602 | newgame(); | 602 | newgame(); |
603 | return; | 603 | return; |
604 | } | 604 | } |
605 | if(y<=200) //move pieces | 605 | if(y<=200) //move pieces |
606 | { | 606 | { |
607 | if((player==1 && player1_auto) || (player==2 && player2_auto)) | 607 | if((player==1 && player1_auto) || (player==2 && player2_auto)) |
608 | return; | 608 | return; |
609 | 609 | ||
610 | Marker marker; | 610 | Marker marker; |
611 | 611 | ||
612 | move->boardpressed(x,y,marker); | 612 | move->boardpressed(x,y,marker); |
613 | if(marker.visible_current) | 613 | if(marker.visible_current) |
614 | { | 614 | { |
615 | marker_current->setX(marker.x_current); | 615 | marker_current->setX(marker.x_current); |
616 | marker_current->setY(marker.y_current); | 616 | marker_current->setY(marker.y_current); |
617 | marker_current->show(); | 617 | marker_current->show(); |
618 | } | 618 | } |
619 | else | 619 | else |
620 | { | 620 | { |
621 | marker_current->hide(); | 621 | marker_current->hide(); |
622 | } | 622 | } |
623 | 623 | ||
624 | for(int a=0;a<4;a++) | 624 | for(int a=0;a<4;a++) |
625 | { | 625 | { |
626 | if(marker.visible_next[a]) | 626 | if(marker.visible_next[a]) |
627 | { | 627 | { |
628 | marker_next[a]->setX(marker.x_next[a]); | 628 | marker_next[a]->setX(marker.x_next[a]); |
629 | marker_next[a]->setY(marker.y_next[a]); | 629 | marker_next[a]->setY(marker.y_next[a]); |
630 | marker_next[a]->show(); | 630 | marker_next[a]->show(); |
631 | } | 631 | } |
632 | else | 632 | else |
633 | { | 633 | { |
634 | marker_next[a]->hide(); | 634 | marker_next[a]->hide(); |
635 | } | 635 | } |
636 | } | 636 | } |
637 | area->update(); | 637 | area->update(); |
638 | } | 638 | } |
639 | else //roll dice | 639 | else //roll dice |
640 | { | 640 | { |
641 | if(x>=10 && x<=65 && player==1 && !dice_rolled) | 641 | if(x>=10 && x<=65 && player==1 && !dice_rolled) |
642 | { | 642 | { |
643 | dice1_played=false; | 643 | dice1_played=false; |
644 | dice2_played=false; | 644 | dice2_played=false; |
645 | dice3_played=false; | 645 | dice3_played=false; |
646 | dice4_played=false; | 646 | dice4_played=false; |
647 | dice_rolled=true; | 647 | dice_rolled=true; |
648 | srand(QTime::currentTime().msec()); | 648 | srand(QTime::currentTime().msec()); |
649 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 649 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
650 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 650 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
651 | if(diceA1_value==diceA2_value) | 651 | if(diceA1_value==diceA2_value) |
652 | { | 652 | { |
653 | diceA3_value=diceA1_value; | 653 | diceA3_value=diceA1_value; |
654 | diceA4_value=diceA1_value; | 654 | diceA4_value=diceA1_value; |
655 | } | 655 | } |
656 | else | 656 | else |
657 | { | 657 | { |
658 | diceA3_value=7; | 658 | diceA3_value=7; |
659 | dice3_played=true; | 659 | dice3_played=true; |
660 | diceA4_value=7; | 660 | diceA4_value=7; |
661 | dice4_played=true; | 661 | dice4_played=true; |
662 | } | 662 | } |
663 | showdice(); | 663 | showdice(); |
664 | area->update(); | 664 | area->update(); |
665 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 665 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
666 | 666 | ||
667 | } | 667 | } |
668 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) | 668 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) |
669 | { | 669 | { |
670 | dice1_played=false; | 670 | dice1_played=false; |
671 | dice2_played=false; | 671 | dice2_played=false; |
672 | dice3_played=false; | 672 | dice3_played=false; |
673 | dice4_played=false; | 673 | dice4_played=false; |
674 | dice_rolled=true; | 674 | dice_rolled=true; |
675 | srand(QTime::currentTime().msec()); | 675 | srand(QTime::currentTime().msec()); |
676 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 676 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
677 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 677 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
678 | if(diceB1_value==diceB2_value) | 678 | if(diceB1_value==diceB2_value) |
679 | { | 679 | { |
680 | diceB3_value=diceB1_value; | 680 | diceB3_value=diceB1_value; |
681 | diceB4_value=diceB1_value; | 681 | diceB4_value=diceB1_value; |
682 | } | 682 | } |
683 | else | 683 | else |
684 | { | 684 | { |
685 | diceB3_value=7; | 685 | diceB3_value=7; |
686 | dice3_played=true; | 686 | dice3_played=true; |
687 | diceB4_value=7; | 687 | diceB4_value=7; |
688 | dice4_played=true; | 688 | dice4_played=true; |
689 | } | 689 | } |
690 | showdice(); | 690 | showdice(); |
691 | area->update(); | 691 | area->update(); |
692 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 692 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
693 | } | 693 | } |
694 | } | 694 | } |
695 | } | 695 | } |
696 | 696 | ||
697 | void BackGammon::done_dice1() | 697 | void BackGammon::done_dice1() |
698 | { | 698 | { |
699 | dice1_played=true; | 699 | dice1_played=true; |
700 | if(player==1) | 700 | if(player==1) |
701 | diceA1_value=7; | 701 | diceA1_value=7; |
702 | else | 702 | else |
703 | diceB1_value=7; | 703 | diceB1_value=7; |
704 | setplayer(); | 704 | setplayer(); |
705 | showdice(); | 705 | showdice(); |
706 | draw(); | 706 | draw(); |
707 | area->update(); | 707 | area->update(); |
708 | if(!dice2_played || !dice3_played || !dice4_played) | 708 | if(!dice2_played || !dice3_played || !dice4_played) |
709 | { | 709 | { |
710 | if(player==1) | 710 | if(player==1) |
711 | { | 711 | { |
712 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 712 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
713 | } | 713 | } |
714 | else | 714 | else |
715 | { | 715 | { |
716 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 716 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | } | 719 | } |
720 | 720 | ||
721 | void BackGammon::done_dice2() | 721 | void BackGammon::done_dice2() |
722 | { | 722 | { |
723 | dice2_played=true; | 723 | dice2_played=true; |
724 | if(player==1) | 724 | if(player==1) |
725 | diceA2_value=7; | 725 | diceA2_value=7; |
726 | else | 726 | else |
727 | diceB2_value=7; | 727 | diceB2_value=7; |
728 | setplayer(); | 728 | setplayer(); |
729 | showdice(); | 729 | showdice(); |
730 | draw(); | 730 | draw(); |
731 | area->update(); | 731 | area->update(); |
732 | if(!dice1_played || !dice3_played || !dice4_played) | 732 | if(!dice1_played || !dice3_played || !dice4_played) |
733 | { | 733 | { |
734 | if(player==1) | 734 | if(player==1) |
735 | { | 735 | { |
736 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 736 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
737 | } | 737 | } |
738 | else | 738 | else |
739 | { | 739 | { |
740 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 740 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
741 | } | 741 | } |
742 | } | 742 | } |
743 | } | 743 | } |
744 | 744 | ||
745 | 745 | ||
746 | void BackGammon::done_dice3() | 746 | void BackGammon::done_dice3() |
747 | { | 747 | { |
748 | dice3_played=true; | 748 | dice3_played=true; |
749 | if(player==1) | 749 | if(player==1) |
750 | diceA3_value=7; | 750 | diceA3_value=7; |
751 | else | 751 | else |
752 | diceB3_value=7; | 752 | diceB3_value=7; |
753 | setplayer(); | 753 | setplayer(); |
754 | showdice(); | 754 | showdice(); |
755 | draw(); | 755 | draw(); |
756 | area->update(); | 756 | area->update(); |
757 | if(!dice1_played || !dice2_played || !dice4_played) | 757 | if(!dice1_played || !dice2_played || !dice4_played) |
758 | { | 758 | { |
759 | if(player==1) | 759 | if(player==1) |
760 | { | 760 | { |
761 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 761 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
762 | } | 762 | } |
763 | else | 763 | else |
764 | { | 764 | { |
765 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 765 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
766 | } | 766 | } |
767 | } | 767 | } |
768 | } | 768 | } |
769 | 769 | ||
770 | 770 | ||
771 | void BackGammon::done_dice4() | 771 | void BackGammon::done_dice4() |
772 | { | 772 | { |
773 | dice4_played=true; | 773 | dice4_played=true; |
774 | if(player==1) | 774 | if(player==1) |
775 | diceA4_value=7; | 775 | diceA4_value=7; |
776 | else | 776 | else |
777 | diceB4_value=7; | 777 | diceB4_value=7; |
778 | setplayer(); | 778 | setplayer(); |
779 | showdice(); | 779 | showdice(); |
780 | draw(); | 780 | draw(); |
781 | area->update(); | 781 | area->update(); |
782 | if(!dice1_played || !dice2_played || !dice3_played) | 782 | if(!dice1_played || !dice2_played || !dice3_played) |
783 | { | 783 | { |
784 | if(player==1) | 784 | if(player==1) |
785 | { | 785 | { |
786 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 786 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
787 | } | 787 | } |
788 | else | 788 | else |
789 | { | 789 | { |
790 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 790 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
791 | } | 791 | } |
792 | } | 792 | } |
793 | } | 793 | } |
794 | 794 | ||
795 | 795 | ||
796 | void BackGammon::nomove() | 796 | void BackGammon::nomove() |
797 | { | 797 | { |
798 | if(player==1) | 798 | if(player==1) |
799 | nomove_marker->setX(0); | 799 | nomove_marker->setX(0); |
800 | else | 800 | else |
801 | nomove_marker->setX(170); | 801 | nomove_marker->setX(170); |
802 | nomove_marker->show(); | 802 | nomove_marker->show(); |
803 | message->setText(tr( "<b>no move</b>" )); | 803 | message->setText(tr( "<b>no move</b>" )); |
804 | dice1_played=true; | 804 | dice1_played=true; |
805 | dice2_played=true; | 805 | dice2_played=true; |
806 | dice3_played=true; | 806 | dice3_played=true; |
807 | dice4_played=true; | 807 | dice4_played=true; |
808 | if(player==1) | 808 | if(player==1) |
809 | { | 809 | { |
810 | diceA1_value=7; | 810 | diceA1_value=7; |
811 | diceA2_value=7; | 811 | diceA2_value=7; |
812 | diceA3_value=7; | 812 | diceA3_value=7; |
813 | diceA4_value=7; | 813 | diceA4_value=7; |
814 | } | 814 | } |
815 | else | 815 | else |
816 | { | 816 | { |
817 | diceB1_value=7; | 817 | diceB1_value=7; |
818 | diceB2_value=7; | 818 | diceB2_value=7; |
819 | diceB3_value=7; | 819 | diceB3_value=7; |
820 | diceB4_value=7; | 820 | diceB4_value=7; |
821 | } | 821 | } |
822 | area->update(); | 822 | area->update(); |
823 | QTimer::singleShot(2000,this,SLOT(nomove2())); | 823 | QTimer::singleShot(2000,this,SLOT(nomove2())); |
824 | } | 824 | } |
825 | 825 | ||
826 | void BackGammon::nomove2() | 826 | void BackGammon::nomove2() |
827 | { | 827 | { |
828 | nomove_marker->hide(); | 828 | nomove_marker->hide(); |
829 | setplayer(); | 829 | setplayer(); |
830 | showdice(); | 830 | showdice(); |
831 | draw(); | 831 | draw(); |
832 | area->update(); | 832 | area->update(); |
833 | } | 833 | } |
834 | 834 | ||
835 | void BackGammon::finished(int theplayer) | 835 | void BackGammon::finished(int theplayer) |
836 | { | 836 | { |
837 | nomove_marker->hide(); | 837 | nomove_marker->hide(); |
838 | if(theplayer==1) | 838 | if(theplayer==1) |
839 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); | 839 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); |
840 | else | 840 | else |
841 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); | 841 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); |
842 | diceA1_value=7; | 842 | diceA1_value=7; |
843 | diceA2_value=7; | 843 | diceA2_value=7; |
844 | diceB1_value=7; | 844 | diceB1_value=7; |
845 | diceB2_value=7; | 845 | diceB2_value=7; |
846 | player=0; | 846 | player=0; |
847 | showdice(); | 847 | showdice(); |
848 | draw(); | 848 | draw(); |
849 | area->update(); | 849 | area->update(); |
850 | gameFinished=true; | 850 | gameFinished=true; |
851 | } | 851 | } |
852 | 852 | ||
853 | void BackGammon::showdice() | 853 | void BackGammon::showdice() |
854 | { | 854 | { |
855 | int value_diceA1=diceA1_value-1; | 855 | int value_diceA1=diceA1_value-1; |
856 | if(diceA1_value==7 && diceA3_value!=7) | 856 | if(diceA1_value==7 && diceA3_value!=7) |
857 | value_diceA1=diceA3_value-1; | 857 | value_diceA1=diceA3_value-1; |
858 | 858 | ||
859 | int value_diceA2=diceA2_value-1; | 859 | int value_diceA2=diceA2_value-1; |
860 | if(diceA2_value==7 && diceA4_value!=7) | 860 | if(diceA2_value==7 && diceA4_value!=7) |
861 | value_diceA2=diceA4_value-1; | 861 | value_diceA2=diceA4_value-1; |
862 | 862 | ||
863 | int value_diceB1=diceB1_value-1; | 863 | int value_diceB1=diceB1_value-1; |
864 | if(diceB1_value==7 && diceB3_value!=7) | 864 | if(diceB1_value==7 && diceB3_value!=7) |
865 | value_diceB1=diceB3_value-1; | 865 | value_diceB1=diceB3_value-1; |
866 | 866 | ||
867 | int value_diceB2=diceB2_value-1; | 867 | int value_diceB2=diceB2_value-1; |
868 | if(diceB2_value==7 && diceB4_value!=7) | 868 | if(diceB2_value==7 && diceB4_value!=7) |
869 | value_diceB2=diceB4_value-1; | 869 | value_diceB2=diceB4_value-1; |
870 | 870 | ||
871 | for(int index=0;index<7;index++) | 871 | for(int index=0;index<7;index++) |
872 | { | 872 | { |
873 | if(value_diceA1==index) | 873 | if(value_diceA1==index) |
874 | diceA1[index]->show(); | 874 | diceA1[index]->show(); |
875 | else | 875 | else |
876 | diceA1[index]->hide(); | 876 | diceA1[index]->hide(); |
877 | 877 | ||
878 | if(value_diceA2==index) | 878 | if(value_diceA2==index) |
879 | diceA2[index]->show(); | 879 | diceA2[index]->show(); |
880 | else | 880 | else |
881 | diceA2[index]->hide(); | 881 | diceA2[index]->hide(); |
882 | 882 | ||
883 | if(value_diceB1==index) | 883 | if(value_diceB1==index) |
884 | diceB1[index]->show(); | 884 | diceB1[index]->show(); |
885 | else | 885 | else |
886 | diceB1[index]->hide(); | 886 | diceB1[index]->hide(); |
887 | 887 | ||
888 | if(value_diceB2==index) | 888 | if(value_diceB2==index) |
889 | diceB2[index]->show(); | 889 | diceB2[index]->show(); |
890 | else | 890 | else |
891 | diceB2[index]->hide(); | 891 | diceB2[index]->hide(); |
892 | } | 892 | } |
893 | } | 893 | } |
894 | 894 | ||
895 | void BackGammon::setplayer() | 895 | void BackGammon::setplayer() |
896 | { | 896 | { |
897 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) | 897 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) |
898 | { | 898 | { |
899 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); | 899 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); |
900 | dice_rolled=false; | 900 | dice_rolled=false; |
901 | player=2; | 901 | player=2; |
902 | if(player2_auto) | 902 | if(player2_auto) |
903 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); | 903 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); |
904 | } | 904 | } |
905 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) | 905 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) |
906 | { | 906 | { |
907 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); | 907 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); |
908 | dice_rolled=false; | 908 | dice_rolled=false; |
909 | player=1; | 909 | player=1; |
910 | if(player1_auto) | 910 | if(player1_auto) |
911 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); | 911 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); |
912 | } | 912 | } |
913 | } | 913 | } |
914 | 914 | ||
915 | void BackGammon::autoroll_dice1() | 915 | void BackGammon::autoroll_dice1() |
916 | { | 916 | { |
917 | mouse(20,210); | 917 | mouse(20,210); |
918 | } | 918 | } |
919 | 919 | ||
920 | void BackGammon::autoroll_dice2() | 920 | void BackGammon::autoroll_dice2() |
921 | { | 921 | { |
922 | mouse(170,210); | 922 | mouse(170,210); |
923 | } | 923 | } |
924 | 924 | ||
925 | void BackGammon::applytheme() | 925 | void BackGammon::applytheme() |
926 | { | 926 | { |
927 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 927 | QImage boardbg(Opie::Core::OResource::loadImage("backgammon/boards/"+board_name)); |
928 | board->setImage(boardbg); | 928 | board->setImage(boardbg); |
929 | 929 | ||
930 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 930 | QImage tablebg(Opie::Core::OResource::loadImage("backgammon/table/"+table_name)); |
931 | table->setImage(tablebg); | 931 | table->setImage(tablebg); |
932 | 932 | ||
933 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 933 | QImage piece_1_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesA_name)); |
934 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 934 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
935 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 935 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
936 | 936 | ||
937 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 937 | QImage piece_2_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesB_name)); |
938 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 938 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
939 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 939 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
940 | 940 | ||
941 | int a=0; | 941 | int a=0; |
942 | for(a=0;a<15;a++) | 942 | for(a=0;a<15;a++) |
943 | { | 943 | { |
944 | p1[a]->setImage(piece_1_front); | 944 | p1[a]->setImage(piece_1_front); |
945 | p1_side[a]->setImage(piece_1_side); | 945 | p1_side[a]->setImage(piece_1_side); |
946 | 946 | ||
947 | p2[a]->setImage(piece_2_front); | 947 | p2[a]->setImage(piece_2_front); |
948 | p2_side[a]->setImage(piece_2_side); | 948 | p2_side[a]->setImage(piece_2_side); |
949 | } | 949 | } |
950 | draw(); | 950 | draw(); |
951 | 951 | ||
952 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 952 | QImage dicebgA_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceA_name)); |
953 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 953 | QImage dicebgB_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceB_name)); |
954 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 954 | QImage oddsbg_all=(Opie::Core::OResource::loadImage("backgammon/odds/"+odds_name)); |
955 | 955 | ||
956 | for(a=0;a<7;a++) | 956 | for(a=0;a<7;a++) |
957 | { | 957 | { |
958 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 958 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
959 | diceA1[a]->setImage(dicebgA); | 959 | diceA1[a]->setImage(dicebgA); |
960 | diceA2[a]->setImage(dicebgA); | 960 | diceA2[a]->setImage(dicebgA); |
961 | 961 | ||
962 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 962 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
963 | diceB1[a]->setImage(dicebgB); | 963 | diceB1[a]->setImage(dicebgB); |
964 | diceB2[a]->setImage(dicebgB); | 964 | diceB2[a]->setImage(dicebgB); |
965 | /* | 965 | /* |
966 | if(a<6) | 966 | if(a<6) |
967 | { | 967 | { |
968 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 968 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
969 | oddsDice[a]->setImage(oddsbg); | 969 | oddsDice[a]->setImage(oddsbg); |
970 | } | 970 | } |
971 | */ | 971 | */ |
972 | } | 972 | } |
973 | } | 973 | } |
974 | 974 | ||
975 | 975 | ||
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index bb57ee1..c41c0a4 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp | |||
@@ -1,558 +1,550 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "fifteen.h" | 21 | #include "fifteen.h" |
22 | 22 | ||
23 | #include "fifteenconfigdialog.h" | 23 | #include "fifteenconfigdialog.h" |
24 | 24 | ||
25 | #include <opie2/ofileselector.h> | 25 | #include <opie2/ofileselector.h> |
26 | #include <opie2/oresource.h> | ||
26 | 27 | ||
27 | #include <qtopia/resource.h> | ||
28 | #include <qtopia/config.h> | 28 | #include <qtopia/config.h> |
29 | #include <qtopia/qpeapplication.h> | 29 | #include <qtopia/qpeapplication.h> |
30 | 30 | ||
31 | #include <qvbox.h> | 31 | #include <qvbox.h> |
32 | #include <qaction.h> | 32 | #include <qaction.h> |
33 | #include <qpainter.h> | 33 | #include <qpainter.h> |
34 | #include <qmessagebox.h> | 34 | #include <qmessagebox.h> |
35 | #include <qtoolbar.h> | 35 | #include <qtoolbar.h> |
36 | #include <qmenubar.h> | 36 | #include <qmenubar.h> |
37 | #include <qimage.h> | 37 | #include <qimage.h> |
38 | 38 | ||
39 | #include <stdlib.h> | 39 | #include <stdlib.h> |
40 | #include <time.h> | 40 | #include <time.h> |
41 | 41 | ||
42 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) | 42 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) |
43 | : QMainWindow( parent, name, fl ) | 43 | : QMainWindow( parent, name, fl ) |
44 | { | 44 | { |
45 | 45 | ||
46 | // random seed | 46 | // random seed |
47 | srand(time(0)); | 47 | srand(time(0)); |
48 | setCaption( tr("Fifteen Pieces") ); | 48 | setCaption( tr("Fifteen Pieces") ); |
49 | 49 | ||
50 | QToolBar *toolbar = new QToolBar(this); | 50 | QToolBar *toolbar = new QToolBar(this); |
51 | toolbar->setHorizontalStretchable( FALSE ); | 51 | toolbar->setHorizontalStretchable( FALSE ); |
52 | QMenuBar *menubar = new QMenuBar( toolbar ); | 52 | QMenuBar *menubar = new QMenuBar( toolbar ); |
53 | menubar->setMargin(0); | 53 | menubar->setMargin(0); |
54 | QPopupMenu *game = new QPopupMenu( this ); | 54 | QPopupMenu *game = new QPopupMenu( this ); |
55 | menubar->insertItem( tr( "Game" ), game ); | ||
55 | 56 | ||
56 | QWidget *spacer = new QWidget( toolbar ); | 57 | QWidget *spacer = new QWidget( toolbar ); |
57 | spacer->setBackgroundMode( PaletteButton ); | 58 | spacer->setBackgroundMode( PaletteButton ); |
58 | toolbar->setStretchableWidget( spacer ); | 59 | toolbar->setStretchableWidget( spacer ); |
59 | 60 | ||
60 | 61 | ||
61 | setToolBarsMovable( FALSE ); | 62 | setToolBarsMovable( FALSE ); |
62 | QVBox *vbox = new QVBox( this ); | 63 | QVBox *vbox = new QVBox( this ); |
63 | PiecesTable *table = new PiecesTable( vbox ); | 64 | PiecesTable *table = new PiecesTable( vbox ); |
64 | setCentralWidget(vbox); | 65 | setCentralWidget(vbox); |
65 | 66 | ||
66 | 67 | ||
67 | 68 | ||
68 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), | 69 | QAction *a = new QAction( tr( "Randomize" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
69 | QString::null, 0, this, 0 ); | 70 | QString::null, 0, this, 0 ); |
70 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); | 71 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); |
71 | a->addTo( game ); | 72 | a->addTo( game ); |
72 | a->addTo( toolbar ); | 73 | a->addTo( toolbar ); |
73 | 74 | ||
74 | 75 | ||
75 | a = new QAction( tr("Configure"), Resource::loadPixmap( "SettingsIcon" ), | 76 | a = new QAction( tr("Configure"), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), |
76 | QString::null, 0, this, 0 ); | 77 | QString::null, 0, this, 0 ); |
77 | connect( a, SIGNAL( activated()), table, SLOT( slotConfigure()) ); | 78 | connect( a, SIGNAL( activated()), table, SLOT( slotConfigure()) ); |
78 | a->addTo( game ); | 79 | a->addTo( game ); |
79 | |||
80 | /* This is pointless and confusing. | ||
81 | a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ), | ||
82 | QString::null, 0, this, 0 ); | ||
83 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); | ||
84 | a->addTo( game ); | ||
85 | a->addTo( toolbar ); | ||
86 | */ | ||
87 | menubar->insertItem( tr( "Game" ), game ); | ||
88 | } | 80 | } |
89 | 81 | ||
90 | 82 | ||
91 | 83 | ||
92 | 84 | ||
93 | /////////////// | 85 | /////////////// |
94 | /////// Pieces table Implementation | 86 | /////// Pieces table Implementation |
95 | /////// | 87 | /////// |
96 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) | 88 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) |
97 | : QTableView(parent, name), _menu(0), _randomized(false), | 89 | : QTableView(parent, name), _menu(0), _randomized(false), |
98 | _dialog( 0l ) | 90 | _dialog( 0l ) |
99 | { | 91 | { |
100 | // setup table view | 92 | // setup table view |
101 | setFrameStyle(StyledPanel | Sunken); | 93 | setFrameStyle(StyledPanel | Sunken); |
102 | setBackgroundMode(NoBackground); | 94 | setBackgroundMode(NoBackground); |
103 | setMouseTracking(true); | 95 | setMouseTracking(true); |
104 | 96 | ||
105 | setNumRows(4); | 97 | setNumRows(4); |
106 | setNumCols(4); | 98 | setNumCols(4); |
107 | 99 | ||
108 | // init arrays | 100 | // init arrays |
109 | readConfig(); | 101 | readConfig(); |
110 | initColors(); | 102 | initColors(); |
111 | 103 | ||
112 | } | 104 | } |
113 | 105 | ||
114 | 106 | ||
115 | PiecesTable::~PiecesTable() | 107 | PiecesTable::~PiecesTable() |
116 | { | 108 | { |
117 | writeConfig(); | 109 | writeConfig(); |
118 | clear(); | 110 | clear(); |
119 | } | 111 | } |
120 | 112 | ||
121 | void PiecesTable::writeConfig() | 113 | void PiecesTable::writeConfig() |
122 | { | 114 | { |
123 | Config cfg("Fifteen"); | 115 | Config cfg("Fifteen"); |
124 | cfg.setGroup("Game"); | 116 | cfg.setGroup("Game"); |
125 | QStringList map; | 117 | QStringList map; |
126 | 118 | ||
127 | int items = numRows()*numCols(); | 119 | int items = numRows()*numCols(); |
128 | 120 | ||
129 | for (int i = 0; i < items; i++) | 121 | for (int i = 0; i < items; i++) |
130 | map.append( QString::number( _map[i] ) ); | 122 | map.append( QString::number( _map[i] ) ); |
131 | 123 | ||
132 | cfg.writeEntry("Map", map, '-'); | 124 | cfg.writeEntry("Map", map, '-'); |
133 | cfg.writeEntry("Randomized", _randomized ); | 125 | cfg.writeEntry("Randomized", _randomized ); |
134 | cfg.writeEntry("Image", _image ); | 126 | cfg.writeEntry("Image", _image ); |
135 | cfg.writeEntry("Rows", numRows() ); | 127 | cfg.writeEntry("Rows", numRows() ); |
136 | cfg.writeEntry("Cols", numCols() ); | 128 | cfg.writeEntry("Cols", numCols() ); |
137 | } | 129 | } |
138 | 130 | ||
139 | void PiecesTable::readConfig() | 131 | void PiecesTable::readConfig() |
140 | { | 132 | { |
141 | Config cfg("Fifteen"); | 133 | Config cfg("Fifteen"); |
142 | cfg.setGroup("Game"); | 134 | cfg.setGroup("Game"); |
143 | QStringList map = cfg.readListEntry("Map", '-'); | 135 | QStringList map = cfg.readListEntry("Map", '-'); |
144 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); | 136 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); |
145 | _image = cfg.readEntry( "Image", QString::null ); | 137 | _image = cfg.readEntry( "Image", QString::null ); |
146 | 138 | ||
147 | int rows = cfg.readNumEntry( "Rows", 4 ); | 139 | int rows = cfg.readNumEntry( "Rows", 4 ); |
148 | int cols = cfg.readNumEntry( "Cols", 4 ); | 140 | int cols = cfg.readNumEntry( "Cols", 4 ); |
149 | uint items= rows*cols; | 141 | uint items= rows*cols; |
150 | setNumRows( rows ); | 142 | setNumRows( rows ); |
151 | setNumCols( cols ); | 143 | setNumCols( cols ); |
152 | 144 | ||
153 | initMap(); | 145 | initMap(); |
154 | 146 | ||
155 | /* if we've more items than 'stones' don't restore the state */ | 147 | /* if we've more items than 'stones' don't restore the state */ |
156 | if ( items > map.count() ) | 148 | if ( items > map.count() ) |
157 | return; | 149 | return; |
158 | 150 | ||
159 | 151 | ||
160 | uint i = 0; | 152 | uint i = 0; |
161 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { | 153 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { |
162 | _map[i] = (*it).toInt(); | 154 | _map[i] = (*it).toInt(); |
163 | i++; | 155 | i++; |
164 | if ( i > items ) break; | 156 | if ( i > items ) break; |
165 | } | 157 | } |
166 | 158 | ||
167 | } | 159 | } |
168 | 160 | ||
169 | 161 | ||
170 | void PiecesTable::clear() { | 162 | void PiecesTable::clear() { |
171 | /* clean up and resize */ | 163 | /* clean up and resize */ |
172 | for (uint i = 0; i < _pixmap.count(); ++i ) | 164 | for (uint i = 0; i < _pixmap.count(); ++i ) |
173 | delete _pixmap[i]; | 165 | delete _pixmap[i]; |
174 | _pixmap.resize( numRows()*numCols() ); | 166 | _pixmap.resize( numRows()*numCols() ); |
175 | } | 167 | } |
176 | 168 | ||
177 | /* | 169 | /* |
178 | * Let us pre-render the tiles. Either we've a Custom Image as | 170 | * Let us pre-render the tiles. Either we've a Custom Image as |
179 | * background or we use the drawRect to fill the background and | 171 | * background or we use the drawRect to fill the background and |
180 | * last we put the number on it | 172 | * last we put the number on it |
181 | */ | 173 | */ |
182 | void PiecesTable::slotCustomImage( const QString& _str ) { | 174 | void PiecesTable::slotCustomImage( const QString& _str ) { |
183 | QString str = _str; | 175 | QString str = _str; |
184 | 176 | ||
185 | 177 | ||
186 | /* couldn't load image fall back to plain tiles*/ | 178 | /* couldn't load image fall back to plain tiles*/ |
187 | QImage img = QImage(str); | 179 | QImage img = QImage(str); |
188 | QPixmap pix; | 180 | QPixmap pix; |
189 | if(img.isNull()) | 181 | if(img.isNull()) |
190 | str = QString::null; | 182 | str = QString::null; |
191 | else{ | 183 | else{ |
192 | img = img.smoothScale( width(),height() ); | 184 | img = img.smoothScale( width(),height() ); |
193 | pix.convertFromImage( img ); | 185 | pix.convertFromImage( img ); |
194 | } | 186 | } |
195 | 187 | ||
196 | /* initialize base point */ | 188 | /* initialize base point */ |
197 | uint image=0; | 189 | uint image=0; |
198 | 190 | ||
199 | /* clear the old tiles */ | 191 | /* clear the old tiles */ |
200 | clear(); | 192 | clear(); |
201 | 193 | ||
202 | /* used variables */ | 194 | /* used variables */ |
203 | int cols = numCols(); | 195 | int cols = numCols(); |
204 | int rows = numRows(); | 196 | int rows = numRows(); |
205 | int cellW = cellWidth(); | 197 | int cellW = cellWidth(); |
206 | int cellH = cellHeight(); | 198 | int cellH = cellHeight(); |
207 | int x2 = cellW-1; | 199 | int x2 = cellW-1; |
208 | int y2 = cellH-1; | 200 | int y2 = cellH-1; |
209 | bool empty = str.isEmpty(); | 201 | bool empty = str.isEmpty(); |
210 | double bw = empty ? 0.9 : 0.98; | 202 | double bw = empty ? 0.9 : 0.98; |
211 | int x_offset = cellW - int(cellW * bw);// 10% should be enough | 203 | int x_offset = cellW - int(cellW * bw);// 10% should be enough |
212 | inty_offset = cellH - int(cellH * bw); | 204 | inty_offset = cellH - int(cellH * bw); |
213 | 205 | ||
214 | /* border polygon calculation*/ | 206 | /* border polygon calculation*/ |
215 | initPolygon(cellW, cellH, x_offset, y_offset ); | 207 | initPolygon(cellW, cellH, x_offset, y_offset ); |
216 | 208 | ||
217 | /* avoid crashes with isNull() pixmap later */ | 209 | /* avoid crashes with isNull() pixmap later */ |
218 | if ( cellW == 0 || cellH == 0 ) { | 210 | if ( cellW == 0 || cellH == 0 ) { |
219 | _pixmap.resize( 0 ); | 211 | _pixmap.resize( 0 ); |
220 | return; | 212 | return; |
221 | } | 213 | } |
222 | 214 | ||
223 | /* make it bold and bigger */ | 215 | /* make it bold and bigger */ |
224 | QFont f = font(); | 216 | QFont f = font(); |
225 | f.setPixelSize(18); | 217 | f.setPixelSize(18); |
226 | f.setBold( TRUE ); | 218 | f.setBold( TRUE ); |
227 | 219 | ||
228 | /* for every tile */ | 220 | /* for every tile */ |
229 | for(int row = 0; row < rows; ++row ) { | 221 | for(int row = 0; row < rows; ++row ) { |
230 | for(int col= 0; col < cols; ++col) { | 222 | for(int col= 0; col < cols; ++col) { |
231 | QPixmap *pip = new QPixmap(cellW, cellH ); | 223 | QPixmap *pip = new QPixmap(cellW, cellH ); |
232 | QPainter *p = new QPainter(pip ); | 224 | QPainter *p = new QPainter(pip ); |
233 | p->setFont( f ); | 225 | p->setFont( f ); |
234 | 226 | ||
235 | /* draw the tradional tile or a part of the pixmap*/ | 227 | /* draw the tradional tile or a part of the pixmap*/ |
236 | if(empty) { | 228 | if(empty) { |
237 | p->setBrush(_colors[image]); | 229 | p->setBrush(_colors[image]); |
238 | p->setPen(NoPen); | 230 | p->setPen(NoPen); |
239 | p->drawRect(0,0,cellW,cellH); | 231 | p->drawRect(0,0,cellW,cellH); |
240 | }else | 232 | }else |
241 | p->drawPixmap(0, 0, pix,col*cellW, row*cellH, cellW, cellH ); | 233 | p->drawPixmap(0, 0, pix,col*cellW, row*cellH, cellW, cellH ); |
242 | 234 | ||
243 | // draw borders | 235 | // draw borders |
244 | if (height() > 40) { | 236 | if (height() > 40) { |
245 | p->setBrush(_colors[image].light(130)); | 237 | p->setBrush(_colors[image].light(130)); |
246 | p->drawPolygon(light_border); | 238 | p->drawPolygon(light_border); |
247 | 239 | ||
248 | p->setBrush(_colors[image].dark(130)); | 240 | p->setBrush(_colors[image].dark(130)); |
249 | p->drawPolygon(dark_border); | 241 | p->drawPolygon(dark_border); |
250 | } | 242 | } |
251 | 243 | ||
252 | // draw number | 244 | // draw number |
253 | p->setPen(black); | 245 | p->setPen(black); |
254 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(image+1)); | 246 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(image+1)); |
255 | 247 | ||
256 | delete p; | 248 | delete p; |
257 | _pixmap[image++] = pip; | 249 | _pixmap[image++] = pip; |
258 | } | 250 | } |
259 | } | 251 | } |
260 | _image = str; | 252 | _image = str; |
261 | } | 253 | } |
262 | 254 | ||
263 | /* | 255 | /* |
264 | * Calculate 3d-effect borders | 256 | * Calculate 3d-effect borders |
265 | */ | 257 | */ |
266 | void PiecesTable::initPolygon(int cell_w, int cell_h, int x_offset, int y_offset ) { | 258 | void PiecesTable::initPolygon(int cell_w, int cell_h, int x_offset, int y_offset ) { |
267 | light_border.setPoints(6, | 259 | light_border.setPoints(6, |
268 | 0, 0, | 260 | 0, 0, |
269 | cell_w, 0, | 261 | cell_w, 0, |
270 | cell_w - x_offset, y_offset, | 262 | cell_w - x_offset, y_offset, |
271 | x_offset, y_offset, | 263 | x_offset, y_offset, |
272 | x_offset, cell_h - y_offset, | 264 | x_offset, cell_h - y_offset, |
273 | 0, cell_h); | 265 | 0, cell_h); |
274 | 266 | ||
275 | dark_border.setPoints(6, | 267 | dark_border.setPoints(6, |
276 | cell_w, 0, | 268 | cell_w, 0, |
277 | cell_w, cell_h, | 269 | cell_w, cell_h, |
278 | 0, cell_h, | 270 | 0, cell_h, |
279 | x_offset, cell_h - y_offset, | 271 | x_offset, cell_h - y_offset, |
280 | cell_w - x_offset, cell_h - y_offset, | 272 | cell_w - x_offset, cell_h - y_offset, |
281 | cell_w - x_offset, y_offset); | 273 | cell_w - x_offset, y_offset); |
282 | } | 274 | } |
283 | 275 | ||
284 | void PiecesTable::paintCell(QPainter *p, int row, int col) | 276 | void PiecesTable::paintCell(QPainter *p, int row, int col) |
285 | { | 277 | { |
286 | int w = cellWidth(); | 278 | int w = cellWidth(); |
287 | int h = cellHeight(); | 279 | int h = cellHeight(); |
288 | 280 | ||
289 | uint pos = col+row*numCols(); | 281 | uint pos = col+row*numCols(); |
290 | 282 | ||
291 | /* sanity check. setNumRows()/setNumCols() calls repaint() directly */ | 283 | /* sanity check. setNumRows()/setNumCols() calls repaint() directly */ |
292 | if ( pos >= _map.count() ) { | 284 | if ( pos >= _map.count() ) { |
293 | p->drawRect(0, 0, w, h); | 285 | p->drawRect(0, 0, w, h); |
294 | return; | 286 | return; |
295 | } | 287 | } |
296 | 288 | ||
297 | int number = _map[col + row * numCols()] + 1; | 289 | int number = _map[col + row * numCols()] + 1; |
298 | 290 | ||
299 | // draw cell background | 291 | // draw cell background |
300 | if(number == numCols()*numRows() ) { | 292 | if(number == numCols()*numRows() ) { |
301 | p->setBrush(colorGroup().background()); | 293 | p->setBrush(colorGroup().background()); |
302 | p->setPen(NoPen); | 294 | p->setPen(NoPen); |
303 | p->drawRect(0, 0, w, h); | 295 | p->drawRect(0, 0, w, h); |
304 | return; | 296 | return; |
305 | } | 297 | } |
306 | 298 | ||
307 | /* no tiles then contentRect() is not visible or too small anyway */ | 299 | /* no tiles then contentRect() is not visible or too small anyway */ |
308 | if( _pixmap.count() == 0 ) | 300 | if( _pixmap.count() == 0 ) |
309 | return; | 301 | return; |
310 | 302 | ||
311 | p->drawPixmap(0, 0, *(_pixmap[(number-1 )]) ); | 303 | p->drawPixmap(0, 0, *(_pixmap[(number-1 )]) ); |
312 | } | 304 | } |
313 | 305 | ||
314 | void PiecesTable::resizeEvent(QResizeEvent *e) | 306 | void PiecesTable::resizeEvent(QResizeEvent *e) |
315 | { | 307 | { |
316 | /* | 308 | /* |
317 | * null if we faked it after the config dialog ran to | 309 | * null if we faked it after the config dialog ran to |
318 | * regenerate everything | 310 | * regenerate everything |
319 | */ | 311 | */ |
320 | if ( e ) | 312 | if ( e ) |
321 | QTableView::resizeEvent(e); | 313 | QTableView::resizeEvent(e); |
322 | 314 | ||
323 | setCellWidth(contentsRect().width()/ numCols()); | 315 | setCellWidth(contentsRect().width()/ numCols()); |
324 | setCellHeight(contentsRect().height() / numRows()); | 316 | setCellHeight(contentsRect().height() / numRows()); |
325 | 317 | ||
326 | 318 | ||
327 | /* update the image and calculate border*/ | 319 | /* update the image and calculate border*/ |
328 | slotCustomImage( _image ); | 320 | slotCustomImage( _image ); |
329 | 321 | ||
330 | } | 322 | } |
331 | 323 | ||
332 | void PiecesTable::initColors() | 324 | void PiecesTable::initColors() |
333 | { | 325 | { |
334 | _colors.resize(numRows() * numCols()); | 326 | _colors.resize(numRows() * numCols()); |
335 | for (int r = 0; r < numRows(); r++) | 327 | for (int r = 0; r < numRows(); r++) |
336 | for (int c = 0; c < numCols(); c++) | 328 | for (int c = 0; c < numCols(); c++) |
337 | _colors[c + r *numCols()] = QColor( 255 - (70 * c)%255 ,255 - (70 * r)%255, 150); | 329 | _colors[c + r *numCols()] = QColor( 255 - (70 * c)%255 ,255 - (70 * r)%255, 150); |
338 | } | 330 | } |
339 | 331 | ||
340 | void PiecesTable::initMap() | 332 | void PiecesTable::initMap() |
341 | { | 333 | { |
342 | int items = numCols()*numRows(); | 334 | int items = numCols()*numRows(); |
343 | _map.resize( items ); | 335 | _map.resize( items ); |
344 | for ( int i = 0; i < items; i++) | 336 | for ( int i = 0; i < items; i++) |
345 | _map[i] = i; | 337 | _map[i] = i; |
346 | 338 | ||
347 | _randomized = false; | 339 | _randomized = false; |
348 | } | 340 | } |
349 | 341 | ||
350 | void PiecesTable::randomizeMap() | 342 | void PiecesTable::randomizeMap() |
351 | { | 343 | { |
352 | initMap(); | 344 | initMap(); |
353 | _randomized = true; | 345 | _randomized = true; |
354 | // find the free position | 346 | // find the free position |
355 | int cols = numCols(); | 347 | int cols = numCols(); |
356 | int rows = numRows(); | 348 | int rows = numRows(); |
357 | int pos = _map.find( cols*rows -1 ); | 349 | int pos = _map.find( cols*rows -1 ); |
358 | 350 | ||
359 | int move = 0; | 351 | int move = 0; |
360 | while ( move < 333 ) { | 352 | while ( move < 333 ) { |
361 | 353 | ||
362 | int frow = pos / cols; | 354 | int frow = pos / cols; |
363 | int fcol = pos - frow * cols; | 355 | int fcol = pos - frow * cols; |
364 | 356 | ||
365 | // find click position | 357 | // find click position |
366 | int row = rand()%rows; | 358 | int row = rand()%rows; |
367 | int col = rand()%cols; | 359 | int col = rand()%cols; |
368 | 360 | ||
369 | // sanity check | 361 | // sanity check |
370 | if ( row < 0 || row >= rows ) continue; | 362 | if ( row < 0 || row >= rows ) continue; |
371 | if ( col < 0 || col >= cols ) continue; | 363 | if ( col < 0 || col >= cols ) continue; |
372 | if ( row != frow && col != fcol ) continue; | 364 | if ( row != frow && col != fcol ) continue; |
373 | 365 | ||
374 | move++; | 366 | move++; |
375 | 367 | ||
376 | // rows match -> shift pieces | 368 | // rows match -> shift pieces |
377 | if(row == frow) { | 369 | if(row == frow) { |
378 | 370 | ||
379 | if (col < fcol) { | 371 | if (col < fcol) { |
380 | for(int c = fcol; c > col; c--) { | 372 | for(int c = fcol; c > col; c--) { |
381 | _map[c + row * cols] = _map[ c-1 + row *cols]; | 373 | _map[c + row * cols] = _map[ c-1 + row *cols]; |
382 | } | 374 | } |
383 | } | 375 | } |
384 | else if (col > fcol) { | 376 | else if (col > fcol) { |
385 | for(int c = fcol; c < col; c++) { | 377 | for(int c = fcol; c < col; c++) { |
386 | _map[c + row * cols] = _map[ c+1 + row *cols]; | 378 | _map[c + row * cols] = _map[ c+1 + row *cols]; |
387 | } | 379 | } |
388 | } | 380 | } |
389 | } | 381 | } |
390 | // cols match -> shift pieces | 382 | // cols match -> shift pieces |
391 | else if (col == fcol) { | 383 | else if (col == fcol) { |
392 | 384 | ||
393 | if (row < frow) { | 385 | if (row < frow) { |
394 | for(int r = frow; r > row; r--) { | 386 | for(int r = frow; r > row; r--) { |
395 | _map[col + r * cols] = _map[ col + (r-1) *cols]; | 387 | _map[col + r * cols] = _map[ col + (r-1) *cols]; |
396 | } | 388 | } |
397 | } | 389 | } |
398 | else if (row > frow) { | 390 | else if (row > frow) { |
399 | for(int r = frow; r < row; r++) { | 391 | for(int r = frow; r < row; r++) { |
400 | _map[col + r * cols] = _map[ col + (r+1) *cols]; | 392 | _map[col + r * cols] = _map[ col + (r+1) *cols]; |
401 | } | 393 | } |
402 | } | 394 | } |
403 | } | 395 | } |
404 | // move free cell to click position | 396 | // move free cell to click position |
405 | _map[pos=(col + row * cols)] = rows*cols-1; | 397 | _map[pos=(col + row * cols)] = rows*cols-1; |
406 | } | 398 | } |
407 | repaint(); | 399 | repaint(); |
408 | } | 400 | } |
409 | 401 | ||
410 | void PiecesTable::checkwin() | 402 | void PiecesTable::checkwin() |
411 | { | 403 | { |
412 | if(!_randomized) return; | 404 | if(!_randomized) return; |
413 | 405 | ||
414 | int items=numCols()*numRows(); | 406 | int items=numCols()*numRows(); |
415 | int i; | 407 | int i; |
416 | for (i = 0; i < items; i++) | 408 | for (i = 0; i < items; i++) |
417 | if(i != _map[i]) | 409 | if(i != _map[i]) |
418 | break; | 410 | break; |
419 | 411 | ||
420 | if (i == items) { | 412 | if (i == items) { |
421 | QMessageBox::information(this, tr("Fifteen Pieces"), | 413 | QMessageBox::information(this, tr("Fifteen Pieces"), |
422 | tr("Congratulations!\nYou win the game!")); | 414 | tr("Congratulations!\nYou win the game!")); |
423 | _randomized = FALSE; | 415 | _randomized = FALSE; |
424 | } | 416 | } |
425 | 417 | ||
426 | } | 418 | } |
427 | 419 | ||
428 | void PiecesTable::slotRandomize() | 420 | void PiecesTable::slotRandomize() |
429 | { | 421 | { |
430 | randomizeMap(); | 422 | randomizeMap(); |
431 | } | 423 | } |
432 | 424 | ||
433 | void PiecesTable::slotReset() | 425 | void PiecesTable::slotReset() |
434 | { | 426 | { |
435 | initMap(); | 427 | initMap(); |
436 | repaint(); | 428 | repaint(); |
437 | } | 429 | } |
438 | 430 | ||
439 | void PiecesTable::mousePressEvent(QMouseEvent* e) | 431 | void PiecesTable::mousePressEvent(QMouseEvent* e) |
440 | { | 432 | { |
441 | QTableView::mousePressEvent(e); | 433 | QTableView::mousePressEvent(e); |
442 | 434 | ||
443 | if (e->button() == RightButton) { | 435 | if (e->button() == RightButton) { |
444 | 436 | ||
445 | // setup RMB pupup menu | 437 | // setup RMB pupup menu |
446 | if(!_menu) { | 438 | if(!_menu) { |
447 | _menu = new QPopupMenu(this); | 439 | _menu = new QPopupMenu(this); |
448 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); | 440 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); |
449 | _menu->insertItem(tr("&Reset Pieces"), mReset); | 441 | _menu->insertItem(tr("&Reset Pieces"), mReset); |
450 | _menu->adjustSize(); | 442 | _menu->adjustSize(); |
451 | } | 443 | } |
452 | 444 | ||
453 | // execute RMB popup and check result | 445 | // execute RMB popup and check result |
454 | switch(_menu->exec(mapToGlobal(e->pos()))) { | 446 | switch(_menu->exec(mapToGlobal(e->pos()))) { |
455 | case mRandomize: | 447 | case mRandomize: |
456 | randomizeMap(); | 448 | randomizeMap(); |
457 | break; | 449 | break; |
458 | case mReset: | 450 | case mReset: |
459 | initMap(); | 451 | initMap(); |
460 | repaint(); | 452 | repaint(); |
461 | break; | 453 | break; |
462 | default: | 454 | default: |
463 | break; | 455 | break; |
464 | } | 456 | } |
465 | } | 457 | } |
466 | else { | 458 | else { |
467 | // GAME LOGIC | 459 | // GAME LOGIC |
468 | int cols = numCols(); | 460 | int cols = numCols(); |
469 | int rows = numRows(); | 461 | int rows = numRows(); |
470 | int item = cols*rows -1; | 462 | int item = cols*rows -1; |
471 | 463 | ||
472 | // find the free position | 464 | // find the free position |
473 | int pos = _map.find(item); | 465 | int pos = _map.find(item); |
474 | if(pos < 0) return; | 466 | if(pos < 0) return; |
475 | 467 | ||
476 | int frow = pos / cols; | 468 | int frow = pos / cols; |
477 | int fcol = pos - frow * cols; | 469 | int fcol = pos - frow * cols; |
478 | 470 | ||
479 | // find click position | 471 | // find click position |
480 | int row = findRow(e->y()); | 472 | int row = findRow(e->y()); |
481 | int col = findCol(e->x()); | 473 | int col = findCol(e->x()); |
482 | 474 | ||
483 | // sanity check | 475 | // sanity check |
484 | if (row < 0 || row >= rows) return; | 476 | if (row < 0 || row >= rows) return; |
485 | if (col < 0 || col >= cols) return; | 477 | if (col < 0 || col >= cols) return; |
486 | if ( row != frow && col != fcol ) return; | 478 | if ( row != frow && col != fcol ) return; |
487 | 479 | ||
488 | // valid move? | 480 | // valid move? |
489 | if(row != frow && col != fcol) return; | 481 | if(row != frow && col != fcol) return; |
490 | 482 | ||
491 | // rows match -> shift pieces | 483 | // rows match -> shift pieces |
492 | if(row == frow) { | 484 | if(row == frow) { |
493 | 485 | ||
494 | if (col < fcol) { | 486 | if (col < fcol) { |
495 | for(int c = fcol; c > col; c--) { | 487 | for(int c = fcol; c > col; c--) { |
496 | _map[c + row * cols] = _map[ c-1 + row *cols]; | 488 | _map[c + row * cols] = _map[ c-1 + row *cols]; |
497 | updateCell(row, c, false); | 489 | updateCell(row, c, false); |
498 | } | 490 | } |
499 | } | 491 | } |
500 | else if (col > fcol) { | 492 | else if (col > fcol) { |
501 | for(int c = fcol; c < col; c++) { | 493 | for(int c = fcol; c < col; c++) { |
502 | _map[c + row * cols] = _map[ c+1 + row *cols]; | 494 | _map[c + row * cols] = _map[ c+1 + row *cols]; |
503 | updateCell(row, c, false); | 495 | updateCell(row, c, false); |
504 | } | 496 | } |
505 | } | 497 | } |
506 | } | 498 | } |
507 | // cols match -> shift pieces | 499 | // cols match -> shift pieces |
508 | else if (col == fcol) { | 500 | else if (col == fcol) { |
509 | 501 | ||
510 | if (row < frow) { | 502 | if (row < frow) { |
511 | for(int r = frow; r > row; r--) { | 503 | for(int r = frow; r > row; r--) { |
512 | _map[col + r * cols] = _map[ col + (r-1) *cols]; | 504 | _map[col + r * cols] = _map[ col + (r-1) *cols]; |
513 | updateCell(r, col, false); | 505 | updateCell(r, col, false); |
514 | } | 506 | } |
515 | } | 507 | } |
516 | else if (row > frow) { | 508 | else if (row > frow) { |
517 | for(int r = frow; r < row; r++) { | 509 | for(int r = frow; r < row; r++) { |
518 | _map[col + r * cols] = _map[ col + (r+1) *cols]; | 510 | _map[col + r * cols] = _map[ col + (r+1) *cols]; |
519 | updateCell(r, col, false); | 511 | updateCell(r, col, false); |
520 | } | 512 | } |
521 | } | 513 | } |
522 | } | 514 | } |
523 | // move free cell to click position | 515 | // move free cell to click position |
524 | _map[col + row * cols] = item; | 516 | _map[col + row * cols] = item; |
525 | updateCell(row, col, false); | 517 | updateCell(row, col, false); |
526 | 518 | ||
527 | // check if the player wins with this move | 519 | // check if the player wins with this move |
528 | checkwin(); | 520 | checkwin(); |
529 | } | 521 | } |
530 | } | 522 | } |
531 | 523 | ||
532 | void PiecesTable::slotConfigure() { | 524 | void PiecesTable::slotConfigure() { |
533 | if ( !_dialog ) | 525 | if ( !_dialog ) |
534 | _dialog = new FifteenConfigDialog(this, "Fifteen Configure Dialog", true ); | 526 | _dialog = new FifteenConfigDialog(this, "Fifteen Configure Dialog", true ); |
535 | 527 | ||
536 | 528 | ||
537 | _dialog->setImageSrc( _image ); | 529 | _dialog->setImageSrc( _image ); |
538 | _dialog->setGameboard( numRows(), numCols() ); | 530 | _dialog->setGameboard( numRows(), numCols() ); |
539 | 531 | ||
540 | if ( QPEApplication::execDialog(_dialog) == QDialog::Accepted ) { | 532 | if ( QPEApplication::execDialog(_dialog) == QDialog::Accepted ) { |
541 | /* | 533 | /* |
542 | * update the board grid and reinit the game if changed | 534 | * update the board grid and reinit the game if changed |
543 | * First set new columns so the update will regenerate the | 535 | * First set new columns so the update will regenerate the |
544 | * tiles with slotCustomImage | 536 | * tiles with slotCustomImage |
545 | */ | 537 | */ |
546 | _image = _dialog->imageSrc(); | 538 | _image = _dialog->imageSrc(); |
547 | if (numRows() != _dialog->rows() || | 539 | if (numRows() != _dialog->rows() || |
548 | numCols() != _dialog->columns() ) { | 540 | numCols() != _dialog->columns() ) { |
549 | setNumCols(_dialog->columns()); | 541 | setNumCols(_dialog->columns()); |
550 | setNumRows(_dialog->rows()); | 542 | setNumRows(_dialog->rows()); |
551 | slotReset(); | 543 | slotReset(); |
552 | } | 544 | } |
553 | resizeEvent( 0l ); | 545 | resizeEvent( 0l ); |
554 | 546 | ||
555 | 547 | ||
556 | update(); | 548 | update(); |
557 | } | 549 | } |
558 | } | 550 | } |
diff --git a/noncore/games/mindbreaker/config.in b/noncore/games/mindbreaker/config.in index b97a9e8..e3c0812 100644 --- a/noncore/games/mindbreaker/config.in +++ b/noncore/games/mindbreaker/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config MINDBREAKER | 1 | config MINDBREAKER |
2 | boolean "opie-mindbreaker (crack the coloured code)" | 2 | boolean "opie-mindbreaker (crack the coloured code)" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE |
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index 1f554d2..aa4afd7 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp | |||
@@ -1,953 +1,954 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "mindbreaker.h" | 21 | #include "mindbreaker.h" |
22 | 22 | ||
23 | #include <qtopia/resource.h> | 23 | #include <opie2/oresource.h> |
24 | |||
24 | #include <qtopia/config.h> | 25 | #include <qtopia/config.h> |
25 | #include <qtopia/qpeapplication.h> | 26 | #include <qtopia/qpeapplication.h> |
26 | #include <qtoolbar.h> | 27 | #include <qtoolbar.h> |
27 | 28 | ||
28 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
29 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
30 | #include <qlayout.h> | 31 | #include <qlayout.h> |
31 | #include <qtimer.h> | 32 | #include <qtimer.h> |
32 | 33 | ||
33 | #include <stdlib.h> | 34 | #include <stdlib.h> |
34 | #include <sys/time.h> | 35 | #include <sys/time.h> |
35 | #include <unistd.h> | 36 | #include <unistd.h> |
36 | 37 | ||
37 | static int pegRTTI = 3393393; | 38 | static int pegRTTI = 3393393; |
38 | 39 | ||
39 | static int adjusted_panel_height; | 40 | static int adjusted_panel_height; |
40 | static int adjusted_panel_width; | 41 | static int adjusted_panel_width; |
41 | 42 | ||
42 | static int adjusted_bin_margin; | 43 | static int adjusted_bin_margin; |
43 | static int adjusted_peg_size; | 44 | static int adjusted_peg_size; |
44 | static int adjusted_answerpeg_size; | 45 | static int adjusted_answerpeg_size; |
45 | 46 | ||
46 | static int adjusted_title_height; | 47 | static int adjusted_title_height; |
47 | static int adjusted_title_width; | 48 | static int adjusted_title_width; |
48 | 49 | ||
49 | static int adjusted_first_peg_x_diff; | 50 | static int adjusted_first_peg_x_diff; |
50 | static int adjusted_first_peg_y_diff; | 51 | static int adjusted_first_peg_y_diff; |
51 | static int adjusted_peg_spacing; | 52 | static int adjusted_peg_spacing; |
52 | 53 | ||
53 | static int adjusted_answerpegx; | 54 | static int adjusted_answerpegx; |
54 | static int adjusted_answerpegy; | 55 | static int adjusted_answerpegy; |
55 | static int adjusted_answerpeg_xdiff; | 56 | static int adjusted_answerpeg_xdiff; |
56 | static int adjusted_answerpeg_ydiff; | 57 | static int adjusted_answerpeg_ydiff; |
57 | 58 | ||
58 | static int adjusted_board_height; | 59 | static int adjusted_board_height; |
59 | static int adjusted_board_width; | 60 | static int adjusted_board_width; |
60 | 61 | ||
61 | static void setupBoardSize(int w, int h) | 62 | static void setupBoardSize(int w, int h) |
62 | { | 63 | { |
63 | adjusted_panel_width = w * 3/4; | 64 | adjusted_panel_width = w * 3/4; |
64 | adjusted_title_width = w * 3/4; | 65 | adjusted_title_width = w * 3/4; |
65 | 66 | ||
66 | adjusted_title_height = h/10; | 67 | adjusted_title_height = h/10; |
67 | adjusted_panel_height = (h-adjusted_title_height)/9; | 68 | adjusted_panel_height = (h-adjusted_title_height)/9; |
68 | 69 | ||
69 | adjusted_bin_margin = w * 10/240; | 70 | adjusted_bin_margin = w * 10/240; |
70 | adjusted_peg_size = adjusted_panel_height*3/4; | 71 | adjusted_peg_size = adjusted_panel_height*3/4; |
71 | adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25); | 72 | adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25); |
72 | 73 | ||
73 | // looks a bit dodgy on larger sizes | 74 | // looks a bit dodgy on larger sizes |
74 | if ( adjusted_peg_size > 40 ) | 75 | if ( adjusted_peg_size > 40 ) |
75 | adjusted_peg_size = 40; | 76 | adjusted_peg_size = 40; |
76 | 77 | ||
77 | adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2; | 78 | adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2; |
78 | adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2; | 79 | adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2; |
79 | adjusted_peg_spacing = w * 30/240; | 80 | adjusted_peg_spacing = w * 30/240; |
80 | 81 | ||
81 | // looks a bit dodgy on larger sizes (still does though, but not as much...) | 82 | // looks a bit dodgy on larger sizes (still does though, but not as much...) |
82 | if ( adjusted_answerpeg_size > 22 ) | 83 | if ( adjusted_answerpeg_size > 22 ) |
83 | adjusted_answerpeg_size = 22; | 84 | adjusted_answerpeg_size = 22; |
84 | 85 | ||
85 | adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2; | 86 | adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2; |
86 | adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2; | 87 | adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2; |
87 | adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180; | 88 | adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180; |
88 | adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25; | 89 | adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25; |
89 | 90 | ||
90 | adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9); | 91 | adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9); |
91 | adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size; | 92 | adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size; |
92 | 93 | ||
93 | // odebug << "Adjusted width " << adjusted_board_width << " height " << adjusted_board_height << "" << oendl; | 94 | // odebug << "Adjusted width " << adjusted_board_width << " height " << adjusted_board_height << "" << oendl; |
94 | } | 95 | } |
95 | 96 | ||
96 | 97 | ||
97 | /* helper class, */ | 98 | /* helper class, */ |
98 | class Peg : public QCanvasRectangle | 99 | class Peg : public QCanvasRectangle |
99 | { | 100 | { |
100 | public: | 101 | public: |
101 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); | 102 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); |
102 | int rtti() const {return pegRTTI; } | 103 | int rtti() const {return pegRTTI; } |
103 | void advance(int phase); | 104 | void advance(int phase); |
104 | 105 | ||
105 | bool hit( const QPoint &) const; | 106 | bool hit( const QPoint &) const; |
106 | 107 | ||
107 | /* a placed peg is one that has been set down on the board correctly and | 108 | /* a placed peg is one that has been set down on the board correctly and |
108 | should not be moved, only copied */ | 109 | should not be moved, only copied */ |
109 | bool placed() const; | 110 | bool placed() const; |
110 | void setPlaced(bool); | 111 | void setPlaced(bool); |
111 | 112 | ||
112 | int pegGo() const; | 113 | int pegGo() const; |
113 | int pegPos() const; | 114 | int pegPos() const; |
114 | void setPegPos(int); | 115 | void setPegPos(int); |
115 | 116 | ||
116 | int type() const; | 117 | int type() const; |
117 | 118 | ||
118 | static void buildImages(); | 119 | static void buildImages(); |
119 | static QImage imageForType(int t); | 120 | static QImage imageForType(int t); |
120 | 121 | ||
121 | static int eggLevel; | 122 | static int eggLevel; |
122 | 123 | ||
123 | protected: | 124 | protected: |
124 | void drawShape(QPainter &); | 125 | void drawShape(QPainter &); |
125 | private: | 126 | private: |
126 | static QVector<QImage> normalPegs; | 127 | static QVector<QImage> normalPegs; |
127 | static QVector<QImage> specialPegs; | 128 | static QVector<QImage> specialPegs; |
128 | 129 | ||
129 | bool isplaced; | 130 | bool isplaced; |
130 | int pegtype; | 131 | int pegtype; |
131 | int peg_go; | 132 | int peg_go; |
132 | int peg_pos; | 133 | int peg_pos; |
133 | 134 | ||
134 | int aniStep; | 135 | int aniStep; |
135 | }; | 136 | }; |
136 | int Peg::eggLevel = 0; | 137 | int Peg::eggLevel = 0; |
137 | QVector<QImage> Peg::normalPegs; | 138 | QVector<QImage> Peg::normalPegs; |
138 | QVector<QImage> Peg::specialPegs; | 139 | QVector<QImage> Peg::specialPegs; |
139 | 140 | ||
140 | void Peg::buildImages() | 141 | void Peg::buildImages() |
141 | { | 142 | { |
142 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); | 143 | QImage pegs = Opie::Core::OResource::loadImage("mindbreaker/pegs"); |
143 | int x = 0; | 144 | int x = 0; |
144 | int y = 0; | 145 | int y = 0; |
145 | int i; | 146 | int i; |
146 | eggLevel = 0; | 147 | eggLevel = 0; |
147 | normalPegs.resize(10); | 148 | normalPegs.resize(10); |
148 | for (i = 0; i < 6; i++) { | 149 | for (i = 0; i < 6; i++) { |
149 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size). | 150 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size). |
150 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); | 151 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); |
151 | x += peg_size; | 152 | x += peg_size; |
152 | } | 153 | } |
153 | specialPegs.resize(5); | 154 | specialPegs.resize(5); |
154 | for (i = 0; i < 5; i++) { | 155 | for (i = 0; i < 5; i++) { |
155 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size). | 156 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size). |
156 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); | 157 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); |
157 | x += peg_size; | 158 | x += peg_size; |
158 | } | 159 | } |
159 | 160 | ||
160 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 161 | QImage image = Opie::Core::OResource::loadImage("mindbreaker/mindbreaker"); |
161 | /* copy from master image to functional images */ | 162 | /* copy from master image to functional images */ |
162 | x = 0; | 163 | x = 0; |
163 | y = panel_height; | 164 | y = panel_height; |
164 | normalPegs.insert(8, | 165 | normalPegs.insert(8, |
165 | new QImage( image.copy(x, y, panel_width, panel_height). | 166 | new QImage( image.copy(x, y, panel_width, panel_height). |
166 | smoothScale( adjusted_panel_width, adjusted_panel_height) | 167 | smoothScale( adjusted_panel_width, adjusted_panel_height) |
167 | )); | 168 | )); |
168 | y += panel_height; | 169 | y += panel_height; |
169 | y += title_height; | 170 | y += title_height; |
170 | normalPegs.insert(9, | 171 | normalPegs.insert(9, |
171 | new QImage(image.copy(x, y, title_width, title_height). | 172 | new QImage(image.copy(x, y, title_width, title_height). |
172 | smoothScale( adjusted_title_width, adjusted_title_height) | 173 | smoothScale( adjusted_title_width, adjusted_title_height) |
173 | )); | 174 | )); |
174 | y += title_height; | 175 | y += title_height; |
175 | 176 | ||
176 | x = 6 * peg_size; | 177 | x = 6 * peg_size; |
177 | normalPegs.insert(6, | 178 | normalPegs.insert(6, |
178 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). | 179 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). |
179 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); | 180 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); |
180 | x += answerpeg_size; | 181 | x += answerpeg_size; |
181 | normalPegs.insert(7, | 182 | normalPegs.insert(7, |
182 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). | 183 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). |
183 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); | 184 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); |
184 | } | 185 | } |
185 | 186 | ||
186 | QImage Peg::imageForType(int t) | 187 | QImage Peg::imageForType(int t) |
187 | { | 188 | { |
188 | if (eggLevel > t ) { | 189 | if (eggLevel > t ) { |
189 | if( t < 5) { | 190 | if( t < 5) { |
190 | return *specialPegs[t]; | 191 | return *specialPegs[t]; |
191 | } else { | 192 | } else { |
192 | return *normalPegs[rand() % 6]; | 193 | return *normalPegs[rand() % 6]; |
193 | } | 194 | } |
194 | } | 195 | } |
195 | return *normalPegs[t]; | 196 | return *normalPegs[t]; |
196 | } | 197 | } |
197 | 198 | ||
198 | Peg::Peg(QCanvas *canvas , int t, int g, int p) | 199 | Peg::Peg(QCanvas *canvas , int t, int g, int p) |
199 | : QCanvasRectangle(canvas) | 200 | : QCanvasRectangle(canvas) |
200 | { | 201 | { |
201 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); | 202 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); |
202 | pegtype = t; | 203 | pegtype = t; |
203 | isplaced = FALSE; | 204 | isplaced = FALSE; |
204 | peg_pos = p; | 205 | peg_pos = p; |
205 | peg_go = g; | 206 | peg_go = g; |
206 | aniStep = rand() % 6; | 207 | aniStep = rand() % 6; |
207 | setAnimated(TRUE); | 208 | setAnimated(TRUE); |
208 | } | 209 | } |
209 | 210 | ||
210 | void Peg::advance(int phase) { | 211 | void Peg::advance(int phase) { |
211 | if (phase == 0) | 212 | if (phase == 0) |
212 | aniStep = (++aniStep) % 6; | 213 | aniStep = (++aniStep) % 6; |
213 | else { | 214 | else { |
214 | hide(); | 215 | hide(); |
215 | show(); | 216 | show(); |
216 | } | 217 | } |
217 | } | 218 | } |
218 | 219 | ||
219 | void Peg::drawShape(QPainter &p ) | 220 | void Peg::drawShape(QPainter &p ) |
220 | { | 221 | { |
221 | if ((pegtype == 5) && eggLevel > 5) { | 222 | if ((pegtype == 5) && eggLevel > 5) { |
222 | p.drawImage(int(x()), int(y()), *normalPegs[aniStep]); | 223 | p.drawImage(int(x()), int(y()), *normalPegs[aniStep]); |
223 | } else | 224 | } else |
224 | p.drawImage(int(x()), int(y()), imageForType(pegtype)); | 225 | p.drawImage(int(x()), int(y()), imageForType(pegtype)); |
225 | } | 226 | } |
226 | 227 | ||
227 | bool Peg::hit( const QPoint &p ) const | 228 | bool Peg::hit( const QPoint &p ) const |
228 | { | 229 | { |
229 | int ix = p.x() - int(x()); | 230 | int ix = p.x() - int(x()); |
230 | int iy = p.y() - int(y()); | 231 | int iy = p.y() - int(y()); |
231 | if (!normalPegs[pegtype]->valid(ix, iy)) | 232 | if (!normalPegs[pegtype]->valid(ix, iy)) |
232 | return FALSE; | 233 | return FALSE; |
233 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); | 234 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); |
234 | return (qAlpha(pixel ) != 0); | 235 | return (qAlpha(pixel ) != 0); |
235 | } | 236 | } |
236 | 237 | ||
237 | inline bool Peg::placed() const | 238 | inline bool Peg::placed() const |
238 | { | 239 | { |
239 | return isplaced; | 240 | return isplaced; |
240 | } | 241 | } |
241 | 242 | ||
242 | inline int Peg::pegGo() const | 243 | inline int Peg::pegGo() const |
243 | { | 244 | { |
244 | return peg_go; | 245 | return peg_go; |
245 | } | 246 | } |
246 | 247 | ||
247 | inline int Peg::pegPos() const | 248 | inline int Peg::pegPos() const |
248 | { | 249 | { |
249 | return peg_pos; | 250 | return peg_pos; |
250 | } | 251 | } |
251 | 252 | ||
252 | inline void Peg::setPegPos(int p) | 253 | inline void Peg::setPegPos(int p) |
253 | { | 254 | { |
254 | peg_pos = p; | 255 | peg_pos = p; |
255 | } | 256 | } |
256 | 257 | ||
257 | inline void Peg::setPlaced(bool p) | 258 | inline void Peg::setPlaced(bool p) |
258 | { | 259 | { |
259 | isplaced = p; | 260 | isplaced = p; |
260 | } | 261 | } |
261 | 262 | ||
262 | inline int Peg::type() const | 263 | inline int Peg::type() const |
263 | { | 264 | { |
264 | return pegtype; | 265 | return pegtype; |
265 | } | 266 | } |
266 | 267 | ||
267 | /* Load the main image, copy from it the pegs, the board, and the answer image | 268 | /* Load the main image, copy from it the pegs, the board, and the answer image |
268 | * and use these to create the tray, answer and board | 269 | * and use these to create the tray, answer and board |
269 | */ | 270 | */ |
270 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) | 271 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) |
271 | : QMainWindow(parent, name, wFlags) | 272 | : QMainWindow(parent, name, wFlags) |
272 | { | 273 | { |
273 | setCaption( tr("Mind Breaker")); | 274 | setCaption( tr("Mind Breaker")); |
274 | QPEApplication::setInputMethodHint( this, QPEApplication::AlwaysOff ); | 275 | QPEApplication::setInputMethodHint( this, QPEApplication::AlwaysOff ); |
275 | setMinimumSize(160,210); | 276 | setMinimumSize(160,210); |
276 | 277 | ||
277 | QWidget *w = new QWidget( this ); | 278 | QWidget *w = new QWidget( this ); |
278 | w->setBackgroundColor( black ); | 279 | w->setBackgroundColor( black ); |
279 | QHBoxLayout *hb = new QHBoxLayout( w ); | 280 | QHBoxLayout *hb = new QHBoxLayout( w ); |
280 | hb->addStretch(); | 281 | hb->addStretch(); |
281 | board = new MindBreakerBoard(w); | 282 | board = new MindBreakerBoard(w); |
282 | hb->addWidget( board, 100 ); | 283 | hb->addWidget( board, 100 ); |
283 | hb->addStretch(); | 284 | hb->addStretch(); |
284 | 285 | ||
285 | setCentralWidget(w); | 286 | setCentralWidget(w); |
286 | 287 | ||
287 | setToolBarsMovable( FALSE ); | 288 | setToolBarsMovable( FALSE ); |
288 | 289 | ||
289 | QToolBar *tb = new QToolBar(this); | 290 | QToolBar *tb = new QToolBar(this); |
290 | tb->setHorizontalStretchable( TRUE ); | 291 | tb->setHorizontalStretchable( TRUE ); |
291 | 292 | ||
292 | QIconSet newicon = Resource::loadIconSet("new"); | 293 | QToolButton *btn = new QToolButton( Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon), tr("New Game"), 0, |
293 | new QToolButton(newicon, tr("New Game"), 0, | 294 | board, SLOT(clear()), tb, "NewGame"); |
294 | board, SLOT(clear()), tb, "NewGame"); | 295 | btn->setUsesBigPixmap( qApp->desktop()->size().width() > 330 ); |
295 | 296 | ||
296 | score = new QToolButton(tb); | 297 | score = new QToolButton(tb); |
297 | score->setText(""); | 298 | score->setText(""); |
298 | score->setMaximumHeight(20); | 299 | score->setMaximumHeight(20); |
299 | score->setUsesTextLabel(TRUE); | 300 | score->setUsesTextLabel(TRUE); |
300 | tb->setStretchableWidget(score); | 301 | tb->setStretchableWidget(score); |
301 | 302 | ||
302 | connect(board, SIGNAL(scoreChanged(int,int)), this, SLOT(setScore(int,int))); | 303 | connect(board, SIGNAL(scoreChanged(int,int)), this, SLOT(setScore(int,int))); |
303 | connect(score, SIGNAL(clicked()), board, SLOT(resetScore())); | 304 | connect(score, SIGNAL(clicked()), board, SLOT(resetScore())); |
304 | 305 | ||
305 | int a, b; | 306 | int a, b; |
306 | board->getScore(&a, &b); | 307 | board->getScore(&a, &b); |
307 | setScore(a,b); | 308 | setScore(a,b); |
308 | 309 | ||
309 | layout()->setResizeMode(QLayout::FreeResize); | 310 | layout()->setResizeMode(QLayout::FreeResize); |
310 | } | 311 | } |
311 | 312 | ||
312 | void MindBreaker::setScore(int turns, int games) | 313 | void MindBreaker::setScore(int turns, int games) |
313 | { | 314 | { |
314 | double average; | 315 | double average; |
315 | double total_turns = turns; | 316 | double total_turns = turns; |
316 | double total_games = games; | 317 | double total_games = games; |
317 | 318 | ||
318 | if(total_games > 0) | 319 | if(total_games > 0) |
319 | average = total_turns / total_games; | 320 | average = total_turns / total_games; |
320 | else | 321 | else |
321 | average = 0.0; | 322 | average = 0.0; |
322 | 323 | ||
323 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); | 324 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); |
324 | } | 325 | } |
325 | 326 | ||
326 | void MindBreaker::resizeEvent( QResizeEvent *e ) | 327 | void MindBreaker::resizeEvent( QResizeEvent *e ) |
327 | { | 328 | { |
328 | board->fixSize(); | 329 | board->fixSize(); |
329 | QMainWindow::resizeEvent( e ); | 330 | QMainWindow::resizeEvent( e ); |
330 | } | 331 | } |
331 | 332 | ||
332 | 333 | ||
333 | MindBreakerBoard::MindBreakerBoard( QWidget *parent, | 334 | MindBreakerBoard::MindBreakerBoard( QWidget *parent, |
334 | const char *name, int wFlags ) | 335 | const char *name, int wFlags ) |
335 | : QCanvasView(0, parent, name, wFlags), | 336 | : QCanvasView(0, parent, name, wFlags), |
336 | moving(0), game_over(FALSE), total_turns(0), total_games(0) | 337 | moving(0), game_over(FALSE), total_turns(0), total_games(0) |
337 | { | 338 | { |
338 | setFrameStyle( NoFrame ); | 339 | setFrameStyle( NoFrame ); |
339 | setupBoardSize(qApp->desktop()->width(),qApp->desktop()->height()); | 340 | setupBoardSize(qApp->desktop()->width(),qApp->desktop()->height()); |
340 | cnv.resize(100,100); | 341 | cnv.resize(100,100); |
341 | setCanvas(&cnv); | 342 | setCanvas(&cnv); |
342 | setBackgroundColor( black ); | 343 | setBackgroundColor( black ); |
343 | 344 | ||
344 | struct timeval tv; | 345 | struct timeval tv; |
345 | 346 | ||
346 | current_go = 0; | 347 | current_go = 0; |
347 | gettimeofday(&tv, 0); | 348 | gettimeofday(&tv, 0); |
348 | srand(tv.tv_usec); | 349 | srand(tv.tv_usec); |
349 | 350 | ||
350 | canvas()->setAdvancePeriod(500); | 351 | canvas()->setAdvancePeriod(500); |
351 | current_highlight = 0; | 352 | current_highlight = 0; |
352 | 353 | ||
353 | widthTimer = new QTimer( this ); | 354 | widthTimer = new QTimer( this ); |
354 | connect(widthTimer, SIGNAL(timeout()), this, SLOT(doFixSize()) ); | 355 | connect(widthTimer, SIGNAL(timeout()), this, SLOT(doFixSize()) ); |
355 | 356 | ||
356 | setMaximumWidth( QMIN(qApp->desktop()->height(),qApp->desktop()->width()) ); | 357 | setMaximumWidth( QMIN(qApp->desktop()->height(),qApp->desktop()->width()) ); |
357 | //doFixSize(); // build images... needs to be done before reading config. | 358 | //doFixSize(); // build images... needs to be done before reading config. |
358 | //readConfig(); // first read... to ensure initial labels and side look right. | 359 | //readConfig(); // first read... to ensure initial labels and side look right. |
359 | } | 360 | } |
360 | 361 | ||
361 | void MindBreakerBoard::readConfig() | 362 | void MindBreakerBoard::readConfig() |
362 | { | 363 | { |
363 | Config c("MindBreaker", Config::User); | 364 | Config c("MindBreaker", Config::User); |
364 | c.setGroup("Board"); | 365 | c.setGroup("Board"); |
365 | game_over = FALSE; | 366 | game_over = FALSE; |
366 | int i; | 367 | int i; |
367 | if (c.readNumEntry("Answer0") < 0) { | 368 | if (c.readNumEntry("Answer0") < 0) { |
368 | for (i = 0; i < 4; i++) { | 369 | for (i = 0; i < 4; i++) { |
369 | answer[i] = rand() % 6; | 370 | answer[i] = rand() % 6; |
370 | current_guess[i] = 6; | 371 | current_guess[i] = 6; |
371 | } | 372 | } |
372 | total_turns = 0; | 373 | total_turns = 0; |
373 | total_games = 0; | 374 | total_games = 0; |
374 | } else { | 375 | } else { |
375 | int j; | 376 | int j; |
376 | c.setGroup("Score"); | 377 | c.setGroup("Score"); |
377 | total_turns = c.readNumEntry("Turns"); | 378 | total_turns = c.readNumEntry("Turns"); |
378 | total_games = c.readNumEntry("Games"); | 379 | total_games = c.readNumEntry("Games"); |
379 | if(total_turns < 0) | 380 | if(total_turns < 0) |
380 | total_turns = 0; | 381 | total_turns = 0; |
381 | if(total_games < 0) | 382 | if(total_games < 0) |
382 | total_games = 0; | 383 | total_games = 0; |
383 | 384 | ||
384 | 385 | ||
385 | checkScores(); | 386 | checkScores(); |
386 | c.setGroup("Board"); | 387 | c.setGroup("Board"); |
387 | for(i = 0; i < 4; i++) | 388 | for(i = 0; i < 4; i++) |
388 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); | 389 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); |
389 | /* read, and parse past guesses */ | 390 | /* read, and parse past guesses */ |
390 | current_go = 0; | 391 | current_go = 0; |
391 | for(j=0; j < 9; j++) { | 392 | for(j=0; j < 9; j++) { |
392 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); | 393 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); |
393 | if (current_guess[0] < 0) | 394 | if (current_guess[0] < 0) |
394 | break; | 395 | break; |
395 | placeGuessPeg(0, current_guess[0]); | 396 | placeGuessPeg(0, current_guess[0]); |
396 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); | 397 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); |
397 | placeGuessPeg(1, current_guess[1]); | 398 | placeGuessPeg(1, current_guess[1]); |
398 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); | 399 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); |
399 | placeGuessPeg(2, current_guess[2]); | 400 | placeGuessPeg(2, current_guess[2]); |
400 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); | 401 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); |
401 | placeGuessPeg(3, current_guess[3]); | 402 | placeGuessPeg(3, current_guess[3]); |
402 | checkGuess(); | 403 | checkGuess(); |
403 | } | 404 | } |
404 | for(i = 0; i < 4; i++) { | 405 | for(i = 0; i < 4; i++) { |
405 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); | 406 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); |
406 | if (current_guess[i] != 6) | 407 | if (current_guess[i] != 6) |
407 | placeGuessPeg(i, current_guess[i]); | 408 | placeGuessPeg(i, current_guess[i]); |
408 | } | 409 | } |
409 | } | 410 | } |
410 | } | 411 | } |
411 | 412 | ||
412 | MindBreakerBoard::~MindBreakerBoard() | 413 | MindBreakerBoard::~MindBreakerBoard() |
413 | { | 414 | { |
414 | int i; | 415 | int i; |
415 | if (game_over) { | 416 | if (game_over) { |
416 | current_go = 0; | 417 | current_go = 0; |
417 | /* clear the answer, clear the guess */ | 418 | /* clear the answer, clear the guess */ |
418 | for (i = 0; i < 4; i++) { | 419 | for (i = 0; i < 4; i++) { |
419 | answer[i] = rand() % 6; | 420 | answer[i] = rand() % 6; |
420 | current_guess[i] = 6; | 421 | current_guess[i] = 6; |
421 | } | 422 | } |
422 | } | 423 | } |
423 | writeConfig(); | 424 | writeConfig(); |
424 | } | 425 | } |
425 | 426 | ||
426 | void MindBreakerBoard::writeConfig() | 427 | void MindBreakerBoard::writeConfig() |
427 | { | 428 | { |
428 | Config c("MindBreaker", Config::User); | 429 | Config c("MindBreaker", Config::User); |
429 | c.setGroup("Board"); | 430 | c.setGroup("Board"); |
430 | c.clearGroup(); | 431 | c.clearGroup(); |
431 | /* write the board */ | 432 | /* write the board */ |
432 | int i,j; | 433 | int i,j; |
433 | for (i = 0; i < current_go; i++) { | 434 | for (i = 0; i < current_go; i++) { |
434 | for(j = 0; j < 4; j++) | 435 | for(j = 0; j < 4; j++) |
435 | c.writeEntry(QString("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); | 436 | c.writeEntry(QString("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); |
436 | } | 437 | } |
437 | for(j = 0; j < 4; j++) | 438 | for(j = 0; j < 4; j++) |
438 | c.writeEntry(QString("CurrentGo%1").arg(j), current_guess[j]); | 439 | c.writeEntry(QString("CurrentGo%1").arg(j), current_guess[j]); |
439 | for(j = 0; j < 4; j++) | 440 | for(j = 0; j < 4; j++) |
440 | c.writeEntry(QString("Answer%1").arg(j), answer[j]); | 441 | c.writeEntry(QString("Answer%1").arg(j), answer[j]); |
441 | 442 | ||
442 | c.setGroup("Score"); | 443 | c.setGroup("Score"); |
443 | /* write the score */ | 444 | /* write the score */ |
444 | 445 | ||
445 | c.writeEntry("Turns", total_turns); | 446 | c.writeEntry("Turns", total_turns); |
446 | c.writeEntry("Games", total_games); | 447 | c.writeEntry("Games", total_games); |
447 | } | 448 | } |
448 | 449 | ||
449 | void MindBreakerBoard::getScore(int *a, int *b) | 450 | void MindBreakerBoard::getScore(int *a, int *b) |
450 | { | 451 | { |
451 | *a = total_turns; | 452 | *a = total_turns; |
452 | *b = total_games; | 453 | *b = total_games; |
453 | return; | 454 | return; |
454 | } | 455 | } |
455 | 456 | ||
456 | void MindBreakerBoard::fixSize() | 457 | void MindBreakerBoard::fixSize() |
457 | { | 458 | { |
458 | hide(); | 459 | hide(); |
459 | setMaximumWidth( parentWidget()->height() ); | 460 | setMaximumWidth( parentWidget()->height() ); |
460 | widthTimer->start( 20, TRUE ); | 461 | widthTimer->start( 20, TRUE ); |
461 | } | 462 | } |
462 | 463 | ||
463 | void MindBreakerBoard::doFixSize() | 464 | void MindBreakerBoard::doFixSize() |
464 | { | 465 | { |
465 | QSize s = size(); | 466 | QSize s = size(); |
466 | int fw = frameWidth(); | 467 | int fw = frameWidth(); |
467 | s.setWidth(s.width() - fw); | 468 | s.setWidth(s.width() - fw); |
468 | s.setHeight(s.height() - fw); | 469 | s.setHeight(s.height() - fw); |
469 | 470 | ||
470 | /* min size is 200 x 260 */ | 471 | /* min size is 200 x 260 */ |
471 | /* | 472 | /* |
472 | if (s.width() < adjusted_board_width) | 473 | if (s.width() < adjusted_board_width) |
473 | s.setWidth(adjusted_board_width); | 474 | s.setWidth(adjusted_board_width); |
474 | 475 | ||
475 | if (s.height() < adjusted_board_height) | 476 | if (s.height() < adjusted_board_height) |
476 | s.setHeight(adjusted_board_height); | 477 | s.setHeight(adjusted_board_height); |
477 | */ | 478 | */ |
478 | 479 | ||
479 | if ( current_highlight ) // non-first resize | 480 | if ( current_highlight ) // non-first resize |
480 | writeConfig(); | 481 | writeConfig(); |
481 | 482 | ||
482 | setupBoardSize(s.width() - fw, s.height() - fw); | 483 | setupBoardSize(s.width() - fw, s.height() - fw); |
483 | canvas()->resize(s.width() - fw, s.height() - fw); | 484 | canvas()->resize(s.width() - fw, s.height() - fw); |
484 | Peg::buildImages(); // must be done BEFORE any pegs are made | 485 | Peg::buildImages(); // must be done BEFORE any pegs are made |
485 | 486 | ||
486 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 487 | QImage image = Opie::Core::OResource::loadImage("mindbreaker/mindbreaker"); |
487 | 488 | ||
488 | /* copy from master image to functional images */ | 489 | /* copy from master image to functional images */ |
489 | int x = 0; | 490 | int x = 0; |
490 | int y = 0; | 491 | int y = 0; |
491 | panelImage = image.copy(x, y, panel_width, panel_height). | 492 | panelImage = image.copy(x, y, panel_width, panel_height). |
492 | smoothScale( adjusted_panel_width, adjusted_panel_height); | 493 | smoothScale( adjusted_panel_width, adjusted_panel_height); |
493 | 494 | ||
494 | y += panel_height; | 495 | y += panel_height; |
495 | y += panel_height; | 496 | y += panel_height; |
496 | 497 | ||
497 | titleImage = image.copy(x, y, title_width, title_height). | 498 | titleImage = image.copy(x, y, title_width, title_height). |
498 | smoothScale( adjusted_title_width, adjusted_title_height); | 499 | smoothScale( adjusted_title_width, adjusted_title_height); |
499 | show(); | 500 | show(); |
500 | 501 | ||
501 | delete current_highlight; | 502 | delete current_highlight; |
502 | current_highlight = new Peg(canvas(), 8); | 503 | current_highlight = new Peg(canvas(), 8); |
503 | current_highlight->setPlaced(TRUE); | 504 | current_highlight->setPlaced(TRUE); |
504 | current_highlight->setX(0); | 505 | current_highlight->setX(0); |
505 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); | 506 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); |
506 | current_highlight->setZ(0); | 507 | current_highlight->setZ(0); |
507 | current_highlight->show(); | 508 | current_highlight->show(); |
508 | 509 | ||
509 | /* set up the game */ | 510 | /* set up the game */ |
510 | //readConfig(); | 511 | //readConfig(); |
511 | 512 | ||
512 | /* draw initial screen */ | 513 | /* draw initial screen */ |
513 | //drawBackground(); | 514 | //drawBackground(); |
514 | //canvas()->update(); | 515 | //canvas()->update(); |
515 | clear(); | 516 | clear(); |
516 | 517 | ||
517 | readConfig(); | 518 | readConfig(); |
518 | } | 519 | } |
519 | 520 | ||
520 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) | 521 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) |
521 | { | 522 | { |
522 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); | 523 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); |
523 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) | 524 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) |
524 | + adjusted_first_peg_y_diff; | 525 | + adjusted_first_peg_y_diff; |
525 | 526 | ||
526 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); | 527 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); |
527 | peg->setPegPos(pos); | 528 | peg->setPegPos(pos); |
528 | peg->setPlaced(TRUE); | 529 | peg->setPlaced(TRUE); |
529 | peg->setX(x); | 530 | peg->setX(x); |
530 | peg->setY(y); | 531 | peg->setY(y); |
531 | peg->setZ(2); | 532 | peg->setZ(2); |
532 | peg->show(); | 533 | peg->show(); |
533 | } | 534 | } |
534 | 535 | ||
535 | void MindBreakerBoard::drawBackground() | 536 | void MindBreakerBoard::drawBackground() |
536 | { | 537 | { |
537 | int i, j, x, y, x_gap, y_gap; | 538 | int i, j, x, y, x_gap, y_gap; |
538 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); | 539 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); |
539 | 540 | ||
540 | QPainter painter(&background); | 541 | QPainter painter(&background); |
541 | 542 | ||
542 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); | 543 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); |
543 | /* very first thing is to draw the bins, as everything else needs | 544 | /* very first thing is to draw the bins, as everything else needs |
544 | * to be drawn over them */ | 545 | * to be drawn over them */ |
545 | 546 | ||
546 | QPen pen(QColor(85, 45, 27), 4); | 547 | QPen pen(QColor(85, 45, 27), 4); |
547 | painter.setPen(pen); | 548 | painter.setPen(pen); |
548 | x_gap = canvas()->width() - (adjusted_panel_width + (2 * adjusted_bin_margin)); | 549 | x_gap = canvas()->width() - (adjusted_panel_width + (2 * adjusted_bin_margin)); |
549 | //x_gap += peg_size >> 1; | 550 | //x_gap += peg_size >> 1; |
550 | if (x_gap < 1) | 551 | if (x_gap < 1) |
551 | x_gap = 1; | 552 | x_gap = 1; |
552 | 553 | ||
553 | y_gap = adjusted_board_height / 6; | 554 | y_gap = adjusted_board_height / 6; |
554 | y_gap -= (2 * adjusted_bin_margin); | 555 | y_gap -= (2 * adjusted_bin_margin); |
555 | //y_gap += peg_size >> 1; | 556 | //y_gap += peg_size >> 1; |
556 | if (y_gap < 1) | 557 | if (y_gap < 1) |
557 | y_gap = 1; | 558 | y_gap = 1; |
558 | x = adjusted_panel_width + adjusted_bin_margin - (adjusted_peg_size >> 1); | 559 | x = adjusted_panel_width + adjusted_bin_margin - (adjusted_peg_size >> 1); |
559 | y = adjusted_bin_margin - (adjusted_peg_size >> 1) + 2; | 560 | y = adjusted_bin_margin - (adjusted_peg_size >> 1) + 2; |
560 | 561 | ||
561 | for (i = 0; i < 6; i++) { | 562 | for (i = 0; i < 6; i++) { |
562 | for (j = 0; j < 10; j++) { | 563 | for (j = 0; j < 10; j++) { |
563 | int rx = x + (rand() % x_gap); | 564 | int rx = x + (rand() % x_gap); |
564 | int ry = y + (rand() % y_gap); | 565 | int ry = y + (rand() % y_gap); |
565 | painter.drawImage(rx,ry, Peg::imageForType(i)); | 566 | painter.drawImage(rx,ry, Peg::imageForType(i)); |
566 | } | 567 | } |
567 | y += adjusted_board_height / 6; | 568 | y += adjusted_board_height / 6; |
568 | } | 569 | } |
569 | /* now draw the surrounding boxes */ | 570 | /* now draw the surrounding boxes */ |
570 | x_gap = canvas()->width() - adjusted_panel_width; | 571 | x_gap = canvas()->width() - adjusted_panel_width; |
571 | if (x_gap < 1) x_gap = 1; | 572 | if (x_gap < 1) x_gap = 1; |
572 | y_gap = adjusted_board_height / 6; | 573 | y_gap = adjusted_board_height / 6; |
573 | x = adjusted_panel_width; | 574 | x = adjusted_panel_width; |
574 | y = 1; | 575 | y = 1; |
575 | 576 | ||
576 | for (i = 0; i < 6; i++) { | 577 | for (i = 0; i < 6; i++) { |
577 | painter.drawRect(x, y, x_gap, y_gap); | 578 | painter.drawRect(x, y, x_gap, y_gap); |
578 | y += y_gap; | 579 | y += y_gap; |
579 | } | 580 | } |
580 | 581 | ||
581 | x = 0; | 582 | x = 0; |
582 | y = 0; | 583 | y = 0; |
583 | 584 | ||
584 | painter.drawImage(x,y, titleImage); | 585 | painter.drawImage(x,y, titleImage); |
585 | y = adjusted_title_height; | 586 | y = adjusted_title_height; |
586 | /* now nine gues panels */ | 587 | /* now nine gues panels */ |
587 | for (i = 0; i < 9; i ++) { | 588 | for (i = 0; i < 9; i ++) { |
588 | painter.drawImage(x, y, panelImage); | 589 | painter.drawImage(x, y, panelImage); |
589 | y += adjusted_panel_height; | 590 | y += adjusted_panel_height; |
590 | } | 591 | } |
591 | 592 | ||
592 | painter.flush(); | 593 | painter.flush(); |
593 | canvas()->setBackgroundPixmap(background); | 594 | canvas()->setBackgroundPixmap(background); |
594 | } | 595 | } |
595 | 596 | ||
596 | void MindBreakerBoard::checkGuess() | 597 | void MindBreakerBoard::checkGuess() |
597 | { | 598 | { |
598 | int i,j; | 599 | int i,j; |
599 | int num_white = 0; | 600 | int num_white = 0; |
600 | int num_black = 0; | 601 | int num_black = 0; |
601 | int copy_answer[4]; | 602 | int copy_answer[4]; |
602 | int copy_guess[4]; | 603 | int copy_guess[4]; |
603 | 604 | ||
604 | for(i = 0; i < 4; i++) { | 605 | for(i = 0; i < 4; i++) { |
605 | copy_answer[i] = answer[i]; | 606 | copy_answer[i] = answer[i]; |
606 | copy_guess[i] = current_guess[i]; | 607 | copy_guess[i] = current_guess[i]; |
607 | if (current_guess[i] == 6) | 608 | if (current_guess[i] == 6) |
608 | return; | 609 | return; |
609 | if (answer[i] == current_guess[i]) { | 610 | if (answer[i] == current_guess[i]) { |
610 | num_black++; | 611 | num_black++; |
611 | copy_answer[i] = 6; | 612 | copy_answer[i] = 6; |
612 | copy_guess[i] = 7; | 613 | copy_guess[i] = 7; |
613 | } | 614 | } |
614 | } | 615 | } |
615 | 616 | ||
616 | /* now sure that user has completed a 'guess' */ | 617 | /* now sure that user has completed a 'guess' */ |
617 | for (i = 0; i < 4; i++) { | 618 | for (i = 0; i < 4; i++) { |
618 | if (copy_guess[i] == 7) | 619 | if (copy_guess[i] == 7) |
619 | continue; // already marked for a black | 620 | continue; // already marked for a black |
620 | for (j = 0; j < 4; j++) { | 621 | for (j = 0; j < 4; j++) { |
621 | if(copy_guess[i] == copy_answer[j]) { | 622 | if(copy_guess[i] == copy_answer[j]) { |
622 | copy_answer[j] = 6; | 623 | copy_answer[j] = 6; |
623 | num_white++; | 624 | num_white++; |
624 | break; | 625 | break; |
625 | } | 626 | } |
626 | } | 627 | } |
627 | } | 628 | } |
628 | 629 | ||
629 | int x = adjusted_answerpegx; | 630 | int x = adjusted_answerpegx; |
630 | int y = (adjusted_board_height - ((current_go + 1) * adjusted_panel_height)) + adjusted_answerpegy; | 631 | int y = (adjusted_board_height - ((current_go + 1) * adjusted_panel_height)) + adjusted_answerpegy; |
631 | 632 | ||
632 | if (num_black == 4) | 633 | if (num_black == 4) |
633 | game_over = TRUE; | 634 | game_over = TRUE; |
634 | 635 | ||
635 | while(num_black > 0) { | 636 | while(num_black > 0) { |
636 | Peg *p = new Peg(canvas(), 7); | 637 | Peg *p = new Peg(canvas(), 7); |
637 | p->setPlaced(TRUE); | 638 | p->setPlaced(TRUE); |
638 | p->setX(x); | 639 | p->setX(x); |
639 | p->setY(y); | 640 | p->setY(y); |
640 | p->setZ(1); | 641 | p->setZ(1); |
641 | p->show(); | 642 | p->show(); |
642 | num_black--; | 643 | num_black--; |
643 | 644 | ||
644 | if (x == adjusted_answerpegx) | 645 | if (x == adjusted_answerpegx) |
645 | x = adjusted_answerpegx + adjusted_answerpeg_xdiff; | 646 | x = adjusted_answerpegx + adjusted_answerpeg_xdiff; |
646 | else { | 647 | else { |
647 | x = adjusted_answerpegx; | 648 | x = adjusted_answerpegx; |
648 | y += adjusted_answerpeg_ydiff; | 649 | y += adjusted_answerpeg_ydiff; |
649 | } | 650 | } |
650 | } | 651 | } |
651 | while(num_white > 0){ | 652 | while(num_white > 0){ |
652 | Peg *p = new Peg(canvas(), 6); | 653 | Peg *p = new Peg(canvas(), 6); |
653 | p->setPlaced(TRUE); | 654 | p->setPlaced(TRUE); |
654 | p->setX(x); | 655 | p->setX(x); |
655 | p->setY(y); | 656 | p->setY(y); |
656 | p->setZ(1); | 657 | p->setZ(1); |
657 | p->show(); | 658 | p->show(); |
658 | num_white--; | 659 | num_white--; |
659 | 660 | ||
660 | if (x == adjusted_answerpegx) | 661 | if (x == adjusted_answerpegx) |
661 | x = adjusted_answerpegx + adjusted_answerpeg_xdiff; | 662 | x = adjusted_answerpegx + adjusted_answerpeg_xdiff; |
662 | else { | 663 | else { |
663 | x = adjusted_answerpegx; | 664 | x = adjusted_answerpegx; |
664 | y += adjusted_answerpeg_ydiff; | 665 | y += adjusted_answerpeg_ydiff; |
665 | } | 666 | } |
666 | } | 667 | } |
667 | /* move to next go */ | 668 | /* move to next go */ |
668 | for(i = 0; i < 4; i++) { | 669 | for(i = 0; i < 4; i++) { |
669 | past_guesses[4*current_go+i] = current_guess[i]; | 670 | past_guesses[4*current_go+i] = current_guess[i]; |
670 | current_guess[i] = 6; | 671 | current_guess[i] = 6; |
671 | } | 672 | } |
672 | 673 | ||
673 | current_go++; | 674 | current_go++; |
674 | if((current_go > 8) || game_over) { | 675 | if((current_go > 8) || game_over) { |
675 | total_games++; | 676 | total_games++; |
676 | if(!game_over) | 677 | if(!game_over) |
677 | total_turns += 10; | 678 | total_turns += 10; |
678 | else | 679 | else |
679 | total_turns += current_go; | 680 | total_turns += current_go; |
680 | 681 | ||
681 | emit scoreChanged(total_turns, total_games); | 682 | emit scoreChanged(total_turns, total_games); |
682 | Peg *p = new Peg(canvas(), 9); | 683 | Peg *p = new Peg(canvas(), 9); |
683 | game_over = TRUE; | 684 | game_over = TRUE; |
684 | p->setPlaced(TRUE); | 685 | p->setPlaced(TRUE); |
685 | p->setX(0); | 686 | p->setX(0); |
686 | p->setY(0); | 687 | p->setY(0); |
687 | p->setZ(0); | 688 | p->setZ(0); |
688 | p->show(); | 689 | p->show(); |
689 | 690 | ||
690 | for (i = 0; i < 4; i++) { | 691 | for (i = 0; i < 4; i++) { |
691 | p = new Peg(canvas(), answer[i], -1); | 692 | p = new Peg(canvas(), answer[i], -1); |
692 | p->setX(adjusted_first_peg_x_diff + (i * adjusted_peg_spacing)); | 693 | p->setX(adjusted_first_peg_x_diff + (i * adjusted_peg_spacing)); |
693 | p->setY(adjusted_first_peg_y_diff); | 694 | p->setY(adjusted_first_peg_y_diff); |
694 | p->setZ(3); | 695 | p->setZ(3); |
695 | p->show(); | 696 | p->show(); |
696 | } | 697 | } |
697 | } else { | 698 | } else { |
698 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); | 699 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); |
699 | } | 700 | } |
700 | canvas()->update(); | 701 | canvas()->update(); |
701 | } | 702 | } |
702 | 703 | ||
703 | void MindBreakerBoard::clear() | 704 | void MindBreakerBoard::clear() |
704 | { | 705 | { |
705 | if(!game_over) { | 706 | if(!game_over) { |
706 | total_games++; | 707 | total_games++; |
707 | total_turns += 10; | 708 | total_turns += 10; |
708 | emit scoreChanged(total_turns, total_games); | 709 | emit scoreChanged(total_turns, total_games); |
709 | } | 710 | } |
710 | int i; | 711 | int i; |
711 | /* reset the game board */ | 712 | /* reset the game board */ |
712 | game_over = FALSE; | 713 | game_over = FALSE; |
713 | /* clear the answer, clear the guess */ | 714 | /* clear the answer, clear the guess */ |
714 | for (i = 0; i < 4; i++) { | 715 | for (i = 0; i < 4; i++) { |
715 | answer[i] = rand() % 6; | 716 | answer[i] = rand() % 6; |
716 | current_guess[i] = 6; | 717 | current_guess[i] = 6; |
717 | } | 718 | } |
718 | current_go = 0; | 719 | current_go = 0; |
719 | 720 | ||
720 | QCanvasItemList list = canvas()->allItems(); | 721 | QCanvasItemList list = canvas()->allItems(); |
721 | QCanvasItemList::Iterator it = list.begin(); | 722 | QCanvasItemList::Iterator it = list.begin(); |
722 | for (; it != list.end(); ++it) { | 723 | for (; it != list.end(); ++it) { |
723 | if (*it == current_highlight) | 724 | if (*it == current_highlight) |
724 | continue; | 725 | continue; |
725 | if (*it) | 726 | if (*it) |
726 | delete *it; | 727 | delete *it; |
727 | } | 728 | } |
728 | 729 | ||
729 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); | 730 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); |
730 | checkScores(); | 731 | checkScores(); |
731 | drawBackground(); | 732 | drawBackground(); |
732 | canvas()->update(); | 733 | canvas()->update(); |
733 | } | 734 | } |
734 | 735 | ||
735 | void MindBreakerBoard::resetScore() | 736 | void MindBreakerBoard::resetScore() |
736 | { | 737 | { |
737 | /* are u sure */ | 738 | /* are u sure */ |
738 | 739 | ||
739 | if (QMessageBox::information(this, tr( "Reset Statistics" ), | 740 | if (QMessageBox::information(this, tr( "Reset Statistics" ), |
740 | tr( "Reset the win ratio?" ), | 741 | tr( "Reset the win ratio?" ), |
741 | tr( "OK" ), tr( "Cancel" ) ) == 0) { | 742 | tr( "OK" ), tr( "Cancel" ) ) == 0) { |
742 | total_turns = 0; | 743 | total_turns = 0; |
743 | total_games = 0; | 744 | total_games = 0; |
744 | Peg::eggLevel = 0; | 745 | Peg::eggLevel = 0; |
745 | drawBackground(); | 746 | drawBackground(); |
746 | canvas()->update(); | 747 | canvas()->update(); |
747 | emit scoreChanged(total_turns, total_games); | 748 | emit scoreChanged(total_turns, total_games); |
748 | } | 749 | } |
749 | } | 750 | } |
750 | 751 | ||
751 | /* EVENTS */ | 752 | /* EVENTS */ |
752 | 753 | ||
753 | void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e) | 754 | void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e) |
754 | { | 755 | { |
755 | if (game_over) { | 756 | if (game_over) { |
756 | null_press = TRUE; | 757 | null_press = TRUE; |
757 | null_point = e->pos(); | 758 | null_point = e->pos(); |
758 | moving = 0; | 759 | moving = 0; |
759 | return; | 760 | return; |
760 | } | 761 | } |
761 | 762 | ||
762 | copy_press = FALSE; | 763 | copy_press = FALSE; |
763 | null_press = FALSE; | 764 | null_press = FALSE; |
764 | /* ok, first work out if it is one of the bins that | 765 | /* ok, first work out if it is one of the bins that |
765 | got clicked */ | 766 | got clicked */ |
766 | if (e->x() > adjusted_panel_width) { | 767 | if (e->x() > adjusted_panel_width) { |
767 | /* its a bin, but which bin */ | 768 | /* its a bin, but which bin */ |
768 | int bin = (e->y() + 2) / (adjusted_board_height / 6); | 769 | int bin = (e->y() + 2) / (adjusted_board_height / 6); |
769 | if (bin > 5) | 770 | if (bin > 5) |
770 | return; // missed everything | 771 | return; // missed everything |
771 | 772 | ||
772 | /* make new peg... set it moving */ | 773 | /* make new peg... set it moving */ |
773 | moving_pos = e->pos(); | 774 | moving_pos = e->pos(); |
774 | moving = new Peg(canvas(), bin, current_go); | 775 | moving = new Peg(canvas(), bin, current_go); |
775 | moving->setX(e->x() - (adjusted_peg_size >> 1)); | 776 | moving->setX(e->x() - (adjusted_peg_size >> 1)); |
776 | moving->setY(e->y() - (adjusted_peg_size >> 1)); | 777 | moving->setY(e->y() - (adjusted_peg_size >> 1)); |
777 | moving->setZ(5); | 778 | moving->setZ(5); |
778 | moving->show(); | 779 | moving->show(); |
779 | canvas()->update(); | 780 | canvas()->update(); |
780 | return; | 781 | return; |
781 | } | 782 | } |
782 | 783 | ||
783 | QCanvasItemList l = canvas()->collisions(e->pos()); | 784 | QCanvasItemList l = canvas()->collisions(e->pos()); |
784 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 785 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
785 | if ( (*it)->rtti() == pegRTTI ) { | 786 | if ( (*it)->rtti() == pegRTTI ) { |
786 | Peg *item = (Peg *)(*it); | 787 | Peg *item = (Peg *)(*it); |
787 | if (!item->hit(e->pos())) | 788 | if (!item->hit(e->pos())) |
788 | continue; | 789 | continue; |
789 | if (item->type() > 5) { | 790 | if (item->type() > 5) { |
790 | null_press = TRUE; | 791 | null_press = TRUE; |
791 | null_point = e->pos(); | 792 | null_point = e->pos(); |
792 | continue; /* not a color peg */ | 793 | continue; /* not a color peg */ |
793 | } | 794 | } |
794 | if (item->placed()) { | 795 | if (item->placed()) { |
795 | /* copy */ | 796 | /* copy */ |
796 | if(item->pegGo() == -1) | 797 | if(item->pegGo() == -1) |
797 | return; | 798 | return; |
798 | if(item->pegGo() == current_go) { | 799 | if(item->pegGo() == current_go) { |
799 | copy_press = TRUE; | 800 | copy_press = TRUE; |
800 | copy_peg = item; | 801 | copy_peg = item; |
801 | } | 802 | } |
802 | moving = new Peg(canvas(), | 803 | moving = new Peg(canvas(), |
803 | item->type(), current_go); | 804 | item->type(), current_go); |
804 | moving->setX(e->x() - (adjusted_peg_size >> 1)); | 805 | moving->setX(e->x() - (adjusted_peg_size >> 1)); |
805 | moving->setY(e->y() - (adjusted_peg_size >> 1)); | 806 | moving->setY(e->y() - (adjusted_peg_size >> 1)); |
806 | moving->setZ(5); | 807 | moving->setZ(5); |
807 | moving->show(); | 808 | moving->show(); |
808 | moving_pos = QPoint(e->x(), e->y()); | 809 | moving_pos = QPoint(e->x(), e->y()); |
809 | canvas()->update(); | 810 | canvas()->update(); |
810 | return; | 811 | return; |
811 | } | 812 | } |
812 | moving = (Peg *)*it; | 813 | moving = (Peg *)*it; |
813 | moving_pos = e->pos(); | 814 | moving_pos = e->pos(); |
814 | canvas()->update(); | 815 | canvas()->update(); |
815 | return; | 816 | return; |
816 | } | 817 | } |
817 | } | 818 | } |
818 | null_press = TRUE; | 819 | null_press = TRUE; |
819 | null_point = e->pos(); | 820 | null_point = e->pos(); |
820 | moving = 0; | 821 | moving = 0; |
821 | } | 822 | } |
822 | 823 | ||
823 | void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e) | 824 | void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e) |
824 | { | 825 | { |
825 | if (moving ) { | 826 | if (moving ) { |
826 | moving->moveBy(e->pos().x() - moving_pos.x(), | 827 | moving->moveBy(e->pos().x() - moving_pos.x(), |
827 | e->pos().y() - moving_pos.y()); | 828 | e->pos().y() - moving_pos.y()); |
828 | moving_pos = e->pos(); | 829 | moving_pos = e->pos(); |
829 | canvas()->update(); | 830 | canvas()->update(); |
830 | return; | 831 | return; |
831 | } | 832 | } |
832 | } | 833 | } |
833 | 834 | ||
834 | void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e) | 835 | void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e) |
835 | { | 836 | { |
836 | /* time to put down the peg */ | 837 | /* time to put down the peg */ |
837 | if(moving) { | 838 | if(moving) { |
838 | if(copy_press) { | 839 | if(copy_press) { |
839 | /* check if collided with original. if so, delete both */ | 840 | /* check if collided with original. if so, delete both */ |
840 | copy_press = FALSE; | 841 | copy_press = FALSE; |
841 | QCanvasItemList l = canvas()->collisions(e->pos()); | 842 | QCanvasItemList l = canvas()->collisions(e->pos()); |
842 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 843 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
843 | if (*it == copy_peg) | 844 | if (*it == copy_peg) |
844 | copy_press = TRUE; | 845 | copy_press = TRUE; |
845 | } | 846 | } |
846 | if (copy_press) { | 847 | if (copy_press) { |
847 | current_guess[copy_peg->pegPos()] = 6; | 848 | current_guess[copy_peg->pegPos()] = 6; |
848 | delete copy_peg; | 849 | delete copy_peg; |
849 | delete moving; | 850 | delete moving; |
850 | copy_press = FALSE; | 851 | copy_press = FALSE; |
851 | moving = 0; | 852 | moving = 0; |
852 | copy_peg = 0; | 853 | copy_peg = 0; |
853 | canvas()->update(); | 854 | canvas()->update(); |
854 | return; | 855 | return; |
855 | } | 856 | } |
856 | } | 857 | } |
857 | 858 | ||
858 | /* first work out if in y */ | 859 | /* first work out if in y */ |
859 | if (e->y() > (adjusted_board_height - (current_go * adjusted_panel_height))) { | 860 | if (e->y() > (adjusted_board_height - (current_go * adjusted_panel_height))) { |
860 | delete moving; | 861 | delete moving; |
861 | moving = 0; | 862 | moving = 0; |
862 | canvas()->update(); | 863 | canvas()->update(); |
863 | return; | 864 | return; |
864 | } | 865 | } |
865 | if (e->y() < (adjusted_board_height - ((current_go + 1) * adjusted_panel_height))) { | 866 | if (e->y() < (adjusted_board_height - ((current_go + 1) * adjusted_panel_height))) { |
866 | delete moving; | 867 | delete moving; |
867 | moving = 0; | 868 | moving = 0; |
868 | canvas()->update(); | 869 | canvas()->update(); |
869 | return; | 870 | return; |
870 | } | 871 | } |
871 | /* ok, a valid go, but which peg */ | 872 | /* ok, a valid go, but which peg */ |
872 | int x_bar = adjusted_first_peg_x_diff - (adjusted_peg_size >> 1); | 873 | int x_bar = adjusted_first_peg_x_diff - (adjusted_peg_size >> 1); |
873 | x_bar += adjusted_peg_spacing; | 874 | x_bar += adjusted_peg_spacing; |
874 | int pos = 0; | 875 | int pos = 0; |
875 | if (e->x() > x_bar) | 876 | if (e->x() > x_bar) |
876 | pos = 1; | 877 | pos = 1; |
877 | x_bar += adjusted_peg_spacing; | 878 | x_bar += adjusted_peg_spacing; |
878 | if (e->x() > x_bar) | 879 | if (e->x() > x_bar) |
879 | pos = 2; | 880 | pos = 2; |
880 | x_bar += adjusted_peg_spacing; | 881 | x_bar += adjusted_peg_spacing; |
881 | if (e->x() > x_bar) | 882 | if (e->x() > x_bar) |
882 | pos = 3; | 883 | pos = 3; |
883 | x_bar += adjusted_peg_spacing; | 884 | x_bar += adjusted_peg_spacing; |
884 | 885 | ||
885 | if (e->x() > x_bar) { | 886 | if (e->x() > x_bar) { |
886 | /* invalid x */ | 887 | /* invalid x */ |
887 | delete moving; | 888 | delete moving; |
888 | moving = 0; | 889 | moving = 0; |
889 | canvas()->update(); | 890 | canvas()->update(); |
890 | return; | 891 | return; |
891 | } | 892 | } |
892 | 893 | ||
893 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); | 894 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); |
894 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) | 895 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) |
895 | + adjusted_first_peg_y_diff; | 896 | + adjusted_first_peg_y_diff; |
896 | moving->setPegPos(pos); | 897 | moving->setPegPos(pos); |
897 | moving->setX(x); | 898 | moving->setX(x); |
898 | moving->setY(y); | 899 | moving->setY(y); |
899 | moving->setZ(2); | 900 | moving->setZ(2); |
900 | 901 | ||
901 | /* remove all other pegs from this position */ | 902 | /* remove all other pegs from this position */ |
902 | QCanvasItemList l = canvas()->collisions(QPoint(x,y)); | 903 | QCanvasItemList l = canvas()->collisions(QPoint(x,y)); |
903 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 904 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
904 | if ( (*it)->rtti() == pegRTTI ) { | 905 | if ( (*it)->rtti() == pegRTTI ) { |
905 | Peg *item = (Peg *)(*it); | 906 | Peg *item = (Peg *)(*it); |
906 | if ((item != moving) && (item != current_highlight)) | 907 | if ((item != moving) && (item != current_highlight)) |
907 | delete item; | 908 | delete item; |
908 | } | 909 | } |
909 | } | 910 | } |
910 | current_guess[pos] = ((Peg *)moving)->type(); | 911 | current_guess[pos] = ((Peg *)moving)->type(); |
911 | 912 | ||
912 | ((Peg *)moving)->setPlaced(true); | 913 | ((Peg *)moving)->setPlaced(true); |
913 | canvas()->update(); | 914 | canvas()->update(); |
914 | return; | 915 | return; |
915 | } | 916 | } |
916 | moving = 0; | 917 | moving = 0; |
917 | null_point -= e->pos(); | 918 | null_point -= e->pos(); |
918 | if(null_point.manhattanLength() < 6) { | 919 | if(null_point.manhattanLength() < 6) { |
919 | if (game_over) | 920 | if (game_over) |
920 | clear(); | 921 | clear(); |
921 | else | 922 | else |
922 | checkGuess(); | 923 | checkGuess(); |
923 | } | 924 | } |
924 | } | 925 | } |
925 | 926 | ||
926 | void MindBreakerBoard::resizeEvent(QResizeEvent *e) | 927 | void MindBreakerBoard::resizeEvent(QResizeEvent *e) |
927 | { | 928 | { |
928 | QCanvasView::resizeEvent(e); | 929 | QCanvasView::resizeEvent(e); |
929 | fixSize(); | 930 | fixSize(); |
930 | } | 931 | } |
931 | 932 | ||
932 | 933 | ||
933 | /* Easter egg function... beat the clock */ | 934 | /* Easter egg function... beat the clock */ |
934 | void MindBreakerBoard::checkScores() | 935 | void MindBreakerBoard::checkScores() |
935 | { | 936 | { |
936 | double games = total_games; | 937 | double games = total_games; |
937 | double turns = total_turns; | 938 | double turns = total_turns; |
938 | double g = games / 10.0; | 939 | double g = games / 10.0; |
939 | Peg::eggLevel = 0; | 940 | Peg::eggLevel = 0; |
940 | 941 | ||
941 | double break_even = 5.0; | 942 | double break_even = 5.0; |
942 | if (g < 1.0) | 943 | if (g < 1.0) |
943 | return; | 944 | return; |
944 | double avg = turns / games; | 945 | double avg = turns / games; |
945 | g--; | 946 | g--; |
946 | while (break_even >= 0.0) { | 947 | while (break_even >= 0.0) { |
947 | if (avg >= (break_even + g)) | 948 | if (avg >= (break_even + g)) |
948 | return; | 949 | return; |
949 | // score a peg. | 950 | // score a peg. |
950 | break_even -= 1.0; | 951 | break_even -= 1.0; |
951 | Peg::eggLevel = int(5.0 - break_even); | 952 | Peg::eggLevel = int(5.0 - break_even); |
952 | } | 953 | } |
953 | } | 954 | } |
diff --git a/noncore/games/mindbreaker/opie-mindbreaker.control b/noncore/games/mindbreaker/opie-mindbreaker.control index 5b342da..d3826fd 100644 --- a/noncore/games/mindbreaker/opie-mindbreaker.control +++ b/noncore/games/mindbreaker/opie-mindbreaker.control | |||
@@ -1,10 +1,10 @@ | |||
1 | Package: opie-mindbreaker | 1 | Package: opie-mindbreaker |
2 | Files: plugins/application/libmindbreaker.so* bin/mindbreaker apps/Games/mindbreaker.desktop pics/mindbreaker | 2 | Files: plugins/application/libmindbreaker.so* bin/mindbreaker apps/Games/mindbreaker.desktop pics/mindbreaker |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/games | 4 | Section: opie/games |
5 | Maintainer: Martin Imobersteg <imm@gmx.ch> | 5 | Maintainer: Martin Imobersteg <imm@gmx.ch> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Depends: task-opie-minimal | 7 | Depends: task-opie-minimal, libopiecore2 |
8 | Description: Game: crack the coloured code | 8 | Description: Game: crack the coloured code |
9 | A game for the Opie environment. | 9 | A game for the Opie environment. |
10 | Version: $QPE_VERSION$EXTRAVERSION | 10 | Version: $QPE_VERSION$EXTRAVERSION |
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index c14609d..18449ff 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -1,408 +1,409 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "minesweep.h" | 21 | #include "minesweep.h" |
22 | #include "minefield.h" | 22 | #include "minefield.h" |
23 | 23 | ||
24 | #include <opie2/oresource.h> | ||
25 | |||
24 | #include <qtopia/qpeapplication.h> | 26 | #include <qtopia/qpeapplication.h> |
25 | #include <qtopia/resource.h> | ||
26 | #include <qtopia/config.h> | 27 | #include <qtopia/config.h> |
27 | 28 | ||
28 | #include <qtoolbar.h> | 29 | #include <qtoolbar.h> |
29 | #include <qmenubar.h> | 30 | #include <qmenubar.h> |
30 | #include <qpushbutton.h> | 31 | #include <qpushbutton.h> |
31 | #include <qlcdnumber.h> | 32 | #include <qlcdnumber.h> |
32 | #include <qtimer.h> | 33 | #include <qtimer.h> |
33 | #include <qlabel.h> | 34 | #include <qlabel.h> |
34 | 35 | ||
35 | #include <stdlib.h> | 36 | #include <stdlib.h> |
36 | #include <time.h> | 37 | #include <time.h> |
37 | 38 | ||
38 | 39 | ||
39 | 40 | ||
40 | 41 | ||
41 | static const char *pix_new[]={ | 42 | static const char *pix_new[]={ |
42 | "20 20 3 1", | 43 | "20 20 3 1", |
43 | " c None", | 44 | " c None", |
44 | "# c #00FF00", | 45 | "# c #00FF00", |
45 | ". c #000000", | 46 | ". c #000000", |
46 | " ", | 47 | " ", |
47 | " ...... ", | 48 | " ...... ", |
48 | " ..######.. ", | 49 | " ..######.. ", |
49 | " .##########. ", | 50 | " .##########. ", |
50 | " .############. ", | 51 | " .############. ", |
51 | " .##############. ", | 52 | " .##############. ", |
52 | " .##############. ", | 53 | " .##############. ", |
53 | " .################. ", | 54 | " .################. ", |
54 | " .################. ", | 55 | " .################. ", |
55 | " .################. ", | 56 | " .################. ", |
56 | " .################. ", | 57 | " .################. ", |
57 | " .################. ", | 58 | " .################. ", |
58 | " .################. ", | 59 | " .################. ", |
59 | " .##############. ", | 60 | " .##############. ", |
60 | " .##############. ", | 61 | " .##############. ", |
61 | " .############. ", | 62 | " .############. ", |
62 | " .##########. ", | 63 | " .##########. ", |
63 | " ..######.. ", | 64 | " ..######.. ", |
64 | " ...... ", | 65 | " ...... ", |
65 | " "}; | 66 | " "}; |
66 | 67 | ||
67 | 68 | ||
68 | /* XPM */ | 69 | /* XPM */ |
69 | static const char * happy_xpm[] = { | 70 | static const char * happy_xpm[] = { |
70 | "20 20 3 1", | 71 | "20 20 3 1", |
71 | " c None", | 72 | " c None", |
72 | ".c #ffff3f ", | 73 | ".c #ffff3f ", |
73 | "#c #000000", | 74 | "#c #000000", |
74 | " ", | 75 | " ", |
75 | " ###### ", | 76 | " ###### ", |
76 | " ##......## ", | 77 | " ##......## ", |
77 | " #..........# ", | 78 | " #..........# ", |
78 | " #............# ", | 79 | " #............# ", |
79 | " #..............# ", | 80 | " #..............# ", |
80 | " #..............# ", | 81 | " #..............# ", |
81 | " #....##....##....# ", | 82 | " #....##....##....# ", |
82 | " #....##....##....# ", | 83 | " #....##....##....# ", |
83 | " #................# ", | 84 | " #................# ", |
84 | " #................# ", | 85 | " #................# ", |
85 | " #................# ", | 86 | " #................# ", |
86 | " #...#........#...# ", | 87 | " #...#........#...# ", |
87 | " #.##........##.# ", | 88 | " #.##........##.# ", |
88 | " #...########...# ", | 89 | " #...########...# ", |
89 | " #...######...# ", | 90 | " #...######...# ", |
90 | " #..........# ", | 91 | " #..........# ", |
91 | " ##......## ", | 92 | " ##......## ", |
92 | " ###### ", | 93 | " ###### ", |
93 | " "}; | 94 | " "}; |
94 | 95 | ||
95 | 96 | ||
96 | /* XPM */ | 97 | /* XPM */ |
97 | static const char * worried_xpm[] = { | 98 | static const char * worried_xpm[] = { |
98 | "20 20 3 1", | 99 | "20 20 3 1", |
99 | " c None", | 100 | " c None", |
100 | ".c #ffff3f", | 101 | ".c #ffff3f", |
101 | "#c #000000", | 102 | "#c #000000", |
102 | " ", | 103 | " ", |
103 | " ###### ", | 104 | " ###### ", |
104 | " ##......## ", | 105 | " ##......## ", |
105 | " #..........# ", | 106 | " #..........# ", |
106 | " #............# ", | 107 | " #............# ", |
107 | " #..............# ", | 108 | " #..............# ", |
108 | " #..............# ", | 109 | " #..............# ", |
109 | " #....##....##....# ", | 110 | " #....##....##....# ", |
110 | " #....##....##....# ", | 111 | " #....##....##....# ", |
111 | " #................# ", | 112 | " #................# ", |
112 | " #................# ", | 113 | " #................# ", |
113 | " #................# ", | 114 | " #................# ", |
114 | " #................# ", | 115 | " #................# ", |
115 | " #....######....# ", | 116 | " #....######....# ", |
116 | " #..............# ", | 117 | " #..............# ", |
117 | " #............# ", | 118 | " #............# ", |
118 | " #..........# ", | 119 | " #..........# ", |
119 | " ##......## ", | 120 | " ##......## ", |
120 | " ###### ", | 121 | " ###### ", |
121 | " "}; | 122 | " "}; |
122 | 123 | ||
123 | 124 | ||
124 | /* XPM */ | 125 | /* XPM */ |
125 | static const char * dead_xpm[] = { | 126 | static const char * dead_xpm[] = { |
126 | "20 20 3 1", | 127 | "20 20 3 1", |
127 | " c None", | 128 | " c None", |
128 | ".c #ffff3f", | 129 | ".c #ffff3f", |
129 | "#c #000000", | 130 | "#c #000000", |
130 | " ", | 131 | " ", |
131 | " ###### ", | 132 | " ###### ", |
132 | " ##......## ", | 133 | " ##......## ", |
133 | " #..........# ", | 134 | " #..........# ", |
134 | " #............# ", | 135 | " #............# ", |
135 | " #..............# ", | 136 | " #..............# ", |
136 | " #..#.#...#.#...# ", | 137 | " #..#.#...#.#...# ", |
137 | " #....#.....#.....# ", | 138 | " #....#.....#.....# ", |
138 | " #...#.#...#.#....# ", | 139 | " #...#.#...#.#....# ", |
139 | " #................# ", | 140 | " #................# ", |
140 | " #................# ", | 141 | " #................# ", |
141 | " #................# ", | 142 | " #................# ", |
142 | " #......####......# ", | 143 | " #......####......# ", |
143 | " #....# #....# ", | 144 | " #....# #....# ", |
144 | " #...#......#...# ", | 145 | " #...#......#...# ", |
145 | " #............# ", | 146 | " #............# ", |
146 | " #..........# ", | 147 | " #..........# ", |
147 | " ##......## ", | 148 | " ##......## ", |
148 | " ###### ", | 149 | " ###### ", |
149 | " "}; | 150 | " "}; |
150 | 151 | ||
151 | 152 | ||
152 | class ResultIndicator : private QLabel | 153 | class ResultIndicator : private QLabel |
153 | { | 154 | { |
154 | public: | 155 | public: |
155 | static void showResult( QWidget *ref, bool won ); | 156 | static void showResult( QWidget *ref, bool won ); |
156 | private: | 157 | private: |
157 | ResultIndicator( QWidget *parent, const char *name, WFlags f) | 158 | ResultIndicator( QWidget *parent, const char *name, WFlags f) |
158 | :QLabel( parent, name, f ) {} | 159 | :QLabel( parent, name, f ) {} |
159 | 160 | ||
160 | void timerEvent( QTimerEvent *); | 161 | void timerEvent( QTimerEvent *); |
161 | void center(); | 162 | void center(); |
162 | bool twoStage; | 163 | bool twoStage; |
163 | int timerId; | 164 | int timerId; |
164 | }; | 165 | }; |
165 | 166 | ||
166 | void ResultIndicator::showResult( QWidget *ref, bool won ) | 167 | void ResultIndicator::showResult( QWidget *ref, bool won ) |
167 | { | 168 | { |
168 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); | 169 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); |
169 | 170 | ||
170 | r->setAlignment( AlignCenter ); | 171 | r->setAlignment( AlignCenter ); |
171 | r->setFrameStyle( Sunken|StyledPanel ); | 172 | r->setFrameStyle( Sunken|StyledPanel ); |
172 | if ( won ) { | 173 | if ( won ) { |
173 | r->setText( MineSweep::tr("You won!") ); | 174 | r->setText( MineSweep::tr("You won!") ); |
174 | r->center(); | 175 | r->center(); |
175 | r->show(); | 176 | r->show(); |
176 | r->twoStage = FALSE; | 177 | r->twoStage = FALSE; |
177 | r->timerId = r->startTimer(1500); | 178 | r->timerId = r->startTimer(1500); |
178 | } else { | 179 | } else { |
179 | QPalette p( red ); | 180 | QPalette p( red ); |
180 | r->setPalette( p ); | 181 | r->setPalette( p ); |
181 | r->setText( MineSweep::tr("You exploded!") ); | 182 | r->setText( MineSweep::tr("You exploded!") ); |
182 | r->resize( ref->size() ); | 183 | r->resize( ref->size() ); |
183 | r->move( ref->mapToGlobal(QPoint(0,0)) ); | 184 | r->move( ref->mapToGlobal(QPoint(0,0)) ); |
184 | r->show(); | 185 | r->show(); |
185 | r->twoStage = TRUE; | 186 | r->twoStage = TRUE; |
186 | r->timerId =r->startTimer(200); | 187 | r->timerId =r->startTimer(200); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | 190 | ||
190 | void ResultIndicator::center() | 191 | void ResultIndicator::center() |
191 | { | 192 | { |
192 | QWidget *w = parentWidget(); | 193 | QWidget *w = parentWidget(); |
193 | 194 | ||
194 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | 195 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); |
195 | QSize s = sizeHint()*3; | 196 | QSize s = sizeHint()*3; |
196 | s.setWidth( QMIN(s.width(), w->width()) ); | 197 | s.setWidth( QMIN(s.width(), w->width()) ); |
197 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, | 198 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, |
198 | pp.y() + w->height()/ 2 - s.height()/2 ); | 199 | pp.y() + w->height()/ 2 - s.height()/2 ); |
199 | 200 | ||
200 | setGeometry( QRect(pp, s) ); | 201 | setGeometry( QRect(pp, s) ); |
201 | 202 | ||
202 | } | 203 | } |
203 | 204 | ||
204 | void ResultIndicator::timerEvent( QTimerEvent *te ) | 205 | void ResultIndicator::timerEvent( QTimerEvent *te ) |
205 | { | 206 | { |
206 | if ( te->timerId() != timerId ) | 207 | if ( te->timerId() != timerId ) |
207 | return; | 208 | return; |
208 | killTimer( timerId ); | 209 | killTimer( timerId ); |
209 | if ( twoStage ) { | 210 | if ( twoStage ) { |
210 | center(); | 211 | center(); |
211 | twoStage = FALSE; | 212 | twoStage = FALSE; |
212 | timerId = startTimer( 1000 ); | 213 | timerId = startTimer( 1000 ); |
213 | } else { | 214 | } else { |
214 | delete this; | 215 | delete this; |
215 | } | 216 | } |
216 | } | 217 | } |
217 | 218 | ||
218 | 219 | ||
219 | class MineFrame : public QFrame | 220 | class MineFrame : public QFrame |
220 | { | 221 | { |
221 | public: | 222 | public: |
222 | MineFrame( QWidget *parent, const char *name = 0 ) | 223 | MineFrame( QWidget *parent, const char *name = 0 ) |
223 | :QFrame( parent, name ), field(0) {} | 224 | :QFrame( parent, name ), field(0) {} |
224 | void setField( MineField *f ) { | 225 | void setField( MineField *f ) { |
225 | field = f; | 226 | field = f; |
226 | setMinimumSize( field->sizeHint() ); | 227 | setMinimumSize( field->sizeHint() ); |
227 | } | 228 | } |
228 | protected: | 229 | protected: |
229 | void resizeEvent( QResizeEvent *e ) { | 230 | void resizeEvent( QResizeEvent *e ) { |
230 | field->setAvailableRect( contentsRect()); | 231 | field->setAvailableRect( contentsRect()); |
231 | QFrame::resizeEvent(e); | 232 | QFrame::resizeEvent(e); |
232 | } | 233 | } |
233 | private: | 234 | private: |
234 | MineField *field; | 235 | MineField *field; |
235 | }; | 236 | }; |
236 | 237 | ||
237 | 238 | ||
238 | 239 | ||
239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | 240 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) |
240 | : QMainWindow( parent, name, f ) | 241 | : QMainWindow( parent, name, f ) |
241 | { | 242 | { |
242 | srand(::time(0)); | 243 | srand(::time(0)); |
243 | setCaption( tr("Mine Sweep") ); | 244 | setCaption( tr("Mine Sweep") ); |
244 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | 245 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
245 | setIcon( Resource::loadPixmap( "minesweep/MineSweep" ) ); | 246 | setIcon( Opie::Core::OResource::loadPixmap( "minesweep/MineSweep" ) ); |
246 | 247 | ||
247 | QToolBar *toolBar = new QToolBar( this ); | 248 | QToolBar *toolBar = new QToolBar( this ); |
248 | toolBar->setHorizontalStretchable( TRUE ); | 249 | toolBar->setHorizontalStretchable( TRUE ); |
249 | 250 | ||
250 | QMenuBar *menuBar = new QMenuBar( toolBar ); | 251 | QMenuBar *menuBar = new QMenuBar( toolBar ); |
251 | 252 | ||
252 | QPopupMenu *gameMenu = new QPopupMenu( this ); | 253 | QPopupMenu *gameMenu = new QPopupMenu( this ); |
253 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 254 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
254 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 255 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
255 | 256 | ||
256 | if (qApp->desktop()->width() >= 240) { | 257 | if (qApp->desktop()->width() >= 240) { |
257 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 258 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); |
258 | } | 259 | } |
259 | 260 | ||
260 | menuBar->insertItem( tr("Game"), gameMenu ); | 261 | menuBar->insertItem( tr("Game"), gameMenu ); |
261 | 262 | ||
262 | guessLCD = new QLCDNumber( toolBar ); | 263 | guessLCD = new QLCDNumber( toolBar ); |
263 | toolBar->setStretchableWidget( guessLCD ); | 264 | toolBar->setStretchableWidget( guessLCD ); |
264 | 265 | ||
265 | QPalette lcdPal( red ); | 266 | QPalette lcdPal( red ); |
266 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); | 267 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); |
267 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); | 268 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); |
268 | 269 | ||
269 | // guessLCD->setPalette( lcdPal ); | 270 | // guessLCD->setPalette( lcdPal ); |
270 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); | 271 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); |
271 | guessLCD->setFrameStyle( QFrame::NoFrame ); | 272 | guessLCD->setFrameStyle( QFrame::NoFrame ); |
272 | guessLCD->setNumDigits( 2 ); | 273 | guessLCD->setNumDigits( 2 ); |
273 | guessLCD->setBackgroundMode( PaletteButton ); | 274 | guessLCD->setBackgroundMode( PaletteButton ); |
274 | newGameButton = new QPushButton( toolBar ); | 275 | newGameButton = new QPushButton( toolBar ); |
275 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 276 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
276 | newGameButton->setFocusPolicy(QWidget::NoFocus); | 277 | newGameButton->setFocusPolicy(QWidget::NoFocus); |
277 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); | 278 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); |
278 | 279 | ||
279 | timeLCD = new QLCDNumber( toolBar ); | 280 | timeLCD = new QLCDNumber( toolBar ); |
280 | // timeLCD->setPalette( lcdPal ); | 281 | // timeLCD->setPalette( lcdPal ); |
281 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); | 282 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); |
282 | timeLCD->setFrameStyle( QFrame::NoFrame ); | 283 | timeLCD->setFrameStyle( QFrame::NoFrame ); |
283 | timeLCD->setNumDigits( 5 ); // "mm:ss" | 284 | timeLCD->setNumDigits( 5 ); // "mm:ss" |
284 | timeLCD->setBackgroundMode( PaletteButton ); | 285 | timeLCD->setBackgroundMode( PaletteButton ); |
285 | 286 | ||
286 | setToolBarsMovable ( FALSE ); | 287 | setToolBarsMovable ( FALSE ); |
287 | 288 | ||
288 | addToolBar( toolBar ); | 289 | addToolBar( toolBar ); |
289 | 290 | ||
290 | MineFrame *mainframe = new MineFrame( this ); | 291 | MineFrame *mainframe = new MineFrame( this ); |
291 | mainframe->setFrameShape( QFrame::Box ); | 292 | mainframe->setFrameShape( QFrame::Box ); |
292 | mainframe->setFrameShadow( QFrame::Raised ); | 293 | mainframe->setFrameShadow( QFrame::Raised ); |
293 | 294 | ||
294 | mainframe->setLineWidth(2); | 295 | mainframe->setLineWidth(2); |
295 | 296 | ||
296 | field = new MineField( mainframe ); | 297 | field = new MineField( mainframe ); |
297 | mainframe->setField( field ); | 298 | mainframe->setField( field ); |
298 | QFont fnt = field->font(); | 299 | QFont fnt = field->font(); |
299 | fnt.setBold( TRUE ); | 300 | fnt.setBold( TRUE ); |
300 | field->setFont( QFont( fnt ) ); | 301 | field->setFont( QFont( fnt ) ); |
301 | field->setFocus(); | 302 | field->setFocus(); |
302 | setCentralWidget( mainframe ); | 303 | setCentralWidget( mainframe ); |
303 | 304 | ||
304 | connect( field, SIGNAL( gameOver(bool) ), this, SLOT( gameOver(bool) ) ); | 305 | connect( field, SIGNAL( gameOver(bool) ), this, SLOT( gameOver(bool) ) ); |
305 | connect( field, SIGNAL( mineCount(int) ), this, SLOT( setCounter(int) ) ); | 306 | connect( field, SIGNAL( mineCount(int) ), this, SLOT( setCounter(int) ) ); |
306 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 307 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
307 | 308 | ||
308 | timer = new QTimer( this ); | 309 | timer = new QTimer( this ); |
309 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 310 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
310 | 311 | ||
311 | readConfig(); | 312 | readConfig(); |
312 | } | 313 | } |
313 | 314 | ||
314 | MineSweep::~MineSweep() | 315 | MineSweep::~MineSweep() |
315 | { | 316 | { |
316 | writeConfig(); | 317 | writeConfig(); |
317 | } | 318 | } |
318 | 319 | ||
319 | void MineSweep::gameOver( bool won ) | 320 | void MineSweep::gameOver( bool won ) |
320 | { | 321 | { |
321 | field->showMines(); | 322 | field->showMines(); |
322 | if ( won ) { | 323 | if ( won ) { |
323 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); | 324 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); |
324 | } else { | 325 | } else { |
325 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); | 326 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); |
326 | } | 327 | } |
327 | ResultIndicator::showResult( this, won ); | 328 | ResultIndicator::showResult( this, won ); |
328 | timer->stop(); | 329 | timer->stop(); |
329 | } | 330 | } |
330 | 331 | ||
331 | void MineSweep::newGame() | 332 | void MineSweep::newGame() |
332 | { | 333 | { |
333 | newGame(field->level()); | 334 | newGame(field->level()); |
334 | } | 335 | } |
335 | 336 | ||
336 | void MineSweep::newGame(int level) | 337 | void MineSweep::newGame(int level) |
337 | { | 338 | { |
338 | timeLCD->display( "0:00" ); | 339 | timeLCD->display( "0:00" ); |
339 | field->setup( level ); | 340 | field->setup( level ); |
340 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 341 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
341 | timer->stop(); | 342 | timer->stop(); |
342 | } | 343 | } |
343 | 344 | ||
344 | void MineSweep::startPlaying() | 345 | void MineSweep::startPlaying() |
345 | { | 346 | { |
346 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); | 347 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); |
347 | starttime = QDateTime::currentDateTime(); | 348 | starttime = QDateTime::currentDateTime(); |
348 | timer->start( 1000 ); | 349 | timer->start( 1000 ); |
349 | } | 350 | } |
350 | 351 | ||
351 | void MineSweep::beginner() | 352 | void MineSweep::beginner() |
352 | { | 353 | { |
353 | newGame(1); | 354 | newGame(1); |
354 | } | 355 | } |
355 | 356 | ||
356 | void MineSweep::advanced() | 357 | void MineSweep::advanced() |
357 | { | 358 | { |
358 | newGame(2); | 359 | newGame(2); |
359 | } | 360 | } |
360 | 361 | ||
361 | void MineSweep::expert() | 362 | void MineSweep::expert() |
362 | { | 363 | { |
363 | newGame(3); | 364 | newGame(3); |
364 | } | 365 | } |
365 | 366 | ||
366 | void MineSweep::setCounter( int c ) | 367 | void MineSweep::setCounter( int c ) |
367 | { | 368 | { |
368 | if ( !guessLCD ) | 369 | if ( !guessLCD ) |
369 | return; | 370 | return; |
370 | 371 | ||
371 | guessLCD->display( c ); | 372 | guessLCD->display( c ); |
372 | } | 373 | } |
373 | 374 | ||
374 | void MineSweep::updateTime() | 375 | void MineSweep::updateTime() |
375 | { | 376 | { |
376 | if ( !timeLCD ) | 377 | if ( !timeLCD ) |
377 | return; | 378 | return; |
378 | 379 | ||
379 | int s = starttime.secsTo(QDateTime::currentDateTime()); | 380 | int s = starttime.secsTo(QDateTime::currentDateTime()); |
380 | if ( s/60 > 99 ) | 381 | if ( s/60 > 99 ) |
381 | timeLCD->display( "-----" ); | 382 | timeLCD->display( "-----" ); |
382 | else | 383 | else |
383 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); | 384 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); |
384 | } | 385 | } |
385 | 386 | ||
386 | void MineSweep::writeConfig() const | 387 | void MineSweep::writeConfig() const |
387 | { | 388 | { |
388 | Config cfg("MineSweep"); | 389 | Config cfg("MineSweep"); |
389 | cfg.setGroup("Panel"); | 390 | cfg.setGroup("Panel"); |
390 | cfg.writeEntry("Time", | 391 | cfg.writeEntry("Time", |
391 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); | 392 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); |
392 | field->writeConfig(cfg); | 393 | field->writeConfig(cfg); |
393 | } | 394 | } |
394 | 395 | ||
395 | void MineSweep::readConfig() | 396 | void MineSweep::readConfig() |
396 | { | 397 | { |
397 | Config cfg("MineSweep"); | 398 | Config cfg("MineSweep"); |
398 | field->readConfig(cfg); | 399 | field->readConfig(cfg); |
399 | cfg.setGroup("Panel"); | 400 | cfg.setGroup("Panel"); |
400 | int s = cfg.readNumEntry("Time",-1); | 401 | int s = cfg.readNumEntry("Time",-1); |
401 | if ( s<0 ) { | 402 | if ( s<0 ) { |
402 | newGame(); | 403 | newGame(); |
403 | } else { | 404 | } else { |
404 | startPlaying(); | 405 | startPlaying(); |
405 | starttime = QDateTime::currentDateTime().addSecs(-s); | 406 | starttime = QDateTime::currentDateTime().addSecs(-s); |
406 | updateTime(); | 407 | updateTime(); |
407 | } | 408 | } |
408 | } | 409 | } |
diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp index 5f3c79d..f232536 100644 --- a/noncore/games/parashoot/base.cpp +++ b/noncore/games/parashoot/base.cpp | |||
@@ -1,75 +1,74 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "codes.h" | 20 | #include "codes.h" |
21 | #include "base.h" | 21 | #include "base.h" |
22 | 22 | ||
23 | #include <qtopia/resource.h> | 23 | #include <opie2/oresource.h> |
24 | |||
25 | 24 | ||
26 | int damage; | 25 | int damage; |
27 | 26 | ||
28 | Base::Base(QCanvas* canvas) : | 27 | Base::Base(QCanvas* canvas) : |
29 | QCanvasSprite(0, canvas), | 28 | QCanvasSprite(0, canvas), |
30 | kaboom("landmine"), | 29 | kaboom("landmine"), |
31 | ohdear("crmble01") | 30 | ohdear("crmble01") |
32 | { | 31 | { |
33 | basearray = new QCanvasPixmapArray(); | 32 | basearray = new QCanvasPixmapArray(); |
34 | QString b0 = Resource::findPixmap("parashoot/b0001"); | 33 | QString b0 = Opie::Core::OResource::findPixmap("parashoot/b0001"); |
35 | b0.replace(QRegExp("0001"),"%1"); | 34 | b0.replace(QRegExp("0001"),"%1"); |
36 | basearray->readPixmaps(b0, 4); | 35 | basearray->readPixmaps(b0, 4); |
37 | setSequence(basearray); | 36 | setSequence(basearray); |
38 | setFrame(0); | 37 | setFrame(0); |
39 | move(2, canvas->height()-50); | 38 | move(2, canvas->height()-50); |
40 | setZ(10); | 39 | setZ(10); |
41 | show(); | 40 | show(); |
42 | damage = 0; | 41 | damage = 0; |
43 | } | 42 | } |
44 | 43 | ||
45 | void Base::damageBase() | 44 | void Base::damageBase() |
46 | { | 45 | { |
47 | damage++; | 46 | damage++; |
48 | 47 | ||
49 | switch(damage) { | 48 | switch(damage) { |
50 | case 1: setFrame(1); ohdear.play(); break; | 49 | case 1: setFrame(1); ohdear.play(); break; |
51 | case 2: setFrame(2); ohdear.play(); break; | 50 | case 2: setFrame(2); ohdear.play(); break; |
52 | case 3: setFrame(3); kaboom.play(); break; | 51 | case 3: setFrame(3); kaboom.play(); break; |
53 | } | 52 | } |
54 | show(); | 53 | show(); |
55 | } | 54 | } |
56 | 55 | ||
57 | bool Base::baseDestroyed() | 56 | bool Base::baseDestroyed() |
58 | { | 57 | { |
59 | return (damage >= 3); | 58 | return (damage >= 3); |
60 | } | 59 | } |
61 | 60 | ||
62 | Base::~Base() | 61 | Base::~Base() |
63 | { | 62 | { |
64 | } | 63 | } |
65 | 64 | ||
66 | int Base::rtti() const | 65 | int Base::rtti() const |
67 | { | 66 | { |
68 | return base_rtti; | 67 | return base_rtti; |
69 | } | 68 | } |
70 | 69 | ||
71 | void | 70 | void |
72 | Base::reposition(void) | 71 | Base::reposition(void) |
73 | { | 72 | { |
74 | move(2, canvas()->height()-50); | 73 | move(2, canvas()->height()-50); |
75 | } | 74 | } |
diff --git a/noncore/games/parashoot/bullet.cpp b/noncore/games/parashoot/bullet.cpp index 584f564..1f02251 100644 --- a/noncore/games/parashoot/bullet.cpp +++ b/noncore/games/parashoot/bullet.cpp | |||
@@ -1,142 +1,143 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "codes.h" | 21 | #include "codes.h" |
22 | #include "bullet.h" | 22 | #include "bullet.h" |
23 | #include "man.h" | 23 | #include "man.h" |
24 | #include "helicopter.h" | 24 | #include "helicopter.h" |
25 | 25 | ||
26 | #include <qpe/resource.h> | 26 | #include <opie2/oresource.h> |
27 | |||
27 | #include <qpe/qmath.h> | 28 | #include <qpe/qmath.h> |
28 | 29 | ||
29 | 30 | ||
30 | int limit; | 31 | int limit; |
31 | int shotcount; | 32 | int shotcount; |
32 | int nobullets; | 33 | int nobullets; |
33 | 34 | ||
34 | Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) : | 35 | Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) : |
35 | QCanvasSprite(0, canvas), | 36 | QCanvasSprite(0, canvas), |
36 | bang("collide01") | 37 | bang("collide01") |
37 | { | 38 | { |
38 | QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Resource::findPixmap("parashoot/bullet")); | 39 | QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Opie::Core::OResource::findPixmap("parashoot/bullet")); |
39 | setSequence(bulletarray); | 40 | setSequence(bulletarray); |
40 | if (nobullets < limit) { | 41 | if (nobullets < limit) { |
41 | nobullets++; | 42 | nobullets++; |
42 | move(cannonx, cannony); | 43 | move(cannonx, cannony); |
43 | dy = 0; | 44 | dy = 0; |
44 | dx = 0; | 45 | dx = 0; |
45 | show(); | 46 | show(); |
46 | setXY(angle); | 47 | setXY(angle); |
47 | setVelocity(-dx, -dy); | 48 | setVelocity(-dx, -dy); |
48 | bang.play(); | 49 | bang.play(); |
49 | } else | 50 | } else |
50 | return; | 51 | return; |
51 | } | 52 | } |
52 | 53 | ||
53 | void Bullet::setXY(double angle) | 54 | void Bullet::setXY(double angle) |
54 | { | 55 | { |
55 | double ang = angle; | 56 | double ang = angle; |
56 | if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) || | 57 | if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) || |
57 | (x() > canvas()->width()) ) | 58 | (x() > canvas()->width()) ) |
58 | delete this; | 59 | delete this; |
59 | else { | 60 | else { |
60 | double radians = 0; | 61 | double radians = 0; |
61 | radians = ang * 3.14159265/180; | 62 | radians = ang * 3.14159265/180; |
62 | dx = (qCos(radians)) *7; | 63 | dx = (qCos(radians)) *7; |
63 | dy = (qSin(radians)) *7; | 64 | dy = (qSin(radians)) *7; |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | void Bullet::setLimit(int amount) | 68 | void Bullet::setLimit(int amount) |
68 | { | 69 | { |
69 | limit = amount; | 70 | limit = amount; |
70 | } | 71 | } |
71 | 72 | ||
72 | void Bullet::setNobullets(int amount) | 73 | void Bullet::setNobullets(int amount) |
73 | { | 74 | { |
74 | nobullets = amount; | 75 | nobullets = amount; |
75 | } | 76 | } |
76 | 77 | ||
77 | void Bullet::checkCollision() | 78 | void Bullet::checkCollision() |
78 | { | 79 | { |
79 | QCanvasItem* item; | 80 | QCanvasItem* item; |
80 | QCanvasItemList l=collisions(FALSE); | 81 | QCanvasItemList l=collisions(FALSE); |
81 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 82 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
82 | item = *it; | 83 | item = *it; |
83 | if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) { | 84 | if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) { |
84 | Man* deadman = (Man*)item; | 85 | Man* deadman = (Man*)item; |
85 | if (deadman->frame() != 5) return; | 86 | if (deadman->frame() != 5) return; |
86 | deadman->done(); | 87 | deadman->done(); |
87 | emit score(10); | 88 | emit score(10); |
88 | setShotCount(shotcount+1); | 89 | setShotCount(shotcount+1); |
89 | setAnimated(false); | 90 | setAnimated(false); |
90 | nobullets--; | 91 | nobullets--; |
91 | delete this; | 92 | delete this; |
92 | return; | 93 | return; |
93 | } | 94 | } |
94 | else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) { | 95 | else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) { |
95 | Helicopter* deadchopper = (Helicopter*) item; | 96 | Helicopter* deadchopper = (Helicopter*) item; |
96 | deadchopper->done(); | 97 | deadchopper->done(); |
97 | emit score(50); | 98 | emit score(50); |
98 | setAnimated(false); | 99 | setAnimated(false); |
99 | nobullets--; | 100 | nobullets--; |
100 | delete this; | 101 | delete this; |
101 | return; | 102 | return; |
102 | } | 103 | } |
103 | } | 104 | } |
104 | //check shot is not out of bounds | 105 | //check shot is not out of bounds |
105 | if ( (y() < 0) || (x() < 0) || | 106 | if ( (y() < 0) || (x() < 0) || |
106 | (y() > canvas()->height()) || | 107 | (y() > canvas()->height()) || |
107 | ( x() > canvas()->width())) { | 108 | ( x() > canvas()->width())) { |
108 | setAnimated(false); | 109 | setAnimated(false); |
109 | nobullets--; | 110 | nobullets--; |
110 | delete this; | 111 | delete this; |
111 | return; | 112 | return; |
112 | } | 113 | } |
113 | } | 114 | } |
114 | 115 | ||
115 | void Bullet::advance(int phase) | 116 | void Bullet::advance(int phase) |
116 | { | 117 | { |
117 | QCanvasSprite::advance(phase); | 118 | QCanvasSprite::advance(phase); |
118 | 119 | ||
119 | if (phase == 0) | 120 | if (phase == 0) |
120 | checkCollision(); | 121 | checkCollision(); |
121 | 122 | ||
122 | } | 123 | } |
123 | 124 | ||
124 | int Bullet::getShotCount() | 125 | int Bullet::getShotCount() |
125 | { | 126 | { |
126 | return shotcount; | 127 | return shotcount; |
127 | } | 128 | } |
128 | 129 | ||
129 | void Bullet::setShotCount(int amount) | 130 | void Bullet::setShotCount(int amount) |
130 | { | 131 | { |
131 | shotcount = amount; | 132 | shotcount = amount; |
132 | } | 133 | } |
133 | 134 | ||
134 | Bullet::~Bullet() | 135 | Bullet::~Bullet() |
135 | { | 136 | { |
136 | 137 | ||
137 | } | 138 | } |
138 | 139 | ||
139 | int Bullet::rtti() const | 140 | int Bullet::rtti() const |
140 | { | 141 | { |
141 | return bullet_rtti; | 142 | return bullet_rtti; |
142 | } | 143 | } |
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp index 330d850..2f4c353 100644 --- a/noncore/games/parashoot/cannon.cpp +++ b/noncore/games/parashoot/cannon.cpp | |||
@@ -1,149 +1,148 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qtopia/resource.h> | 21 | #include <opie2/oresource.h> |
22 | |||
23 | 22 | ||
24 | #include "codes.h" | 23 | #include "codes.h" |
25 | #include "cannon.h" | 24 | #include "cannon.h" |
26 | 25 | ||
27 | Cannon::Cannon(QCanvas* canvas) : | 26 | Cannon::Cannon(QCanvas* canvas) : |
28 | QCanvasSprite(0, canvas) | 27 | QCanvasSprite(0, canvas) |
29 | { | 28 | { |
30 | shotsfired=0; | 29 | shotsfired=0; |
31 | index = 8; | 30 | index = 8; |
32 | cannonx = 0; | 31 | cannonx = 0; |
33 | cannony = 0; | 32 | cannony = 0; |
34 | cannonarray = new QCanvasPixmapArray(); | 33 | cannonarray = new QCanvasPixmapArray(); |
35 | QString c0 = Resource::findPixmap("parashoot/can0001"); | 34 | QString c0 = Opie::Core::OResource::findPixmap("parashoot/can0001"); |
36 | c0.replace(QRegExp("0001"),"%1"); | 35 | c0.replace(QRegExp("0001"),"%1"); |
37 | cannonarray->readPixmaps(c0,17); | 36 | cannonarray->readPixmaps(c0,17); |
38 | setSequence(cannonarray); | 37 | setSequence(cannonarray); |
39 | setFrame(index); | 38 | setFrame(index); |
40 | 39 | ||
41 | reposition(); | 40 | reposition(); |
42 | 41 | ||
43 | movedir = NoDir; | 42 | movedir = NoDir; |
44 | moveDelay = 0; | 43 | moveDelay = 0; |
45 | setAnimated(TRUE); | 44 | setAnimated(TRUE); |
46 | show(); | 45 | show(); |
47 | } | 46 | } |
48 | 47 | ||
49 | void Cannon::advance(int stage) | 48 | void Cannon::advance(int stage) |
50 | { | 49 | { |
51 | if ( stage == 1 && moveDelay-- == 0 ) { | 50 | if ( stage == 1 && moveDelay-- == 0 ) { |
52 | if (movedir == Left) { | 51 | if (movedir == Left) { |
53 | if (index > 0) { | 52 | if (index > 0) { |
54 | setFrame(index-1); | 53 | setFrame(index-1); |
55 | index--; | 54 | index--; |
56 | } | 55 | } |
57 | } | 56 | } |
58 | if (movedir == Right) { | 57 | if (movedir == Right) { |
59 | if (index < 16) { | 58 | if (index < 16) { |
60 | setFrame(index+1); | 59 | setFrame(index+1); |
61 | index++; | 60 | index++; |
62 | } | 61 | } |
63 | } | 62 | } |
64 | moveDelay = 0; | 63 | moveDelay = 0; |
65 | } | 64 | } |
66 | } | 65 | } |
67 | 66 | ||
68 | void Cannon::pointCannon(Direction dir) | 67 | void Cannon::pointCannon(Direction dir) |
69 | { | 68 | { |
70 | movedir = dir; | 69 | movedir = dir; |
71 | moveDelay = 0; | 70 | moveDelay = 0; |
72 | advance(1); | 71 | advance(1); |
73 | moveDelay = 1; | 72 | moveDelay = 1; |
74 | } | 73 | } |
75 | 74 | ||
76 | void Cannon::setCoords() | 75 | void Cannon::setCoords() |
77 | { | 76 | { |
78 | switch(index) { | 77 | switch(index) { |
79 | case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; | 78 | case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; |
80 | case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; | 79 | case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; |
81 | case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; | 80 | case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; |
82 | case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; | 81 | case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; |
83 | case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; | 82 | case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; |
84 | case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; | 83 | case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; |
85 | case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; | 84 | case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; |
86 | case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; | 85 | case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; |
87 | case 8: cannonx = barrelxpos; cannony = barrelypos; break; | 86 | case 8: cannonx = barrelxpos; cannony = barrelypos; break; |
88 | case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; | 87 | case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; |
89 | case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; | 88 | case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; |
90 | case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; | 89 | case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; |
91 | case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; | 90 | case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; |
92 | case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; | 91 | case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; |
93 | case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; | 92 | case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; |
94 | case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; | 93 | case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; |
95 | case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; | 94 | case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; |
96 | } | 95 | } |
97 | } | 96 | } |
98 | 97 | ||
99 | double Cannon::shootAngle() | 98 | double Cannon::shootAngle() |
100 | { | 99 | { |
101 | switch(index) { | 100 | switch(index) { |
102 | case 0: return 30.0; | 101 | case 0: return 30.0; |
103 | case 1: return 37.5; | 102 | case 1: return 37.5; |
104 | case 2: return 45.0; | 103 | case 2: return 45.0; |
105 | case 3: return 52.5; | 104 | case 3: return 52.5; |
106 | case 4: return 60.0; | 105 | case 4: return 60.0; |
107 | case 5: return 67.5; | 106 | case 5: return 67.5; |
108 | case 6: return 75.0; | 107 | case 6: return 75.0; |
109 | case 7: return 82.5; | 108 | case 7: return 82.5; |
110 | case 8: return 90.0; | 109 | case 8: return 90.0; |
111 | case 9: return 97.5; | 110 | case 9: return 97.5; |
112 | case 10: return 105.0; | 111 | case 10: return 105.0; |
113 | case 11: return 112.5; | 112 | case 11: return 112.5; |
114 | case 12: return 120.0; | 113 | case 12: return 120.0; |
115 | case 13: return 127.5; | 114 | case 13: return 127.5; |
116 | case 14: return 135.0; | 115 | case 14: return 135.0; |
117 | case 15: return 142.5; | 116 | case 15: return 142.5; |
118 | case 16: return 150.0; | 117 | case 16: return 150.0; |
119 | } | 118 | } |
120 | return 0; | 119 | return 0; |
121 | } | 120 | } |
122 | 121 | ||
123 | void Cannon::shoot() | 122 | void Cannon::shoot() |
124 | { | 123 | { |
125 | setCoords(); | 124 | setCoords(); |
126 | Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); | 125 | Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); |
127 | connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); | 126 | connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); |
128 | shotsfired++; | 127 | shotsfired++; |
129 | } | 128 | } |
130 | 129 | ||
131 | Cannon::~Cannon() | 130 | Cannon::~Cannon() |
132 | { | 131 | { |
133 | } | 132 | } |
134 | 133 | ||
135 | int Cannon::rtti() const | 134 | int Cannon::rtti() const |
136 | { | 135 | { |
137 | return cannon_rtti; | 136 | return cannon_rtti; |
138 | } | 137 | } |
139 | 138 | ||
140 | void Cannon::reposition(void) | 139 | void Cannon::reposition(void) |
141 | { | 140 | { |
142 | move(canvas()->width()/2-20, canvas()->height()-32); | 141 | move(canvas()->width()/2-20, canvas()->height()-32); |
143 | // co ords for barrel of cannon when upright | 142 | // co ords for barrel of cannon when upright |
144 | barrelypos = canvas()->height()-32; | 143 | barrelypos = canvas()->height()-32; |
145 | barrelxpos = canvas()->width()/2; | 144 | barrelxpos = canvas()->width()/2; |
146 | 145 | ||
147 | setFrame(index); | 146 | setFrame(index); |
148 | setCoords(); | 147 | setCoords(); |
149 | } | 148 | } |
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp index 7d91cd1..42adc34 100644 --- a/noncore/games/parashoot/helicopter.cpp +++ b/noncore/games/parashoot/helicopter.cpp | |||
@@ -1,119 +1,119 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "helicopter.h" | 21 | #include "helicopter.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | #include "codes.h" | 23 | #include "codes.h" |
24 | 24 | ||
25 | #include <qtopia/resource.h> | 25 | #include <opie2/oresource.h> |
26 | 26 | ||
27 | 27 | ||
28 | static QList<Helicopter> all; | 28 | static QList<Helicopter> all; |
29 | 29 | ||
30 | Helicopter::Helicopter(QCanvas* canvas) : | 30 | Helicopter::Helicopter(QCanvas* canvas) : |
31 | QCanvasSprite(0, canvas), | 31 | QCanvasSprite(0, canvas), |
32 | chikachika("aland01") | 32 | chikachika("aland01") |
33 | { | 33 | { |
34 | all.append(this); | 34 | all.append(this); |
35 | hits = 0; | 35 | hits = 0; |
36 | QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); | 36 | QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); |
37 | QString h0 = Resource::findPixmap("parashoot/helicopter0001"); | 37 | QString h0 = Opie::Core::OResource::findPixmap("parashoot/helicopter0001"); |
38 | h0.replace(QRegExp("0001"),"%1"); | 38 | h0.replace(QRegExp("0001"),"%1"); |
39 | helicopterarray->readPixmaps(h0,4 ); | 39 | helicopterarray->readPixmaps(h0,4 ); |
40 | 40 | ||
41 | setSequence(helicopterarray); | 41 | setSequence(helicopterarray); |
42 | setAnimated(true); | 42 | setAnimated(true); |
43 | move(canvas->width(), 5); | 43 | move(canvas->width(), 5); |
44 | setVelocity(-2, 0); | 44 | setVelocity(-2, 0); |
45 | chikachika.playLoop(); | 45 | chikachika.playLoop(); |
46 | show(); | 46 | show(); |
47 | } | 47 | } |
48 | 48 | ||
49 | Helicopter::~Helicopter() | 49 | Helicopter::~Helicopter() |
50 | { | 50 | { |
51 | all.remove(this); | 51 | all.remove(this); |
52 | } | 52 | } |
53 | 53 | ||
54 | int fr = 0; | 54 | int fr = 0; |
55 | 55 | ||
56 | void Helicopter::advance(int phase) | 56 | void Helicopter::advance(int phase) |
57 | { | 57 | { |
58 | QCanvasSprite::advance(phase); | 58 | QCanvasSprite::advance(phase); |
59 | if (phase == 0) { | 59 | if (phase == 0) { |
60 | if (frame() == 3) { | 60 | if (frame() == 3) { |
61 | delete this; | 61 | delete this; |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | 64 | ||
65 | if (hits >= 2) { | 65 | if (hits >= 2) { |
66 | setFrame(3); | 66 | setFrame(3); |
67 | } else { | 67 | } else { |
68 | setFrame(fr%3); | 68 | setFrame(fr%3); |
69 | fr++; | 69 | fr++; |
70 | checkCollision(); | 70 | checkCollision(); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | void Helicopter::checkCollision() | 75 | void Helicopter::checkCollision() |
76 | { | 76 | { |
77 | if (x() == 6) { | 77 | if (x() == 6) { |
78 | setAnimated(false); //setVelocity(0, 0); | 78 | setAnimated(false); //setVelocity(0, 0); |
79 | dropman(); | 79 | dropman(); |
80 | } | 80 | } |
81 | if (x() < 0) | 81 | if (x() < 0) |
82 | done(); | 82 | done(); |
83 | } | 83 | } |
84 | 84 | ||
85 | void Helicopter::dropman() | 85 | void Helicopter::dropman() |
86 | { | 86 | { |
87 | (void)new Man(canvas(), 15, 25); | 87 | (void)new Man(canvas(), 15, 25); |
88 | (void)new Man(canvas(), 35, 25); | 88 | (void)new Man(canvas(), 35, 25); |
89 | takeOff(); | 89 | takeOff(); |
90 | } | 90 | } |
91 | 91 | ||
92 | void Helicopter::done() | 92 | void Helicopter::done() |
93 | { | 93 | { |
94 | hits++; | 94 | hits++; |
95 | } | 95 | } |
96 | 96 | ||
97 | void Helicopter::takeOff() | 97 | void Helicopter::takeOff() |
98 | { | 98 | { |
99 | setVelocity(-1, 0); | 99 | setVelocity(-1, 0); |
100 | } | 100 | } |
101 | 101 | ||
102 | int Helicopter::rtti() const | 102 | int Helicopter::rtti() const |
103 | { | 103 | { |
104 | return helicopter_rtti; | 104 | return helicopter_rtti; |
105 | } | 105 | } |
106 | 106 | ||
107 | void Helicopter::silenceAll() | 107 | void Helicopter::silenceAll() |
108 | { | 108 | { |
109 | for (Helicopter* h = all.first(); h; h = all.next()) | 109 | for (Helicopter* h = all.first(); h; h = all.next()) |
110 | h->chikachika.stop(); | 110 | h->chikachika.stop(); |
111 | } | 111 | } |
112 | 112 | ||
113 | void Helicopter::deleteAll() | 113 | void Helicopter::deleteAll() |
114 | { | 114 | { |
115 | Helicopter* h; | 115 | Helicopter* h; |
116 | while ((h = all.first())) | 116 | while ((h = all.first())) |
117 | delete h; | 117 | delete h; |
118 | } | 118 | } |
119 | 119 | ||
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp index 5c9b0ef..8ec7032 100644 --- a/noncore/games/parashoot/interface.cpp +++ b/noncore/games/parashoot/interface.cpp | |||
@@ -1,278 +1,280 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | 23 | ||
24 | #include <opie2/oresource.h> | ||
25 | |||
24 | #include <qtopia/qpeapplication.h> | 26 | #include <qtopia/qpeapplication.h> |
25 | #include <qtopia/resource.h> | ||
26 | 27 | ||
27 | #include <qtoolbar.h> | 28 | #include <qtoolbar.h> |
28 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
29 | 30 | ||
30 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : | 31 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : |
31 | QMainWindow(parent,name,f), | 32 | QMainWindow(parent,name,f), |
32 | canvas( 232, 258 ), | 33 | canvas( 232, 258 ), |
33 | cannon(NULL), | 34 | cannon(NULL), |
34 | base(NULL), | 35 | base(NULL), |
35 | gamestopped( true ), | 36 | gamestopped( true ), |
36 | waitover( false ), | 37 | waitover( false ), |
37 | fanfare("level_up"), | 38 | fanfare("level_up"), |
38 | score(0) | 39 | score(0) |
39 | { | 40 | { |
40 | QPEApplication::grabKeyboard(); | 41 | QPEApplication::grabKeyboard(); |
41 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | 42 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
42 | 43 | ||
43 | updatespeed = 80; | 44 | updatespeed = 80; |
44 | canvas.setAdvancePeriod(80); | 45 | canvas.setAdvancePeriod(80); |
45 | 46 | ||
46 | pb = new QCanvasView(&canvas, this); | 47 | pb = new QCanvasView(&canvas, this); |
47 | pb->setFocus(); | 48 | pb->setFocus(); |
48 | 49 | ||
49 | setToolBarsMovable( FALSE ); | 50 | setToolBarsMovable( FALSE ); |
50 | 51 | ||
51 | QToolBar* toolbar = new QToolBar(this); | 52 | QToolBar* toolbar = new QToolBar(this); |
52 | toolbar->setHorizontalStretchable( TRUE ); | 53 | toolbar->setHorizontalStretchable( TRUE ); |
53 | 54 | ||
54 | setCaption( tr("ParaShoot") ); | 55 | setCaption( tr("ParaShoot") ); |
55 | new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0, | 56 | QToolButton *btn = new QToolButton( Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon), |
56 | this, SLOT(newGame()), toolbar, "New Game"); | 57 | tr("New Game"), 0, this, SLOT(newGame()), toolbar, "New Game"); |
58 | btn->setUsesBigPixmap( qApp->desktop()->size().width() > 330 ); | ||
57 | 59 | ||
58 | levelscore = new QLabel(toolbar); | 60 | levelscore = new QLabel(toolbar); |
59 | levelscore->setBackgroundMode( PaletteButton ); | 61 | levelscore->setBackgroundMode( PaletteButton ); |
60 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 62 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
61 | toolbar->setStretchableWidget( levelscore ); | 63 | toolbar->setStretchableWidget( levelscore ); |
62 | showScore(0,0); | 64 | showScore(0,0); |
63 | 65 | ||
64 | setCentralWidget(pb); | 66 | setCentralWidget(pb); |
65 | 67 | ||
66 | autoDropTimer = new QTimer(this); | 68 | autoDropTimer = new QTimer(this); |
67 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); | 69 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); |
68 | 70 | ||
69 | pauseTimer = new QTimer(this); | 71 | pauseTimer = new QTimer(this); |
70 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 72 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
71 | 73 | ||
72 | setFocusPolicy(StrongFocus); | 74 | setFocusPolicy(StrongFocus); |
73 | } | 75 | } |
74 | 76 | ||
75 | 77 | ||
76 | void ParaShoot::resizeEvent(QResizeEvent *) | 78 | void ParaShoot::resizeEvent(QResizeEvent *) |
77 | { | 79 | { |
78 | QSize s = centralWidget()->size(); | 80 | QSize s = centralWidget()->size(); |
79 | int fw = style().defaultFrameWidth(); | 81 | int fw = style().defaultFrameWidth(); |
80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 82 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
81 | 83 | ||
82 | QImage bgimage = Resource::loadImage("parashoot/sky"); | 84 | QImage bgimage = Opie::Core::OResource::loadImage("parashoot/sky"); |
83 | QPixmap bgpixmap; | 85 | QPixmap bgpixmap; |
84 | 86 | ||
85 | bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(), | 87 | bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(), |
86 | canvas.height()), QPixmap::Auto); | 88 | canvas.height()), QPixmap::Auto); |
87 | canvas.setBackgroundPixmap(bgpixmap); | 89 | canvas.setBackgroundPixmap(bgpixmap); |
88 | 90 | ||
89 | if (base) { | 91 | if (base) { |
90 | base->reposition(); | 92 | base->reposition(); |
91 | } | 93 | } |
92 | 94 | ||
93 | if (cannon) { | 95 | if (cannon) { |
94 | cannon->reposition(); | 96 | cannon->reposition(); |
95 | } | 97 | } |
96 | } | 98 | } |
97 | 99 | ||
98 | void ParaShoot::focusOutEvent (QFocusEvent *) | 100 | void ParaShoot::focusOutEvent (QFocusEvent *) |
99 | { | 101 | { |
100 | if (!gamestopped) | 102 | if (!gamestopped) |
101 | canvas.setAdvancePeriod(-1); | 103 | canvas.setAdvancePeriod(-1); |
102 | } | 104 | } |
103 | 105 | ||
104 | void ParaShoot::focusInEvent (QFocusEvent *) | 106 | void ParaShoot::focusInEvent (QFocusEvent *) |
105 | { | 107 | { |
106 | if (!gamestopped) | 108 | if (!gamestopped) |
107 | canvas.setAdvancePeriod(updatespeed); | 109 | canvas.setAdvancePeriod(updatespeed); |
108 | } | 110 | } |
109 | 111 | ||
110 | void ParaShoot::showScore( int score, int level ) | 112 | void ParaShoot::showScore( int score, int level ) |
111 | { | 113 | { |
112 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); | 114 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); |
113 | } | 115 | } |
114 | 116 | ||
115 | 117 | ||
116 | void ParaShoot::newGame() | 118 | void ParaShoot::newGame() |
117 | { | 119 | { |
118 | clear(); | 120 | clear(); |
119 | if (pauseTimer->isActive()) | 121 | if (pauseTimer->isActive()) |
120 | pauseTimer->stop(); | 122 | pauseTimer->stop(); |
121 | clear(); | 123 | clear(); |
122 | Man::setManCount(0); | 124 | Man::setManCount(0); |
123 | score = 0; | 125 | score = 0; |
124 | Bullet::setShotCount(0); | 126 | Bullet::setShotCount(0); |
125 | Bullet::setNobullets(0); | 127 | Bullet::setNobullets(0); |
126 | nomen = 2; | 128 | nomen = 2; |
127 | Bullet::setLimit(nomen); | 129 | Bullet::setLimit(nomen); |
128 | level = 0; | 130 | level = 0; |
129 | updatespeed = 80; | 131 | updatespeed = 80; |
130 | showScore(0,0); | 132 | showScore(0,0); |
131 | gamestopped = false; | 133 | gamestopped = false; |
132 | Helicopter::deleteAll(); | 134 | Helicopter::deleteAll(); |
133 | waitover = true; | 135 | waitover = true; |
134 | base = new Base(&canvas); | 136 | base = new Base(&canvas); |
135 | cannon = new Cannon(&canvas); | 137 | cannon = new Cannon(&canvas); |
136 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); | 138 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); |
137 | autoDropTimer->start(100); | 139 | autoDropTimer->start(100); |
138 | } | 140 | } |
139 | 141 | ||
140 | 142 | ||
141 | void ParaShoot::clear() | 143 | void ParaShoot::clear() |
142 | { | 144 | { |
143 | autoDropTimer->stop(); | 145 | autoDropTimer->stop(); |
144 | // QCanvasItem* item; | 146 | // QCanvasItem* item; |
145 | QCanvasItemList l = canvas.allItems(); | 147 | QCanvasItemList l = canvas.allItems(); |
146 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 148 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
147 | delete *it; | 149 | delete *it; |
148 | } | 150 | } |
149 | } | 151 | } |
150 | 152 | ||
151 | void ParaShoot::gameOver() | 153 | void ParaShoot::gameOver() |
152 | { | 154 | { |
153 | QCanvasItem* item; | 155 | QCanvasItem* item; |
154 | QCanvasItemList l = canvas.allItems(); | 156 | QCanvasItemList l = canvas.allItems(); |
155 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 157 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
156 | item = *it; | 158 | item = *it; |
157 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) | 159 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) |
158 | item->setAnimated(false); | 160 | item->setAnimated(false); |
159 | } | 161 | } |
160 | autoDropTimer->stop(); | 162 | autoDropTimer->stop(); |
161 | Helicopter::silenceAll(); | 163 | Helicopter::silenceAll(); |
162 | 164 | ||
163 | int shots = Bullet::getShotCount(); | 165 | int shots = Bullet::getShotCount(); |
164 | 166 | ||
165 | int shotsFired = cannon->shotsFired(); | 167 | int shotsFired = cannon->shotsFired(); |
166 | if ( shotsFired == 0 ) | 168 | if ( shotsFired == 0 ) |
167 | shotsFired = 1; | 169 | shotsFired = 1; |
168 | QCanvasText* gameover = new QCanvasText( | 170 | QCanvasText* gameover = new QCanvasText( |
169 | tr( " GAME OVER!\n" | 171 | tr( " GAME OVER!\n" |
170 | " Your Score: %1\n" | 172 | " Your Score: %1\n" |
171 | " Parachuters Killed: %2\n" | 173 | " Parachuters Killed: %2\n" |
172 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), | 174 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), |
173 | &canvas); | 175 | &canvas); |
174 | gameover->setColor(red); | 176 | gameover->setColor(red); |
175 | gameover->setFont( QFont("times", 16, QFont::Bold) ); | 177 | gameover->setFont( QFont("times", 16, QFont::Bold) ); |
176 | gameover->move((canvas.width() - gameover->boundingRect().width()) / 2, | 178 | gameover->move((canvas.width() - gameover->boundingRect().width()) / 2, |
177 | (canvas.height() - gameover->boundingRect().height()) / 2); | 179 | (canvas.height() - gameover->boundingRect().height()) / 2); |
178 | gameover->setZ(500); | 180 | gameover->setZ(500); |
179 | gameover->show(); | 181 | gameover->show(); |
180 | gamestopped = true; | 182 | gamestopped = true; |
181 | waitover = false; | 183 | waitover = false; |
182 | pauseTimer->start(3000); | 184 | pauseTimer->start(3000); |
183 | } | 185 | } |
184 | 186 | ||
185 | void ParaShoot::wait() | 187 | void ParaShoot::wait() |
186 | { | 188 | { |
187 | waitover = true; | 189 | waitover = true; |
188 | pauseTimer->stop(); | 190 | pauseTimer->stop(); |
189 | } | 191 | } |
190 | 192 | ||
191 | void ParaShoot::play() | 193 | void ParaShoot::play() |
192 | { | 194 | { |
193 | if (Man::getManCount() < nomen ) { | 195 | if (Man::getManCount() < nomen ) { |
194 | new Man(&canvas); | 196 | new Man(&canvas); |
195 | } | 197 | } |
196 | if (Base::baseDestroyed()) { | 198 | if (Base::baseDestroyed()) { |
197 | gameOver(); | 199 | gameOver(); |
198 | return; | 200 | return; |
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
202 | void ParaShoot::increaseScore(int x) | 204 | void ParaShoot::increaseScore(int x) |
203 | { | 205 | { |
204 | score += x; | 206 | score += x; |
205 | if ( score / 150 != (score-x) / 150 ) | 207 | if ( score / 150 != (score-x) / 150 ) |
206 | levelUp(); | 208 | levelUp(); |
207 | showScore(level,score); | 209 | showScore(level,score); |
208 | } | 210 | } |
209 | 211 | ||
210 | void ParaShoot::levelUp() | 212 | void ParaShoot::levelUp() |
211 | { | 213 | { |
212 | level++; | 214 | level++; |
213 | int stage = level % 3; | 215 | int stage = level % 3; |
214 | switch(stage) { | 216 | switch(stage) { |
215 | case 0: | 217 | case 0: |
216 | nomen++; | 218 | nomen++; |
217 | Bullet::setLimit(nomen); | 219 | Bullet::setLimit(nomen); |
218 | fanfare.play(); | 220 | fanfare.play(); |
219 | break; | 221 | break; |
220 | case 1: | 222 | case 1: |
221 | new Helicopter(&canvas); | 223 | new Helicopter(&canvas); |
222 | break; | 224 | break; |
223 | case 2: | 225 | case 2: |
224 | moveFaster(); | 226 | moveFaster(); |
225 | fanfare.play(); | 227 | fanfare.play(); |
226 | break; | 228 | break; |
227 | default: return; | 229 | default: return; |
228 | } | 230 | } |
229 | } | 231 | } |
230 | 232 | ||
231 | void ParaShoot::moveFaster() | 233 | void ParaShoot::moveFaster() |
232 | { | 234 | { |
233 | if (updatespeed > 50) | 235 | if (updatespeed > 50) |
234 | updatespeed = updatespeed-5; | 236 | updatespeed = updatespeed-5; |
235 | else | 237 | else |
236 | updatespeed = updatespeed-3; | 238 | updatespeed = updatespeed-3; |
237 | canvas.setAdvancePeriod(updatespeed); | 239 | canvas.setAdvancePeriod(updatespeed); |
238 | } | 240 | } |
239 | 241 | ||
240 | void ParaShoot::keyPressEvent(QKeyEvent* event) | 242 | void ParaShoot::keyPressEvent(QKeyEvent* event) |
241 | { | 243 | { |
242 | if (gamestopped) { | 244 | if (gamestopped) { |
243 | if (waitover) | 245 | if (waitover) |
244 | newGame(); | 246 | newGame(); |
245 | else | 247 | else |
246 | return; | 248 | return; |
247 | } else { | 249 | } else { |
248 | switch(event->key()) { | 250 | switch(event->key()) { |
249 | case Key_Up: | 251 | case Key_Up: |
250 | case Key_F1: | 252 | case Key_F1: |
251 | case Key_F9: | 253 | case Key_F9: |
252 | case Key_Space: | 254 | case Key_Space: |
253 | if ( cannon ) | 255 | if ( cannon ) |
254 | cannon->shoot(); | 256 | cannon->shoot(); |
255 | break; | 257 | break; |
256 | case Key_Left:{ | 258 | case Key_Left:{ |
257 | if (cannon ) | 259 | if (cannon ) |
258 | cannon->pointCannon(Cannon::Left); | 260 | cannon->pointCannon(Cannon::Left); |
259 | lastcannonkey=Key_Left; | 261 | lastcannonkey=Key_Left; |
260 | break; | 262 | break; |
261 | } | 263 | } |
262 | case Key_Right:{ | 264 | case Key_Right:{ |
263 | if ( cannon ) | 265 | if ( cannon ) |
264 | cannon->pointCannon(Cannon::Right); | 266 | cannon->pointCannon(Cannon::Right); |
265 | lastcannonkey=Key_Right; | 267 | lastcannonkey=Key_Right; |
266 | break; | 268 | break; |
267 | } | 269 | } |
268 | default: | 270 | default: |
269 | return; | 271 | return; |
270 | } | 272 | } |
271 | } | 273 | } |
272 | } | 274 | } |
273 | 275 | ||
274 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) | 276 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) |
275 | { | 277 | { |
276 | if ( cannon && lastcannonkey == event->key() ) | 278 | if ( cannon && lastcannonkey == event->key() ) |
277 | cannon->pointCannon(Cannon::NoDir); | 279 | cannon->pointCannon(Cannon::NoDir); |
278 | } | 280 | } |
diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp index 0a151b0..080615e 100644 --- a/noncore/games/parashoot/man.cpp +++ b/noncore/games/parashoot/man.cpp | |||
@@ -1,190 +1,189 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "codes.h" | 21 | #include "codes.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | #include "base.h" | 23 | #include "base.h" |
24 | 24 | ||
25 | #include <qtopia/resource.h> | 25 | #include <opie2/oresource.h> |
26 | |||
27 | 26 | ||
28 | int mancount; | 27 | int mancount; |
29 | 28 | ||
30 | Man::Man(QCanvas* canvas) : | 29 | Man::Man(QCanvas* canvas) : |
31 | QCanvasSprite(0, canvas), | 30 | QCanvasSprite(0, canvas), |
32 | splat("lose") // No tr | 31 | splat("lose") // No tr |
33 | { | 32 | { |
34 | manarray = new QCanvasPixmapArray(); | 33 | manarray = new QCanvasPixmapArray(); |
35 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 34 | QString m0 = Opie::Core::OResource::findPixmap("parashoot/man0001"); |
36 | m0.replace(QRegExp("0001"),"%1"); | 35 | m0.replace(QRegExp("0001"),"%1"); |
37 | manarray->readPixmaps(m0, 7); | 36 | manarray->readPixmaps(m0, 7); |
38 | setSequence(manarray); | 37 | setSequence(manarray); |
39 | setAnimated(true); | 38 | setAnimated(true); |
40 | mancount++; | 39 | mancount++; |
41 | dead = false; | 40 | dead = false; |
42 | start(); | 41 | start(); |
43 | } | 42 | } |
44 | 43 | ||
45 | Man::Man(QCanvas* canvas, int x, int y) : | 44 | Man::Man(QCanvas* canvas, int x, int y) : |
46 | QCanvasSprite(0, canvas), | 45 | QCanvasSprite(0, canvas), |
47 | splat("bang") // No tr | 46 | splat("bang") // No tr |
48 | { | 47 | { |
49 | manarray = new QCanvasPixmapArray(); | 48 | manarray = new QCanvasPixmapArray(); |
50 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 49 | QString m0 = Opie::Core::OResource::findPixmap("parashoot/man0001"); |
51 | m0.replace(QString("0001"),"%1"); | 50 | m0.replace(QString("0001"),"%1"); |
52 | manarray->readPixmaps(m0, 7); | 51 | manarray->readPixmaps(m0, 7); |
53 | setSequence(manarray); | 52 | setSequence(manarray); |
54 | move(x, y); | 53 | move(x, y); |
55 | setFrame(5); | 54 | setFrame(5); |
56 | setZ(300); | 55 | setZ(300); |
57 | show(); | 56 | show(); |
58 | 57 | ||
59 | static bool first_time = TRUE; | 58 | static bool first_time = TRUE; |
60 | if (first_time) { | 59 | if (first_time) { |
61 | first_time = FALSE; | 60 | first_time = FALSE; |
62 | QTime midnight(0, 0, 0); | 61 | QTime midnight(0, 0, 0); |
63 | srand(midnight.secsTo(QTime::currentTime()) ); | 62 | srand(midnight.secsTo(QTime::currentTime()) ); |
64 | } | 63 | } |
65 | int yfallspeed = 0; | 64 | int yfallspeed = 0; |
66 | yfallspeed = (rand() % 3) + 1; | 65 | yfallspeed = (rand() % 3) + 1; |
67 | setVelocity(0, yfallspeed); | 66 | setVelocity(0, yfallspeed); |
68 | 67 | ||
69 | mancount++; | 68 | mancount++; |
70 | dead = false; | 69 | dead = false; |
71 | } | 70 | } |
72 | int f = 0; | 71 | int f = 0; |
73 | 72 | ||
74 | void Man::advance(int phase) | 73 | void Man::advance(int phase) |
75 | { | 74 | { |
76 | QCanvasSprite::advance(phase); | 75 | QCanvasSprite::advance(phase); |
77 | if (phase == 0) { | 76 | if (phase == 0) { |
78 | checkCollision(); | 77 | checkCollision(); |
79 | if (dead) { | 78 | if (dead) { |
80 | if (count < 10) { | 79 | if (count < 10) { |
81 | setFrame(6); | 80 | setFrame(6); |
82 | setVelocity(0,0); | 81 | setVelocity(0,0); |
83 | count++; | 82 | count++; |
84 | } else { | 83 | } else { |
85 | delete this; | 84 | delete this; |
86 | return; | 85 | return; |
87 | } | 86 | } |
88 | } | 87 | } |
89 | if (y() > canvas()->height()-43) { | 88 | if (y() > canvas()->height()-43) { |
90 | setFrame(f%5); | 89 | setFrame(f%5); |
91 | f++; | 90 | f++; |
92 | move(x(), canvas()->height()-26); | 91 | move(x(), canvas()->height()-26); |
93 | setVelocity(-2, 0); | 92 | setVelocity(-2, 0); |
94 | } else if (xVelocity() == -2) { | 93 | } else if (xVelocity() == -2) { |
95 | // | 94 | // |
96 | // There's been a resize event while this Man has | 95 | // There's been a resize event while this Man has |
97 | // been on the ground. Move the man back to the | 96 | // been on the ground. Move the man back to the |
98 | // new ground location. This is not neat. | 97 | // new ground location. This is not neat. |
99 | // | 98 | // |
100 | move(x(), canvas()->height()-26); | 99 | move(x(), canvas()->height()-26); |
101 | } | 100 | } |
102 | } | 101 | } |
103 | } | 102 | } |
104 | 103 | ||
105 | void Man::setInitialCoords() | 104 | void Man::setInitialCoords() |
106 | { | 105 | { |
107 | static bool first_time = TRUE; | 106 | static bool first_time = TRUE; |
108 | if (first_time) { | 107 | if (first_time) { |
109 | first_time = FALSE; | 108 | first_time = FALSE; |
110 | QTime midnight(0, 0, 0); | 109 | QTime midnight(0, 0, 0); |
111 | srand(midnight.secsTo(QTime::currentTime()) ); | 110 | srand(midnight.secsTo(QTime::currentTime()) ); |
112 | } | 111 | } |
113 | dx = rand() % (canvas()->width()-16); | 112 | dx = rand() % (canvas()->width()-16); |
114 | dy = -43; //height of a man off the screen | 113 | dy = -43; //height of a man off the screen |
115 | } | 114 | } |
116 | 115 | ||
117 | //check if man has reached the base | 116 | //check if man has reached the base |
118 | void Man::checkCollision() | 117 | void Man::checkCollision() |
119 | { | 118 | { |
120 | if ( (x() < 23) && (y() == canvas()->height()-26)) { | 119 | if ( (x() < 23) && (y() == canvas()->height()-26)) { |
121 | QCanvasItem* item; | 120 | QCanvasItem* item; |
122 | QCanvasItemList l=collisions(FALSE); | 121 | QCanvasItemList l=collisions(FALSE); |
123 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 122 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
124 | item = *it; | 123 | item = *it; |
125 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { | 124 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { |
126 | Base* base = (Base*) item; | 125 | Base* base = (Base*) item; |
127 | base->damageBase(); | 126 | base->damageBase(); |
128 | start(); | 127 | start(); |
129 | } | 128 | } |
130 | } | 129 | } |
131 | } | 130 | } |
132 | 131 | ||
133 | // | 132 | // |
134 | // resize events may cause Man objects to appear | 133 | // resize events may cause Man objects to appear |
135 | // outside the screen. Get rid of them if this | 134 | // outside the screen. Get rid of them if this |
136 | // is the case. | 135 | // is the case. |
137 | // | 136 | // |
138 | if ((x() < 0) || (x() > canvas()->width())) { | 137 | if ((x() < 0) || (x() > canvas()->width())) { |
139 | delete this; | 138 | delete this; |
140 | return; | 139 | return; |
141 | } | 140 | } |
142 | } | 141 | } |
143 | 142 | ||
144 | void Man::start() | 143 | void Man::start() |
145 | { | 144 | { |
146 | setInitialCoords(); | 145 | setInitialCoords(); |
147 | move(dx, dy); | 146 | move(dx, dy); |
148 | setFrame(5); | 147 | setFrame(5); |
149 | setZ(300); | 148 | setZ(300); |
150 | show(); | 149 | show(); |
151 | 150 | ||
152 | static bool first_time = TRUE; | 151 | static bool first_time = TRUE; |
153 | if (first_time) { | 152 | if (first_time) { |
154 | first_time = FALSE; | 153 | first_time = FALSE; |
155 | QTime midnight(0, 0, 0); | 154 | QTime midnight(0, 0, 0); |
156 | srand(midnight.secsTo(QTime::currentTime()) ); | 155 | srand(midnight.secsTo(QTime::currentTime()) ); |
157 | } | 156 | } |
158 | int yfallspeed = 0; | 157 | int yfallspeed = 0; |
159 | yfallspeed = (rand() % 3) + 1; | 158 | yfallspeed = (rand() % 3) + 1; |
160 | setVelocity(0, yfallspeed); | 159 | setVelocity(0, yfallspeed); |
161 | } | 160 | } |
162 | 161 | ||
163 | void Man::done() | 162 | void Man::done() |
164 | { | 163 | { |
165 | splat.play(); | 164 | splat.play(); |
166 | count = 0; | 165 | count = 0; |
167 | dead = true; | 166 | dead = true; |
168 | setFrame(6); | 167 | setFrame(6); |
169 | } | 168 | } |
170 | 169 | ||
171 | int Man::getManCount() | 170 | int Man::getManCount() |
172 | { | 171 | { |
173 | return mancount; | 172 | return mancount; |
174 | } | 173 | } |
175 | 174 | ||
176 | void Man::setManCount(int count) | 175 | void Man::setManCount(int count) |
177 | { | 176 | { |
178 | mancount = count; | 177 | mancount = count; |
179 | } | 178 | } |
180 | 179 | ||
181 | 180 | ||
182 | int Man::rtti() const | 181 | int Man::rtti() const |
183 | { | 182 | { |
184 | return man_rtti; | 183 | return man_rtti; |
185 | } | 184 | } |
186 | 185 | ||
187 | Man::~Man() | 186 | Man::~Man() |
188 | { | 187 | { |
189 | mancount--; | 188 | mancount--; |
190 | } | 189 | } |
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp index c36da6c..cd298ef 100644 --- a/noncore/games/solitaire/canvascard.cpp +++ b/noncore/games/solitaire/canvascard.cpp | |||
@@ -1,308 +1,303 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "canvascard.h" | 21 | #include "canvascard.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <opie2/oresource.h> |
24 | 24 | ||
25 | #include <qgfx_qws.h> // Needed to get the device's width | 25 | #include <qgfx_qws.h> // Needed to get the device's width |
26 | 26 | ||
27 | #include <math.h> | 27 | #include <math.h> |
28 | 28 | ||
29 | #if defined( QT_QWS_CASSIOPEIA ) | 29 | #if defined( QT_QWS_CASSIOPEIA ) |
30 | #define SLOW_HARDWARE | 30 | #define SLOW_HARDWARE |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | // Seems to be fast enough to me even without Transformations in the library | 33 | // Seems to be fast enough to me even without Transformations in the library |
34 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) | 34 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) |
35 | //#define SLOW_HARDWARE | 35 | //#define SLOW_HARDWARE |
36 | //#endif | 36 | //#endif |
37 | 37 | ||
38 | 38 | ||
39 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) | 39 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) |
40 | { | 40 | { |
41 | #ifdef QT_NO_TRANSFORMATIONS | 41 | #ifdef QT_NO_TRANSFORMATIONS |
42 | int w = srcBitmap->width(); | 42 | int w = srcBitmap->width(); |
43 | int h = srcBitmap->height(); | 43 | int h = srcBitmap->height(); |
44 | QBitmap *dstBitmap = new QBitmap( w, h ); | 44 | QBitmap *dstBitmap = new QBitmap( w, h ); |
45 | // ### this is very poorly implemented and probably could be much faster | 45 | // ### this is very poorly implemented and probably could be much faster |
46 | for (int i = 0; i < w; i++) | 46 | for (int i = 0; i < w; i++) |
47 | for (int j = 0; j < h; j++) | 47 | for (int j = 0; j < h; j++) |
48 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); | 48 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); |
49 | return dstBitmap; | 49 | return dstBitmap; |
50 | #else | 50 | #else |
51 | QWMatrix m; | 51 | QWMatrix m; |
52 | m.rotate( 180.0 ); | 52 | m.rotate( 180.0 ); |
53 | return new QBitmap( srcBitmap->xForm( m ) ); | 53 | return new QBitmap( srcBitmap->xForm( m ) ); |
54 | #endif | 54 | #endif |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) | 58 | QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) |
59 | { | 59 | { |
60 | #ifdef QT_NO_TRANSFORMATIONS | 60 | #ifdef QT_NO_TRANSFORMATIONS |
61 | int w = srcPixmap->width(); | 61 | int w = srcPixmap->width(); |
62 | int h = srcPixmap->height(); | 62 | int h = srcPixmap->height(); |
63 | int newW = (int)(w * scaleX); | 63 | int newW = (int)(w * scaleX); |
64 | int newH = (int)(h * scaleY); | 64 | int newH = (int)(h * scaleY); |
65 | QPixmap *dstPixmap = new QPixmap( newW, newH ); | 65 | QPixmap *dstPixmap = new QPixmap( newW, newH ); |
66 | // ### this is very poorly implemented and probably could be much faster | 66 | // ### this is very poorly implemented and probably could be much faster |
67 | for (int i = 0; i < newW; i++) { | 67 | for (int i = 0; i < newW; i++) { |
68 | int srcX = w * i / newW; | 68 | int srcX = w * i / newW; |
69 | if (newH == h) { | 69 | if (newH == h) { |
70 | // Optimise for scaleing in the X-axis only | 70 | // Optimise for scaleing in the X-axis only |
71 | bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h ); | 71 | bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h ); |
72 | } else { | 72 | } else { |
73 | for (int j = 0; j < newH; j++) { | 73 | for (int j = 0; j < newH; j++) { |
74 | int srcY = h * j / newH; | 74 | int srcY = h * j / newH; |
75 | bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 ); | 75 | bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 ); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | } | 78 | } |
79 | return dstPixmap; | 79 | return dstPixmap; |
80 | #else | 80 | #else |
81 | QWMatrix s; | 81 | QWMatrix s; |
82 | s.scale( scaleX, scaleY ); | 82 | s.scale( scaleX, scaleY ); |
83 | return new QPixmap( srcPixmap->xForm( s ) ); | 83 | return new QPixmap( srcPixmap->xForm( s ) ); |
84 | #endif | 84 | #endif |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | // Initialise static member variables to NULL | 88 | // Initialise static member variables to NULL |
89 | QPixmap *CanvasCard::cardsFaces = NULL; | 89 | QPixmap *CanvasCard::cardsFaces = NULL; |
90 | QPixmap *CanvasCard::cardsBacks = NULL; | 90 | QPixmap *CanvasCard::cardsBacks = NULL; |
91 | QBitmap *CanvasCard::cardsChars = NULL; | 91 | QBitmap *CanvasCard::cardsChars = NULL; |
92 | QBitmap *CanvasCard::cardsSuits = NULL; | 92 | QBitmap *CanvasCard::cardsSuits = NULL; |
93 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; | 93 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; |
94 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; | 94 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; |
95 | 95 | ||
96 | 96 | ||
97 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : | 97 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : |
98 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) | 98 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) |
99 | { | 99 | { |
100 | if ( !cardsFaces ) { | 100 | if ( !cardsFaces ) { |
101 | if ( qt_screen->deviceWidth() < 200 ) { | 101 | if ( qt_screen->deviceWidth() < 200 ) { |
102 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) ); | 102 | cardsFaces = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_face_small" ) ); |
103 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); | 103 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001_small" ) ); |
104 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) ); | 104 | cardsChars = new QBitmap(); |
105 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) ); | 105 | *cardsChars = Opie::Core::OResource::loadPixmap( "cards/card_chars_small" ); |
106 | cardsSuits = new QBitmap(); | ||
107 | *cardsSuits = Opie::Core::OResource::loadPixmap( "cards/card_suits_small" ); | ||
106 | } else { | 108 | } else { |
107 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); | 109 | cardsFaces = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_face" ) ); |
108 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); | 110 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001" ) ); |
109 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); | 111 | cardsChars = new QBitmap(); |
110 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); | 112 | *cardsChars = Opie::Core::OResource::loadPixmap( "cards/card_chars" ); |
113 | cardsSuits = new QBitmap(); | ||
114 | *cardsSuits = Opie::Core::OResource::loadPixmap( "cards/card_suits" ); | ||
111 | } | 115 | } |
112 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); | 116 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); |
113 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); | 117 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); |
114 | } | 118 | } |
115 | xOff = cardsFaces->width() / 2; | 119 | xOff = cardsFaces->width() / 2; |
116 | yOff = cardsFaces->height() / 2; | 120 | yOff = cardsFaces->height() / 2; |
117 | setSize( cardsFaces->width(), cardsFaces->height() ); | 121 | setSize( cardsFaces->width(), cardsFaces->height() ); |
118 | setPen( NoPen ); | 122 | setPen( NoPen ); |
119 | flipping = FALSE; | 123 | flipping = FALSE; |
120 | } | 124 | } |
121 | 125 | ||
122 | 126 | ||
123 | void CanvasCard::setCardBack(int b) | 127 | void CanvasCard::setCardBack(int b) |
124 | { | 128 | { |
125 | if ( cardBack != b ) { | 129 | if ( cardBack != b ) { |
126 | 130 | ||
127 | cardBack = b; | 131 | cardBack = b; |
128 | 132 | ||
129 | if ( cardsBacks ) | 133 | if ( cardsBacks ) |
130 | delete cardsBacks; | 134 | delete cardsBacks; |
131 | 135 | ||
132 | if ( qt_screen->deviceWidth() < 200 ) { | 136 | if ( qt_screen->deviceWidth() < 200 ) { |
133 | switch (cardBack) { | 137 | switch (cardBack) { |
134 | case 0: | 138 | case 0: |
135 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break; | 139 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001_small" ) ); break; |
136 | case 1: | 140 | case 1: |
137 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break; | 141 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002_small" ) ); break; |
138 | case 2: | 142 | case 2: |
139 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break; | 143 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003_small" ) ); break; |
140 | case 3: | 144 | case 3: |
141 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break; | 145 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004_small" ) ); break; |
142 | case 4: | 146 | case 4: |
143 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break; | 147 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005_small" ) ); break; |
144 | } | 148 | } |
145 | } else { | 149 | } else { |
146 | switch (cardBack) { | 150 | switch (cardBack) { |
147 | case 0: | 151 | case 0: |
148 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; | 152 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001" ) ); break; |
149 | case 1: | 153 | case 1: |
150 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; | 154 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002" ) ); break; |
151 | case 2: | 155 | case 2: |
152 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; | 156 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003" ) ); break; |
153 | case 3: | 157 | case 3: |
154 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; | 158 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004" ) ); break; |
155 | case 4: | 159 | case 4: |
156 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; | 160 | cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005" ) ); break; |
157 | } | 161 | } |
158 | } | 162 | } |
159 | 163 | ||
160 | if ( !isFacing() ) | 164 | if ( !isFacing() ) |
161 | redraw(); | 165 | redraw(); |
162 | } | 166 | } |
163 | } | 167 | } |
164 | 168 | ||
165 | 169 | ||
166 | void CanvasCard::draw(QPainter &painter) | 170 | void CanvasCard::draw(QPainter &painter) |
167 | { | 171 | { |
168 | int ix = (int)x(), iy = (int)y(); | 172 | int ix = (int)x(), iy = (int)y(); |
169 | 173 | ||
170 | QPainter *p = &painter; | 174 | QPainter *p = &painter; |
171 | QPixmap *unscaledCard = NULL; | 175 | QPixmap *unscaledCard = NULL; |
172 | 176 | ||
173 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) | 177 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) |
174 | { | 178 | { |
175 | p = new QPainter(); | 179 | p = new QPainter(); |
176 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); | 180 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); |
177 | p->begin(unscaledCard); | 181 | p->begin(unscaledCard); |
178 | ix = 0; | 182 | ix = 0; |
179 | iy = 0; | 183 | iy = 0; |
180 | } | 184 | } |
181 | 185 | ||
182 | if ( isFacing() ) { | 186 | if ( isFacing() ) { |
183 | 187 | ||
184 | /* | ||
185 | // Now add the joker and card backs to the list of pixmaps | ||
186 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); | ||
187 | QPoint *newBackHotspot = new QPoint( 0, 0 ); | ||
188 | pixmaps->append((const QPixmap *)CardsBack); | ||
189 | hotspots->append((const QPoint *)newBackHotspot); | ||
190 | */ | ||
191 | |||
192 | int w = cardsFaces->width(), h = cardsFaces->height(); | 188 | int w = cardsFaces->width(), h = cardsFaces->height(); |
193 | 189 | ||
194 | //p->setBrush( NoBrush ); | ||
195 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); | 190 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); |
196 | 191 | ||
197 | if ( isRed() == TRUE ) | 192 | if ( isRed() == TRUE ) |
198 | p->setPen( QColor( 0xFF, 0, 0 ) ); | 193 | p->setPen( QColor( 0xFF, 0, 0 ) ); |
199 | else | 194 | else |
200 | p->setPen( QColor( 0, 0, 0 ) ); | 195 | p->setPen( QColor( 0, 0, 0 ) ); |
201 | 196 | ||
202 | if ( qt_screen->deviceWidth() < 200 ) { | 197 | if ( qt_screen->deviceWidth() < 200 ) { |
203 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | 198 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); |
204 | p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); | 199 | p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); |
205 | p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); | 200 | p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); |
206 | p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); | 201 | p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); |
207 | p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); | 202 | p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); |
208 | } else { | 203 | } else { |
209 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | 204 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); |
210 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); | 205 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); |
211 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); | 206 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); |
212 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); | 207 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); |
213 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); | 208 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); |
214 | } | 209 | } |
215 | 210 | ||
216 | } else { | 211 | } else { |
217 | 212 | ||
218 | p->drawPixmap( ix, iy, *cardsBacks ); | 213 | p->drawPixmap( ix, iy, *cardsBacks ); |
219 | 214 | ||
220 | } | 215 | } |
221 | 216 | ||
222 | if (p != &painter) | 217 | if (p != &painter) |
223 | { | 218 | { |
224 | p->end(); | 219 | p->end(); |
225 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); | 220 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); |
226 | int xoff = scaledCard->width() / 2; | 221 | int xoff = scaledCard->width() / 2; |
227 | int yoff = scaledCard->height() / 2; | 222 | int yoff = scaledCard->height() / 2; |
228 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); | 223 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); |
229 | delete p; | 224 | delete p; |
230 | delete unscaledCard; | 225 | delete unscaledCard; |
231 | delete scaledCard; | 226 | delete scaledCard; |
232 | } | 227 | } |
233 | } | 228 | } |
234 | 229 | ||
235 | 230 | ||
236 | static const double flipLift = 1.5; | 231 | static const double flipLift = 1.5; |
237 | 232 | ||
238 | 233 | ||
239 | void CanvasCard::flipTo(int x2, int y2, int steps) | 234 | void CanvasCard::flipTo(int x2, int y2, int steps) |
240 | { | 235 | { |
241 | flipSteps = steps; | 236 | flipSteps = steps; |
242 | 237 | ||
243 | #ifdef SLOW_HARDWARE | 238 | #ifdef SLOW_HARDWARE |
244 | move(x2,y2); | 239 | move(x2,y2); |
245 | Card::flipTo(x2,y2,steps); | 240 | Card::flipTo(x2,y2,steps); |
246 | #else | 241 | #else |
247 | int x1 = (int)x(); | 242 | int x1 = (int)x(); |
248 | int y1 = (int)y(); | 243 | int y1 = (int)y(); |
249 | double dx = x2 - x1; | 244 | double dx = x2 - x1; |
250 | double dy = y2 - y1; | 245 | double dy = y2 - y1; |
251 | 246 | ||
252 | flipping = TRUE; | 247 | flipping = TRUE; |
253 | destX = x2; | 248 | destX = x2; |
254 | destY = y2; | 249 | destY = y2; |
255 | animSteps = flipSteps; | 250 | animSteps = flipSteps; |
256 | setVelocity(dx/animSteps, dy/animSteps-flipLift); | 251 | setVelocity(dx/animSteps, dy/animSteps-flipLift); |
257 | setAnimated(TRUE); | 252 | setAnimated(TRUE); |
258 | #endif | 253 | #endif |
259 | } | 254 | } |
260 | 255 | ||
261 | 256 | ||
262 | void CanvasCard::advance(int stage) | 257 | void CanvasCard::advance(int stage) |
263 | { | 258 | { |
264 | if ( stage==1 ) { | 259 | if ( stage==1 ) { |
265 | if ( animSteps-- <= 0 ) { | 260 | if ( animSteps-- <= 0 ) { |
266 | scaleX = 1.0; | 261 | scaleX = 1.0; |
267 | scaleY = 1.0; | 262 | scaleY = 1.0; |
268 | flipping = FALSE; | 263 | flipping = FALSE; |
269 | setVelocity(0,0); | 264 | setVelocity(0,0); |
270 | setAnimated(FALSE); | 265 | setAnimated(FALSE); |
271 | move(destX,destY); // exact | 266 | move(destX,destY); // exact |
272 | } else { | 267 | } else { |
273 | if ( flipping ) { | 268 | if ( flipping ) { |
274 | if ( animSteps > flipSteps / 2 ) { | 269 | if ( animSteps > flipSteps / 2 ) { |
275 | // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 | 270 | // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 |
276 | scaleX = ((double)animSteps/flipSteps-0.5)*2; | 271 | scaleX = ((double)animSteps/flipSteps-0.5)*2; |
277 | } else { | 272 | } else { |
278 | // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 | 273 | // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 |
279 | scaleX = 1-((double)animSteps/flipSteps)*2; | 274 | scaleX = 1-((double)animSteps/flipSteps)*2; |
280 | } | 275 | } |
281 | if ( animSteps == flipSteps / 2-1 ) { | 276 | if ( animSteps == flipSteps / 2-1 ) { |
282 | setYVelocity(yVelocity()+flipLift*2); | 277 | setYVelocity(yVelocity()+flipLift*2); |
283 | setFace( !isFacing() ); | 278 | setFace( !isFacing() ); |
284 | } | 279 | } |
285 | } | 280 | } |
286 | } | 281 | } |
287 | } | 282 | } |
288 | QCanvasRectangle::advance(stage); | 283 | QCanvasRectangle::advance(stage); |
289 | } | 284 | } |
290 | 285 | ||
291 | 286 | ||
292 | void CanvasCard::animatedMove(int x2, int y2, int steps) | 287 | void CanvasCard::animatedMove(int x2, int y2, int steps) |
293 | { | 288 | { |
294 | destX = x2; | 289 | destX = x2; |
295 | destY = y2; | 290 | destY = y2; |
296 | 291 | ||
297 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | 292 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; |
298 | 293 | ||
299 | // Ensure a good speed | 294 | // Ensure a good speed |
300 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | 295 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) |
301 | steps--; | 296 | steps--; |
302 | 297 | ||
303 | setAnimated(TRUE); | 298 | setAnimated(TRUE); |
304 | setVelocity(dx/steps, dy/steps); | 299 | setVelocity(dx/steps, dy/steps); |
305 | 300 | ||
306 | animSteps = steps; | 301 | animSteps = steps; |
307 | } | 302 | } |
308 | 303 | ||
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h index b93cfbf..c559a90 100644 --- a/noncore/games/solitaire/canvascardgame.h +++ b/noncore/games/solitaire/canvascardgame.h | |||
@@ -1,97 +1,96 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef CANVAS_CARD_GAME_H | 20 | #ifndef CANVAS_CARD_GAME_H |
21 | #define CANVAS_CARD_GAME_H | 21 | #define CANVAS_CARD_GAME_H |
22 | 22 | ||
23 | #include "cardgame.h" | 23 | #include "cardgame.h" |
24 | #include "canvasshapes.h" | 24 | #include "canvasshapes.h" |
25 | #include "canvascard.h" | 25 | #include "canvascard.h" |
26 | 26 | ||
27 | #include <qpe/resource.h> | ||
28 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
29 | 28 | ||
30 | #include <qmainwindow.h> | 29 | #include <qmainwindow.h> |
31 | #include <qmenubar.h> | 30 | #include <qmenubar.h> |
32 | #include <qpainter.h> | 31 | #include <qpainter.h> |
33 | 32 | ||
34 | #include <stdlib.h> | 33 | #include <stdlib.h> |
35 | #include <time.h> | 34 | #include <time.h> |
36 | 35 | ||
37 | 36 | ||
38 | class CanvasCardPile; | 37 | class CanvasCardPile; |
39 | 38 | ||
40 | 39 | ||
41 | class CanvasCardGame : public QCanvasView, public CardGame | 40 | class CanvasCardGame : public QCanvasView, public CardGame |
42 | { | 41 | { |
43 | public: | 42 | public: |
44 | CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, int numOfDecks = 1, const char *name = 0, WFlags f = 0) : | 43 | CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, int numOfDecks = 1, const char *name = 0, WFlags f = 0) : |
45 | QCanvasView( &c, parent, name, f ), | 44 | QCanvasView( &c, parent, name, f ), |
46 | CardGame(0,numOfDecks), | 45 | CardGame(0,numOfDecks), |
47 | moved(FALSE), | 46 | moved(FALSE), |
48 | moving(NULL), | 47 | moving(NULL), |
49 | alphaCardPile( NULL ), | 48 | alphaCardPile( NULL ), |
50 | cardXOff(0), cardYOff(0), | 49 | cardXOff(0), cardYOff(0), |
51 | snapOn(snap), | 50 | snapOn(snap), |
52 | numberToDraw(1) { } | 51 | numberToDraw(1) { } |
53 | 52 | ||
54 | virtual ~CanvasCardGame(); | 53 | virtual ~CanvasCardGame(); |
55 | 54 | ||
56 | virtual Card *newCard( eValue v, eSuit s, bool f ) { | 55 | virtual Card *newCard( eValue v, eSuit s, bool f ) { |
57 | return new CanvasCard( v, s, f, canvas() ); | 56 | return new CanvasCard( v, s, f, canvas() ); |
58 | } | 57 | } |
59 | 58 | ||
60 | virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); } | 59 | virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); } |
61 | virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); } | 60 | virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); } |
62 | 61 | ||
63 | virtual void gameWon(); | 62 | virtual void gameWon(); |
64 | virtual bool haveWeWon() { return FALSE; } | 63 | virtual bool haveWeWon() { return FALSE; } |
65 | 64 | ||
66 | virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; } | 65 | virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; } |
67 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | 66 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } |
68 | 67 | ||
69 | void cancelMoving() { moving = NULL; } | 68 | void cancelMoving() { moving = NULL; } |
70 | void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; } | 69 | void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; } |
71 | void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; } | 70 | void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; } |
72 | int cardsDrawn() { return numberToDraw; } | 71 | int cardsDrawn() { return numberToDraw; } |
73 | void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; } | 72 | void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; } |
74 | 73 | ||
75 | void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ); | 74 | void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ); |
76 | 75 | ||
77 | protected: | 76 | protected: |
78 | void contentsMousePressEvent(QMouseEvent *e); | 77 | void contentsMousePressEvent(QMouseEvent *e); |
79 | void contentsMouseReleaseEvent(QMouseEvent *e); | 78 | void contentsMouseReleaseEvent(QMouseEvent *e); |
80 | void contentsMouseMoveEvent(QMouseEvent *e); | 79 | void contentsMouseMoveEvent(QMouseEvent *e); |
81 | virtualvoid checkUnusable() { } //added for freecell | 80 | virtualvoid checkUnusable() { } //added for freecell |
82 | 81 | ||
83 | protected: | 82 | protected: |
84 | // Mouse event state variables | 83 | // Mouse event state variables |
85 | bool moved; | 84 | bool moved; |
86 | CanvasCard *moving; | 85 | CanvasCard *moving; |
87 | CanvasCardPile *alphaCardPile; | 86 | CanvasCardPile *alphaCardPile; |
88 | int cardXOff, cardYOff; | 87 | int cardXOff, cardYOff; |
89 | 88 | ||
90 | private: | 89 | private: |
91 | bool snapOn; | 90 | bool snapOn; |
92 | int numberToDraw; | 91 | int numberToDraw; |
93 | }; | 92 | }; |
94 | 93 | ||
95 | 94 | ||
96 | #endif | 95 | #endif |
97 | 96 | ||
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp index 503bc92..956c5bd 100644 --- a/noncore/games/solitaire/canvascardwindow.cpp +++ b/noncore/games/solitaire/canvascardwindow.cpp | |||
@@ -1,310 +1,309 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "canvascardwindow.h" | 21 | #include "canvascardwindow.h" |
22 | #include "freecellcardgame.h" | 22 | #include "freecellcardgame.h" |
23 | #include "chicanecardgame.h" | 23 | #include "chicanecardgame.h" |
24 | #include "harpcardgame.h" | 24 | #include "harpcardgame.h" |
25 | #include "teeclubcardgame.h" | 25 | #include "teeclubcardgame.h" |
26 | 26 | ||
27 | 27 | #include <opie2/oresource.h> | |
28 | |||
29 | 28 | ||
30 | CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : | 29 | CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : |
31 | QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), | 30 | QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), |
32 | cardGame(NULL) | 31 | cardGame(NULL) |
33 | { | 32 | { |
34 | setIcon( Resource::loadPixmap( "cards" ) ); | 33 | setIcon( Opie::Core::OResource::loadPixmap( "cards" ) ); |
35 | setCaption(tr("Patience")); | 34 | setCaption(tr("Patience")); |
36 | 35 | ||
37 | // Create Playing Area for Games | 36 | // Create Playing Area for Games |
38 | if ( QPixmap::defaultDepth() < 12 ) { | 37 | if ( QPixmap::defaultDepth() < 12 ) { |
39 | // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); | 38 | // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); |
40 | // canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); | 39 | // canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); |
41 | canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); | 40 | canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); |
42 | } else { | 41 | } else { |
43 | QPixmap bg; | 42 | QPixmap bg; |
44 | bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); | 43 | bg.convertFromImage( Opie::Core::OResource::loadImage( "table_pattern" ), ThresholdDither ); |
45 | canvas.setBackgroundPixmap(bg); | 44 | canvas.setBackgroundPixmap(bg); |
46 | } | 45 | } |
47 | 46 | ||
48 | #if defined( QT_QWS_CASSIOPEIA ) | 47 | #if defined( QT_QWS_CASSIOPEIA ) |
49 | canvas.setAdvancePeriod(70); | 48 | canvas.setAdvancePeriod(70); |
50 | #else | 49 | #else |
51 | canvas.setAdvancePeriod(30); | 50 | canvas.setAdvancePeriod(30); |
52 | #endif | 51 | #endif |
53 | 52 | ||
54 | 53 | ||
55 | #ifdef _PATIENCE_USE_ACCELS_ | 54 | #ifdef _PATIENCE_USE_ACCELS_ |
56 | QMenuBar* menu = menuBar(); | 55 | QMenuBar* menu = menuBar(); |
57 | 56 | ||
58 | QPopupMenu* file = new QPopupMenu; | 57 | QPopupMenu* file = new QPopupMenu; |
59 | file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); | 58 | file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); |
60 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); | 59 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); |
61 | file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); | 60 | file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); |
62 | file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); | 61 | file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); |
63 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F); | 62 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F); |
64 | menu->insertItem(tr("&Game"), file); | 63 | menu->insertItem(tr("&Game"), file); |
65 | 64 | ||
66 | menu->insertSeparator(); | 65 | menu->insertSeparator(); |
67 | 66 | ||
68 | settings = new QPopupMenu; | 67 | settings = new QPopupMenu; |
69 | settings->insertItem(tr("&Change card backs"), this, SLOT(changeCardBacks()), Key_F2); | 68 | settings->insertItem(tr("&Change card backs"), this, SLOT(changeCardBacks()), Key_F2); |
70 | snap_id = settings->insertItem(tr("&Snap to position"), this, SLOT(snapToggle()), Key_F3); | 69 | snap_id = settings->insertItem(tr("&Snap to position"), this, SLOT(snapToggle()), Key_F3); |
71 | settings->setCheckable(TRUE); | 70 | settings->setCheckable(TRUE); |
72 | menu->insertItem(tr("&Settings"),settings); | 71 | menu->insertItem(tr("&Settings"),settings); |
73 | 72 | ||
74 | menu->insertSeparator(); | 73 | menu->insertSeparator(); |
75 | 74 | ||
76 | QPopupMenu* help = new QPopupMenu; | 75 | QPopupMenu* help = new QPopupMenu; |
77 | help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); | 76 | help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); |
78 | help->setItemChecked(dbf_id, TRUE); | 77 | help->setItemChecked(dbf_id, TRUE); |
79 | menu->insertItem(tr("&Help"),help); | 78 | menu->insertItem(tr("&Help"),help); |
80 | #else | 79 | #else |
81 | QMenuBar* menu = menuBar(); | 80 | QMenuBar* menu = menuBar(); |
82 | 81 | ||
83 | QPopupMenu* file = new QPopupMenu; | 82 | QPopupMenu* file = new QPopupMenu; |
84 | file->insertItem(tr("Patience"), this, SLOT(initPatience())); | 83 | file->insertItem(tr("Patience"), this, SLOT(initPatience())); |
85 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); | 84 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); |
86 | file->insertItem(tr("Chicane"), this, SLOT(initChicane())); | 85 | file->insertItem(tr("Chicane"), this, SLOT(initChicane())); |
87 | file->insertItem(tr("Harp"), this, SLOT(initHarp())); | 86 | file->insertItem(tr("Harp"), this, SLOT(initHarp())); |
88 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); | 87 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); |
89 | menu->insertItem(tr("Play"), file); | 88 | menu->insertItem(tr("Play"), file); |
90 | 89 | ||
91 | menu->insertSeparator(); | 90 | menu->insertSeparator(); |
92 | 91 | ||
93 | settings = new QPopupMenu; | 92 | settings = new QPopupMenu; |
94 | settings->setCheckable(TRUE); | 93 | settings->setCheckable(TRUE); |
95 | settings->insertItem(tr("Change card backs"), this, SLOT(changeCardBacks())); | 94 | settings->insertItem(tr("Change card backs"), this, SLOT(changeCardBacks())); |
96 | snap_id = settings->insertItem(tr("Snap to position"), this, SLOT(snapToggle())); | 95 | snap_id = settings->insertItem(tr("Snap to position"), this, SLOT(snapToggle())); |
97 | QString m; | 96 | QString m; |
98 | 97 | ||
99 | drawId = settings->insertItem(tr("Turn one card"), this, SLOT(drawnToggle())); | 98 | drawId = settings->insertItem(tr("Turn one card"), this, SLOT(drawnToggle())); |
100 | menu->insertItem(tr("Settings"),settings); | 99 | menu->insertItem(tr("Settings"),settings); |
101 | settings->setCheckable(TRUE); | 100 | settings->setCheckable(TRUE); |
102 | 101 | ||
103 | #endif | 102 | #endif |
104 | 103 | ||
105 | menu->show(); | 104 | menu->show(); |
106 | 105 | ||
107 | Config cfg( "Patience" ); | 106 | Config cfg( "Patience" ); |
108 | cfg.setGroup( "GlobalSettings" ); | 107 | cfg.setGroup( "GlobalSettings" ); |
109 | snapOn = cfg.readBoolEntry( "SnapOn", TRUE); | 108 | snapOn = cfg.readBoolEntry( "SnapOn", TRUE); |
110 | settings->setItemChecked(snap_id, snapOn); | 109 | settings->setItemChecked(snap_id, snapOn); |
111 | 110 | ||
112 | gameType = cfg.readNumEntry( "GameType", -1 ); | 111 | gameType = cfg.readNumEntry( "GameType", -1 ); |
113 | drawThree = cfg.readBoolEntry( "DrawThree", FALSE); | 112 | drawThree = cfg.readBoolEntry( "DrawThree", FALSE); |
114 | if ( gameType == 0 ) { | 113 | if ( gameType == 0 ) { |
115 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | 114 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); |
116 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | 115 | cardGame->setNumberToDraw(drawThree ? 3 : 1); |
117 | 116 | ||
118 | setCaption(tr("Patience")); | 117 | setCaption(tr("Patience")); |
119 | setCentralWidget(cardGame); | 118 | setCentralWidget(cardGame); |
120 | cardGame->readConfig( cfg ); | 119 | cardGame->readConfig( cfg ); |
121 | setCardBacks(); | 120 | setCardBacks(); |
122 | } else if ( gameType == 1 ) { | 121 | } else if ( gameType == 1 ) { |
123 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | 122 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); |
124 | setCaption(tr("Freecell")); | 123 | setCaption(tr("Freecell")); |
125 | setCentralWidget(cardGame); | 124 | setCentralWidget(cardGame); |
126 | //cardGame->newGame(); // Until we know how to handle reading freecell config | 125 | //cardGame->newGame(); // Until we know how to handle reading freecell config |
127 | cardGame->readConfig( cfg ); | 126 | cardGame->readConfig( cfg ); |
128 | setCardBacks(); | 127 | setCardBacks(); |
129 | } else if ( gameType == 2 ) { | 128 | } else if ( gameType == 2 ) { |
130 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); | 129 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); |
131 | cardGame->setNumberToDraw(1); | 130 | cardGame->setNumberToDraw(1); |
132 | setCaption(tr("Chicane")); | 131 | setCaption(tr("Chicane")); |
133 | setCentralWidget(cardGame); | 132 | setCentralWidget(cardGame); |
134 | cardGame->readConfig( cfg ); | 133 | cardGame->readConfig( cfg ); |
135 | setCardBacks(); | 134 | setCardBacks(); |
136 | } else if ( gameType == 3 ) { | 135 | } else if ( gameType == 3 ) { |
137 | cardGame = new HarpCardGame( &canvas, snapOn, this ); | 136 | cardGame = new HarpCardGame( &canvas, snapOn, this ); |
138 | cardGame->setNumberToDraw(1); | 137 | cardGame->setNumberToDraw(1); |
139 | setCaption(tr("Harp")); | 138 | setCaption(tr("Harp")); |
140 | setCentralWidget(cardGame); | 139 | setCentralWidget(cardGame); |
141 | cardGame->readConfig( cfg ); | 140 | cardGame->readConfig( cfg ); |
142 | setCardBacks(); | 141 | setCardBacks(); |
143 | } else if ( gameType == 4 ) { | 142 | } else if ( gameType == 4 ) { |
144 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); | 143 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); |
145 | cardGame->setNumberToDraw(1); | 144 | cardGame->setNumberToDraw(1); |
146 | setCaption(tr("Teeclub")); | 145 | setCaption(tr("Teeclub")); |
147 | setCentralWidget(cardGame); | 146 | setCentralWidget(cardGame); |
148 | cardGame->readConfig( cfg ); | 147 | cardGame->readConfig( cfg ); |
149 | setCardBacks(); | 148 | setCardBacks(); |
150 | } else { | 149 | } else { |
151 | // Probably there isn't a config file or it is broken | 150 | // Probably there isn't a config file or it is broken |
152 | // Start a new game | 151 | // Start a new game |
153 | initPatience(); | 152 | initPatience(); |
154 | } | 153 | } |
155 | 154 | ||
156 | updateDraw(); | 155 | updateDraw(); |
157 | } | 156 | } |
158 | 157 | ||
159 | 158 | ||
160 | CanvasCardWindow::~CanvasCardWindow() | 159 | CanvasCardWindow::~CanvasCardWindow() |
161 | { | 160 | { |
162 | if (cardGame) { | 161 | if (cardGame) { |
163 | Config cfg("Patience"); | 162 | Config cfg("Patience"); |
164 | cfg.setGroup( "GlobalSettings" ); | 163 | cfg.setGroup( "GlobalSettings" ); |
165 | cfg.writeEntry( "GameType", gameType ); | 164 | cfg.writeEntry( "GameType", gameType ); |
166 | cfg.writeEntry( "SnapOn", snapOn ); | 165 | cfg.writeEntry( "SnapOn", snapOn ); |
167 | cfg.writeEntry( "DrawThree", drawThree); | 166 | cfg.writeEntry( "DrawThree", drawThree); |
168 | cfg.write(); | 167 | cfg.write(); |
169 | cardGame->writeConfig( cfg ); | 168 | cardGame->writeConfig( cfg ); |
170 | delete cardGame; | 169 | delete cardGame; |
171 | } | 170 | } |
172 | } | 171 | } |
173 | 172 | ||
174 | 173 | ||
175 | void CanvasCardWindow::resizeEvent(QResizeEvent *) | 174 | void CanvasCardWindow::resizeEvent(QResizeEvent *) |
176 | { | 175 | { |
177 | QSize s = centralWidget()->size(); | 176 | QSize s = centralWidget()->size(); |
178 | int fw = style().defaultFrameWidth(); | 177 | int fw = style().defaultFrameWidth(); |
179 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 178 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
183 | void CanvasCardWindow::initPatience() | 182 | void CanvasCardWindow::initPatience() |
184 | { | 183 | { |
185 | // Create New Game | 184 | // Create New Game |
186 | if ( cardGame ) | 185 | if ( cardGame ) |
187 | delete cardGame; | 186 | delete cardGame; |
188 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | 187 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); |
189 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | 188 | cardGame->setNumberToDraw(drawThree ? 3 : 1); |
190 | gameType = 0; | 189 | gameType = 0; |
191 | setCaption(tr("Patience")); | 190 | setCaption(tr("Patience")); |
192 | setCentralWidget(cardGame); | 191 | setCentralWidget(cardGame); |
193 | cardGame->newGame(); | 192 | cardGame->newGame(); |
194 | setCardBacks(); | 193 | setCardBacks(); |
195 | updateDraw(); | 194 | updateDraw(); |
196 | } | 195 | } |
197 | 196 | ||
198 | 197 | ||
199 | void CanvasCardWindow::initFreecell() | 198 | void CanvasCardWindow::initFreecell() |
200 | { | 199 | { |
201 | // Create New Game | 200 | // Create New Game |
202 | if ( cardGame ) { | 201 | if ( cardGame ) { |
203 | delete cardGame; | 202 | delete cardGame; |
204 | } | 203 | } |
205 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | 204 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); |
206 | gameType = 1; | 205 | gameType = 1; |
207 | setCaption(tr("Freecell")); | 206 | setCaption(tr("Freecell")); |
208 | setCentralWidget(cardGame); | 207 | setCentralWidget(cardGame); |
209 | cardGame->newGame(); | 208 | cardGame->newGame(); |
210 | setCardBacks(); | 209 | setCardBacks(); |
211 | } | 210 | } |
212 | 211 | ||
213 | 212 | ||
214 | void CanvasCardWindow::initChicane() | 213 | void CanvasCardWindow::initChicane() |
215 | { | 214 | { |
216 | // Create New Game | 215 | // Create New Game |
217 | if ( cardGame ) { | 216 | if ( cardGame ) { |
218 | delete cardGame; | 217 | delete cardGame; |
219 | } | 218 | } |
220 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); | 219 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); |
221 | cardGame->setNumberToDraw(1); | 220 | cardGame->setNumberToDraw(1); |
222 | gameType = 2; | 221 | gameType = 2; |
223 | setCaption(tr("Chicane")); | 222 | setCaption(tr("Chicane")); |
224 | setCentralWidget(cardGame); | 223 | setCentralWidget(cardGame); |
225 | cardGame->newGame(); | 224 | cardGame->newGame(); |
226 | setCardBacks(); | 225 | setCardBacks(); |
227 | } | 226 | } |
228 | 227 | ||
229 | void CanvasCardWindow::initHarp() | 228 | void CanvasCardWindow::initHarp() |
230 | { | 229 | { |
231 | // Create New Game | 230 | // Create New Game |
232 | if ( cardGame ) { | 231 | if ( cardGame ) { |
233 | delete cardGame; | 232 | delete cardGame; |
234 | } | 233 | } |
235 | cardGame = new HarpCardGame( &canvas, snapOn, this ); | 234 | cardGame = new HarpCardGame( &canvas, snapOn, this ); |
236 | cardGame->setNumberToDraw(1); | 235 | cardGame->setNumberToDraw(1); |
237 | gameType = 3; | 236 | gameType = 3; |
238 | setCaption(tr("Harp")); | 237 | setCaption(tr("Harp")); |
239 | setCentralWidget(cardGame); | 238 | setCentralWidget(cardGame); |
240 | cardGame->newGame(); | 239 | cardGame->newGame(); |
241 | setCardBacks(); | 240 | setCardBacks(); |
242 | } | 241 | } |
243 | 242 | ||
244 | 243 | ||
245 | void CanvasCardWindow::initTeeclub() | 244 | void CanvasCardWindow::initTeeclub() |
246 | { | 245 | { |
247 | // Create New Game | 246 | // Create New Game |
248 | if ( cardGame ) { | 247 | if ( cardGame ) { |
249 | delete cardGame; | 248 | delete cardGame; |
250 | } | 249 | } |
251 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); | 250 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); |
252 | cardGame->setNumberToDraw(1); | 251 | cardGame->setNumberToDraw(1); |
253 | gameType = 4; | 252 | gameType = 4; |
254 | setCaption(tr("Teeclub")); | 253 | setCaption(tr("Teeclub")); |
255 | setCentralWidget(cardGame); | 254 | setCentralWidget(cardGame); |
256 | cardGame->newGame(); | 255 | cardGame->newGame(); |
257 | setCardBacks(); | 256 | setCardBacks(); |
258 | } | 257 | } |
259 | 258 | ||
260 | 259 | ||
261 | void CanvasCardWindow::snapToggle() | 260 | void CanvasCardWindow::snapToggle() |
262 | { | 261 | { |
263 | snapOn = !snapOn; | 262 | snapOn = !snapOn; |
264 | settings->setItemChecked(snap_id, snapOn); | 263 | settings->setItemChecked(snap_id, snapOn); |
265 | cardGame->toggleSnap(); | 264 | cardGame->toggleSnap(); |
266 | } | 265 | } |
267 | 266 | ||
268 | 267 | ||
269 | void CanvasCardWindow::drawnToggle() | 268 | void CanvasCardWindow::drawnToggle() |
270 | { | 269 | { |
271 | drawThree=!drawThree; | 270 | drawThree=!drawThree; |
272 | Config cfg( "Patience" ); | 271 | Config cfg( "Patience" ); |
273 | cfg.setGroup( "GlobalSettings" ); | 272 | cfg.setGroup( "GlobalSettings" ); |
274 | cardGame->toggleCardsDrawn(); | 273 | cardGame->toggleCardsDrawn(); |
275 | updateDraw(); | 274 | updateDraw(); |
276 | cfg.writeEntry( "DrawThree", drawThree); | 275 | cfg.writeEntry( "DrawThree", drawThree); |
277 | cfg.write(); | 276 | cfg.write(); |
278 | } | 277 | } |
279 | 278 | ||
280 | void CanvasCardWindow::updateDraw() { | 279 | void CanvasCardWindow::updateDraw() { |
281 | if(cardGame->cardsDrawn() == 3){ | 280 | if(cardGame->cardsDrawn() == 3){ |
282 | settings->changeItem(drawId, tr("Turn one card")); | 281 | settings->changeItem(drawId, tr("Turn one card")); |
283 | } else { | 282 | } else { |
284 | settings->changeItem(drawId, tr("Turn three cards")); | 283 | settings->changeItem(drawId, tr("Turn three cards")); |
285 | } | 284 | } |
286 | } | 285 | } |
287 | 286 | ||
288 | 287 | ||
289 | void CanvasCardWindow::setCardBacks() | 288 | void CanvasCardWindow::setCardBacks() |
290 | { | 289 | { |
291 | QCanvasItemList l = canvas.allItems(); | 290 | QCanvasItemList l = canvas.allItems(); |
292 | 291 | ||
293 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 292 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
294 | if ( (*it)->rtti() == canvasCardId ) | 293 | if ( (*it)->rtti() == canvasCardId ) |
295 | ((CanvasCard *)(*it))->setCardBack( cardBack ); | 294 | ((CanvasCard *)(*it))->setCardBack( cardBack ); |
296 | } | 295 | } |
297 | } | 296 | } |
298 | 297 | ||
299 | 298 | ||
300 | void CanvasCardWindow::changeCardBacks() | 299 | void CanvasCardWindow::changeCardBacks() |
301 | { | 300 | { |
302 | cardBack++; | 301 | cardBack++; |
303 | 302 | ||
304 | if (cardBack == 5) | 303 | if (cardBack == 5) |
305 | cardBack = 0; | 304 | cardBack = 0; |
306 | 305 | ||
307 | setCardBacks(); | 306 | setCardBacks(); |
308 | } | 307 | } |
309 | 308 | ||
310 | 309 | ||
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp index a6a5f34..d949176 100644 --- a/noncore/games/tetrix/qtetrix.cpp +++ b/noncore/games/tetrix/qtetrix.cpp | |||
@@ -1,208 +1,208 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "qtetrix.h" | 22 | #include "qtetrix.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <opie2/oresource.h> |
25 | 25 | ||
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qtimer.h> | 29 | #include <qtimer.h> |
30 | 30 | ||
31 | #include "ohighscoredlg.h" | 31 | #include "ohighscoredlg.h" |
32 | 32 | ||
33 | 33 | ||
34 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, | 34 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, |
35 | const QColor *color ) | 35 | const QColor *color ) |
36 | { | 36 | { |
37 | QColor fc; | 37 | QColor fc; |
38 | if ( color ) { | 38 | if ( color ) { |
39 | QPointArray a; | 39 | QPointArray a; |
40 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); | 40 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); |
41 | p->setPen( color->light() ); | 41 | p->setPen( color->light() ); |
42 | p->drawPolyline( a ); | 42 | p->drawPolyline( a ); |
43 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); | 43 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); |
44 | p->setPen( color->dark() ); | 44 | p->setPen( color->dark() ); |
45 | p->drawPolyline( a ); | 45 | p->drawPolyline( a ); |
46 | x++; | 46 | x++; |
47 | y++; | 47 | y++; |
48 | w -= 2; | 48 | w -= 2; |
49 | h -= 2; | 49 | h -= 2; |
50 | fc = *color; | 50 | fc = *color; |
51 | } | 51 | } |
52 | else | 52 | else |
53 | fc = p->backgroundColor(); | 53 | fc = p->backgroundColor(); |
54 | p->fillRect( x, y, w, h, fc ); | 54 | p->fillRect( x, y, w, h, fc ); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) | 58 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) |
59 | : QFrame( parent, name ) | 59 | : QFrame( parent, name ) |
60 | { | 60 | { |
61 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 61 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
62 | xOffset = -1; // -1 until first resizeEvent. | 62 | xOffset = -1; // -1 until first resizeEvent. |
63 | } | 63 | } |
64 | 64 | ||
65 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) | 65 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) |
66 | { | 66 | { |
67 | QSize sz = e->size(); | 67 | QSize sz = e->size(); |
68 | blockWidth = (sz.width() - 3)/5; | 68 | blockWidth = (sz.width() - 3)/5; |
69 | blockHeight = (sz.height() - 3)/6; | 69 | blockHeight = (sz.height() - 3)/6; |
70 | xOffset = (sz.width() - 3)/5; | 70 | xOffset = (sz.width() - 3)/5; |
71 | yOffset = (sz.height() - 3)/6; | 71 | yOffset = (sz.height() - 3)/6; |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | void ShowNextPiece::paintEvent( QPaintEvent * ) | 75 | void ShowNextPiece::paintEvent( QPaintEvent * ) |
76 | { | 76 | { |
77 | QPainter p( this ); | 77 | QPainter p( this ); |
78 | drawFrame( &p ); | 78 | drawFrame( &p ); |
79 | p.end(); // explicit end() so any slots can paint too | 79 | p.end(); // explicit end() so any slots can paint too |
80 | emit update(); | 80 | emit update(); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) | 84 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) |
85 | { | 85 | { |
86 | if (xOffset == -1) // Before first resizeEvent? | 86 | if (xOffset == -1) // Before first resizeEvent? |
87 | return; | 87 | return; |
88 | 88 | ||
89 | QPainter paint; | 89 | QPainter paint; |
90 | paint.begin(this); | 90 | paint.begin(this); |
91 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, | 91 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, |
92 | blockWidth, blockHeight, color ); | 92 | blockWidth, blockHeight, color ); |
93 | paint.end(); | 93 | paint.end(); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) | 97 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) |
98 | : QMainWindow( parent, name, f ) | 98 | : QMainWindow( parent, name, f ) |
99 | { | 99 | { |
100 | setIcon( Resource::loadPixmap( "tetrix_icon" ) ); | 100 | setIcon( Opie::Core::OResource::loadPixmap( "tetrix_icon" ) ); |
101 | setCaption( tr("Tetrix" ) ); | 101 | setCaption( tr("Tetrix" ) ); |
102 | 102 | ||
103 | QTime t = QTime::currentTime(); | 103 | QTime t = QTime::currentTime(); |
104 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ | 104 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ |
105 | (24+60+60) ); | 105 | (24+60+60) ); |
106 | 106 | ||
107 | QWidget *gameArea = new QWidget( this ); | 107 | QWidget *gameArea = new QWidget( this ); |
108 | setCentralWidget( gameArea ); | 108 | setCentralWidget( gameArea ); |
109 | 109 | ||
110 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); | 110 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); |
111 | gl->setColStretch( 1, 5 ); | 111 | gl->setColStretch( 1, 5 ); |
112 | gl->setColStretch( 2, 10 ); | 112 | gl->setColStretch( 2, 10 ); |
113 | 113 | ||
114 | QLabel *l; | 114 | QLabel *l; |
115 | l = new QLabel( tr("Next"), gameArea ); | 115 | l = new QLabel( tr("Next"), gameArea ); |
116 | gl->addWidget( l, 0, 0 ); | 116 | gl->addWidget( l, 0, 0 ); |
117 | showNext = new ShowNextPiece(gameArea); | 117 | showNext = new ShowNextPiece(gameArea); |
118 | showNext->setBackgroundColor(QColor(0,0,0)); | 118 | showNext->setBackgroundColor(QColor(0,0,0)); |
119 | gl->addWidget( showNext, 0, 1 ); | 119 | gl->addWidget( showNext, 0, 1 ); |
120 | 120 | ||
121 | l = new QLabel( tr("Score"), gameArea ); | 121 | l = new QLabel( tr("Score"), gameArea ); |
122 | gl->addWidget( l, 1, 0 ); | 122 | gl->addWidget( l, 1, 0 ); |
123 | showScore = new QLabel(gameArea); | 123 | showScore = new QLabel(gameArea); |
124 | gl->addWidget( showScore, 1, 1 ); | 124 | gl->addWidget( showScore, 1, 1 ); |
125 | l = new QLabel( tr("Level"), gameArea ); | 125 | l = new QLabel( tr("Level"), gameArea ); |
126 | gl->addWidget( l, 2, 0 ); | 126 | gl->addWidget( l, 2, 0 ); |
127 | showLevel = new QLabel(gameArea); | 127 | showLevel = new QLabel(gameArea); |
128 | gl->addWidget( showLevel, 2, 1 ); | 128 | gl->addWidget( showLevel, 2, 1 ); |
129 | l = new QLabel( tr("Removed"), gameArea ); | 129 | l = new QLabel( tr("Removed"), gameArea ); |
130 | gl->addWidget( l, 3, 0 ); | 130 | gl->addWidget( l, 3, 0 ); |
131 | showLines = new QLabel(gameArea); | 131 | showLines = new QLabel(gameArea); |
132 | gl->addWidget( showLines, 3, 1 ); | 132 | gl->addWidget( showLines, 3, 1 ); |
133 | 133 | ||
134 | board = new QTetrixBoard(gameArea); | 134 | board = new QTetrixBoard(gameArea); |
135 | board->setBackgroundColor(QColor(0,0,0)); | 135 | board->setBackgroundColor(QColor(0,0,0)); |
136 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); | 136 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); |
137 | 137 | ||
138 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); | 138 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); |
139 | pb->setFocusPolicy( NoFocus ); | 139 | pb->setFocusPolicy( NoFocus ); |
140 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); | 140 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); |
141 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); | 141 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); |
142 | 142 | ||
143 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); | 143 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); |
144 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), this, | 144 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), this, |
145 | SLOT(setNext(int,int,QColor*)) ); | 145 | SLOT(setNext(int,int,QColor*)) ); |
146 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); | 146 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); |
147 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, SLOT(setNum(int)) ); | 147 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, SLOT(setNum(int)) ); |
148 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, SLOT(setNum(int)) ); | 148 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, SLOT(setNum(int)) ); |
149 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, SLOT(setNum(int)) ); | 149 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, SLOT(setNum(int)) ); |
150 | 150 | ||
151 | showScore->setNum( 0 ); | 151 | showScore->setNum( 0 ); |
152 | showLevel->setNum( 0 ); | 152 | showLevel->setNum( 0 ); |
153 | showLines->setNum( 0 ); | 153 | showLines->setNum( 0 ); |
154 | board->revealNextPiece(TRUE); | 154 | board->revealNextPiece(TRUE); |
155 | board->setFocusPolicy( StrongFocus ); | 155 | board->setFocusPolicy( StrongFocus ); |
156 | 156 | ||
157 | QTimer::singleShot( -1, this, SLOT(setup()) ); | 157 | QTimer::singleShot( -1, this, SLOT(setup()) ); |
158 | } | 158 | } |
159 | 159 | ||
160 | void QTetrix::setup() | 160 | void QTetrix::setup() |
161 | { | 161 | { |
162 | resizeEvent( 0x0 ); | 162 | resizeEvent( 0x0 ); |
163 | } | 163 | } |
164 | 164 | ||
165 | void QTetrix::gameOver() | 165 | void QTetrix::gameOver() |
166 | { | 166 | { |
167 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); | 167 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); |
168 | if ( hs->isNewhighscore ) | 168 | if ( hs->isNewhighscore ) |
169 | hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() ); | 169 | hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() ); |
170 | OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true ); | 170 | OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true ); |
171 | hscdlg.exec(); | 171 | hscdlg.exec(); |
172 | } | 172 | } |
173 | 173 | ||
174 | void QTetrix::quit() | 174 | void QTetrix::quit() |
175 | { | 175 | { |
176 | close(); | 176 | close(); |
177 | } | 177 | } |
178 | 178 | ||
179 | void QTetrix::setNext( int x, int y, QColor *color ) | 179 | void QTetrix::setNext( int x, int y, QColor *color ) |
180 | { | 180 | { |
181 | resizeEvent( 0x0 ); | 181 | resizeEvent( 0x0 ); |
182 | showNext->drawNextSquare( x, y, color ); | 182 | showNext->drawNextSquare( x, y, color ); |
183 | } | 183 | } |
184 | 184 | ||
185 | void QTetrix::resizeEvent( QResizeEvent * ) | 185 | void QTetrix::resizeEvent( QResizeEvent * ) |
186 | { | 186 | { |
187 | // Set size of board | 187 | // Set size of board |
188 | int widthFactor = board->QFrame::width() / board->boardWidth(); | 188 | int widthFactor = board->QFrame::width() / board->boardWidth(); |
189 | if ( widthFactor < 1 ) | 189 | if ( widthFactor < 1 ) |
190 | widthFactor = 1; | 190 | widthFactor = 1; |
191 | int heightFactor = board->QFrame::height() / board->boardHeight(); | 191 | int heightFactor = board->QFrame::height() / board->boardHeight(); |
192 | if ( heightFactor < 1 ) | 192 | if ( heightFactor < 1 ) |
193 | heightFactor = 1; | 193 | heightFactor = 1; |
194 | widthFactor > heightFactor ? board->resize( heightFactor * board->boardWidth() + 2, | 194 | widthFactor > heightFactor ? board->resize( heightFactor * board->boardWidth() + 2, |
195 | heightFactor * board->boardHeight() + 2 ) | 195 | heightFactor * board->boardHeight() + 2 ) |
196 | : board->resize( widthFactor * board->boardWidth() + 2, | 196 | : board->resize( widthFactor * board->boardWidth() + 2, |
197 | widthFactor * board->boardHeight() + 2 ); | 197 | widthFactor * board->boardHeight() + 2 ); |
198 | 198 | ||
199 | // Set size of preview widget | 199 | // Set size of preview widget |
200 | widthFactor = showNext->width() / 5; | 200 | widthFactor = showNext->width() / 5; |
201 | if ( widthFactor < 1 ) | 201 | if ( widthFactor < 1 ) |
202 | widthFactor = 1; | 202 | widthFactor = 1; |
203 | heightFactor = showNext->height() / 6; | 203 | heightFactor = showNext->height() / 6; |
204 | if ( heightFactor < 1 ) | 204 | if ( heightFactor < 1 ) |
205 | heightFactor = 1; | 205 | heightFactor = 1; |
206 | widthFactor > heightFactor ? showNext->resize( heightFactor * 5 + 2, heightFactor * 6 + 2 ) | 206 | widthFactor > heightFactor ? showNext->resize( heightFactor * 5 + 2, heightFactor * 6 + 2 ) |
207 | : showNext->resize( widthFactor * 5 + 2, widthFactor * 6 + 2 ); | 207 | : showNext->resize( widthFactor * 5 + 2, widthFactor * 6 + 2 ); |
208 | } | 208 | } |
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index 47d6725..52e2be2 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -1,1510 +1,1518 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "wordgame.h" | 22 | #include "wordgame.h" |
23 | 23 | ||
24 | #include <opie2/oresource.h> | ||
25 | |||
24 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
25 | #include <qpe/resource.h> | ||
26 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
27 | 28 | ||
28 | #include <qapplication.h> | 29 | #include <qapplication.h> |
29 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
30 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
31 | #include <qdir.h> | 32 | #include <qdir.h> |
32 | #include <qlineedit.h> | 33 | #include <qlineedit.h> |
33 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
34 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
35 | #include <qtimer.h> | 36 | #include <qtimer.h> |
36 | #include <qtoolbar.h> | 37 | #include <qtoolbar.h> |
37 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
38 | #include <qvbox.h> | 39 | #include <qvbox.h> |
39 | #include <qwidgetstack.h> | 40 | #include <qwidgetstack.h> |
40 | #include <qlayout.h> | 41 | #include <qlayout.h> |
41 | 42 | ||
42 | #include <stdlib.h> | 43 | #include <stdlib.h> |
43 | #include <unistd.h> | 44 | #include <unistd.h> |
44 | #include <pwd.h> | 45 | #include <pwd.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | 47 | ||
47 | enum RuleEffects { | 48 | enum RuleEffects { |
48 | Multiplier=15, | 49 | Multiplier=15, |
49 | MultiplyAll=64, | 50 | MultiplyAll=64, |
50 | Start=128 | 51 | Start=128 |
51 | }; | 52 | }; |
52 | 53 | ||
53 | static int tile_smallw = 16; | 54 | static int tile_smallw = 16; |
54 | static int tile_smallh = 16; | 55 | static int tile_smallh = 16; |
55 | static int tile_bigw = 22; | 56 | static int tile_bigw = 22; |
56 | static int tile_bigh = 22; | 57 | static int tile_bigh = 22; |
57 | static int tile_stweak = -2; | 58 | static int tile_stweak = -2; |
58 | static int tile_btweak = -1; | 59 | static int tile_btweak = -1; |
59 | 60 | ||
60 | static const int rack_tiles=7; | 61 | static const int rack_tiles=7; |
61 | 62 | ||
62 | const char* sampleWGR= | 63 | const char* sampleWGR= |
63 | "wordgame_shapes\n" | 64 | "wordgame_shapes\n" |
64 | "15 15\n" | 65 | "15 15\n" |
65 | "400001040100004\n" | 66 | "400001040100004\n" |
66 | "030000000000030\n" | 67 | "030000000000030\n" |
67 | "002002000200200\n" | 68 | "002002000200200\n" |
68 | "000300020003000\n" | 69 | "000300020003000\n" |
69 | "000020000020000\n" | 70 | "000020000020000\n" |
70 | "102001000100201\n" | 71 | "102001000100201\n" |
71 | "000000202000000\n" | 72 | "000000202000000\n" |
72 | "400200050002004\n" | 73 | "400200050002004\n" |
73 | "000000202000000\n" | 74 | "000000202000000\n" |
74 | "102001000100201\n" | 75 | "102001000100201\n" |
75 | "000020000020000\n" | 76 | "000020000020000\n" |
76 | "000300020003000\n" | 77 | "000300020003000\n" |
77 | "002002000200200\n" | 78 | "002002000200200\n" |
78 | "030000000000030\n" | 79 | "030000000000030\n" |
79 | "400001040100004\n" | 80 | "400001040100004\n" |
80 | "1 2 3 66 67 194 100 0\n" | 81 | "1 2 3 66 67 194 100 0\n" |
81 | "1 j 8\n" | 82 | "1 j 8\n" |
82 | "1 q 7\n" | 83 | "1 q 7\n" |
83 | "1 x 6\n" | 84 | "1 x 6\n" |
84 | "1 z 6\n" | 85 | "1 z 6\n" |
85 | "1 w 4\n" | 86 | "1 w 4\n" |
86 | "1 k 4\n" | 87 | "1 k 4\n" |
87 | "1 v 3\n" | 88 | "1 v 3\n" |
88 | "1 f 3\n" | 89 | "1 f 3\n" |
89 | "2 y 3\n" | 90 | "2 y 3\n" |
90 | "2 h 2\n" | 91 | "2 h 2\n" |
91 | "2 b 2\n" | 92 | "2 b 2\n" |
92 | "2 m 2\n" | 93 | "2 m 2\n" |
93 | "3 p 2\n" | 94 | "3 p 2\n" |
94 | "3 g 2\n" | 95 | "3 g 2\n" |
95 | "3 u 2\n" | 96 | "3 u 2\n" |
96 | "4 d 2\n" | 97 | "4 d 2\n" |
97 | "4 c 2\n" | 98 | "4 c 2\n" |
98 | "5 l 1\n" | 99 | "5 l 1\n" |
99 | "5 o 1\n" | 100 | "5 o 1\n" |
100 | "7 t 1\n" | 101 | "7 t 1\n" |
101 | "7 n 1\n" | 102 | "7 n 1\n" |
102 | "7 a 1\n" | 103 | "7 a 1\n" |
103 | "7 r 1\n" | 104 | "7 r 1\n" |
104 | "8 s 1\n" | 105 | "8 s 1\n" |
105 | "8 i 1\n" | 106 | "8 i 1\n" |
106 | "11 e 1\n" | 107 | "11 e 1\n" |
107 | "0\n"; | 108 | "0\n"; |
108 | 109 | ||
109 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 110 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
110 | QMainWindow(parent, name, fl) | 111 | QMainWindow(parent, name, fl) |
111 | { | 112 | { |
112 | if ( qApp->desktop()->width() < 240 ) { | 113 | if ( qApp->desktop()->width() < 240 ) { |
113 | tile_smallw = 10; | 114 | tile_smallw = 10; |
114 | tile_smallh = 10; | 115 | tile_smallh = 10; |
115 | tile_bigw = 16; | 116 | tile_bigw = 16; |
116 | tile_bigh = 16; | 117 | tile_bigh = 16; |
117 | tile_stweak = 0; | 118 | tile_stweak = 0; |
118 | tile_btweak = 0; | 119 | tile_btweak = 0; |
119 | } | 120 | } |
120 | 121 | ||
121 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); | 122 | setIcon( Opie::Core::OResource::loadPixmap( "wordgame/WordGame" ) ); |
122 | setCaption( tr("Word Game") ); | 123 | setCaption( tr("Word Game") ); |
123 | 124 | ||
124 | setToolBarsMovable( FALSE ); | 125 | setToolBarsMovable( FALSE ); |
125 | vbox = new QVBox(this); | 126 | vbox = new QVBox(this); |
126 | 127 | ||
127 | setCentralWidget(vbox); | 128 | setCentralWidget(vbox); |
128 | toolbar = new QToolBar(this); | 129 | toolbar = new QToolBar(this); |
129 | addToolBar(toolbar, Bottom); | 130 | addToolBar(toolbar, Bottom); |
130 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); | 131 | bool useBigIcon = qApp->desktop()->size().width() > 330; |
131 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); | 132 | reset = new QToolButton(Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon), |
133 | tr("Back"), "", this, SLOT(resetTurn()), toolbar); | ||
134 | reset->setUsesBigPixmap( useBigIcon ); | ||
135 | done = new QToolButton(Opie::Core::OResource::loadPixmap("done", Opie::Core::OResource::SmallIcon), | ||
136 | tr("Done"), "", this, SLOT(endTurn()), toolbar); | ||
137 | done->setUsesBigPixmap( useBigIcon ); | ||
132 | scoreinfo = new ScoreInfo(toolbar); | 138 | scoreinfo = new ScoreInfo(toolbar); |
133 | scoreinfo->setFont(QFont("Helvetica",10)); | 139 | scoreinfo->setFont(QFont("Helvetica",10)); |
134 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); | 140 | QToolButton *btn = new QToolButton(Opie::Core::OResource::loadPixmap("finish", Opie::Core::OResource::SmallIcon), |
141 | tr("Close"), "", this, SLOT(endGame()), toolbar); | ||
142 | btn->setUsesBigPixmap( useBigIcon ); | ||
135 | toolbar->setStretchableWidget(scoreinfo); | 143 | toolbar->setStretchableWidget(scoreinfo); |
136 | 144 | ||
137 | cpu = 0; | 145 | cpu = 0; |
138 | board = 0; | 146 | board = 0; |
139 | bag = 0; | 147 | bag = 0; |
140 | racks = 0; | 148 | racks = 0; |
141 | 149 | ||
142 | aiheart = new QTimer(this); | 150 | aiheart = new QTimer(this); |
143 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); | 151 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); |
144 | 152 | ||
145 | readConfig(); | 153 | readConfig(); |
146 | } | 154 | } |
147 | 155 | ||
148 | WordGame::~WordGame() | 156 | WordGame::~WordGame() |
149 | { | 157 | { |
150 | writeConfig(); | 158 | writeConfig(); |
151 | } | 159 | } |
152 | 160 | ||
153 | void WordGame::writeConfig() | 161 | void WordGame::writeConfig() |
154 | { | 162 | { |
155 | Config cfg("WordGame"); | 163 | Config cfg("WordGame"); |
156 | cfg.setGroup("Game"); | 164 | cfg.setGroup("Game"); |
157 | cfg.writeEntry("NameList",namelist,';'); | 165 | cfg.writeEntry("NameList",namelist,';'); |
158 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); | 166 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); |
159 | if ( !gameover ) { | 167 | if ( !gameover ) { |
160 | cfg.writeEntry("Rules",rules); | 168 | cfg.writeEntry("Rules",rules); |
161 | bag->writeConfig(cfg); | 169 | bag->writeConfig(cfg); |
162 | board->writeConfig(cfg); | 170 | board->writeConfig(cfg); |
163 | scoreinfo->writeConfig(cfg); | 171 | scoreinfo->writeConfig(cfg); |
164 | } | 172 | } |
165 | for (int p=0; p<nplayers; p++) { | 173 | for (int p=0; p<nplayers; p++) { |
166 | cfg.setGroup("Player"+QString::number(p+1)); | 174 | cfg.setGroup("Player"+QString::number(p+1)); |
167 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); | 175 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); |
168 | } | 176 | } |
169 | } | 177 | } |
170 | 178 | ||
171 | void WordGame::readConfig() | 179 | void WordGame::readConfig() |
172 | { | 180 | { |
173 | Config cfg("WordGame"); | 181 | Config cfg("WordGame"); |
174 | cfg.setGroup("Game"); | 182 | cfg.setGroup("Game"); |
175 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); | 183 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); |
176 | QStringList pnames = cfg.readListEntry("NameList",';'); | 184 | QStringList pnames = cfg.readListEntry("NameList",';'); |
177 | if ( currentplayer ) { | 185 | if ( currentplayer ) { |
178 | gameover = FALSE; | 186 | gameover = FALSE; |
179 | rules = cfg.readEntry("Rules"); | 187 | rules = cfg.readEntry("Rules"); |
180 | if ( rules.find("x-wordgamerules") >= 0 ) { | 188 | if ( rules.find("x-wordgamerules") >= 0 ) { |
181 | // rules files moved | 189 | // rules files moved |
182 | rules = "Sample.rules"; | 190 | rules = "Sample.rules"; |
183 | } | 191 | } |
184 | if ( loadRules(rules) ) { | 192 | if ( loadRules(rules) ) { |
185 | startGame(pnames); | 193 | startGame(pnames); |
186 | bag->readConfig(cfg); | 194 | bag->readConfig(cfg); |
187 | board->readConfig(cfg); | 195 | board->readConfig(cfg); |
188 | scoreinfo->readConfig(cfg); | 196 | scoreinfo->readConfig(cfg); |
189 | for (int p=0; p<nplayers; p++) { | 197 | for (int p=0; p<nplayers; p++) { |
190 | cfg.setGroup("Player"+QString::number(p+1)); | 198 | cfg.setGroup("Player"+QString::number(p+1)); |
191 | rack(p)->readConfig(cfg); | 199 | rack(p)->readConfig(cfg); |
192 | } | 200 | } |
193 | player=currentplayer-1; | 201 | player=currentplayer-1; |
194 | readyRack(player); | 202 | readyRack(player); |
195 | return; | 203 | return; |
196 | } | 204 | } |
197 | } | 205 | } |
198 | // fall-back | 206 | // fall-back |
199 | openGameSelector(pnames); | 207 | openGameSelector(pnames); |
200 | } | 208 | } |
201 | 209 | ||
202 | void WordGame::openGameSelector(const QStringList& initnames) | 210 | void WordGame::openGameSelector(const QStringList& initnames) |
203 | { | 211 | { |
204 | toolbar->hide(); | 212 | toolbar->hide(); |
205 | gameover = FALSE; | 213 | gameover = FALSE; |
206 | 214 | ||
207 | delete board; | 215 | delete board; |
208 | board = 0; | 216 | board = 0; |
209 | delete racks; | 217 | delete racks; |
210 | racks = 0; | 218 | racks = 0; |
211 | 219 | ||
212 | delete cpu; | 220 | delete cpu; |
213 | cpu = 0; | 221 | cpu = 0; |
214 | 222 | ||
215 | newgame = new NewGame(vbox); | 223 | newgame = new NewGame(vbox); |
216 | 224 | ||
217 | //Rules rules(this); | 225 | //Rules rules(this); |
218 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); | 226 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); |
219 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); | 227 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); |
220 | struct passwd* n = getpwuid(getuid()); | 228 | struct passwd* n = getpwuid(getuid()); |
221 | QString playername = n ? n->pw_name : ""; | 229 | QString playername = n ? n->pw_name : ""; |
222 | if ( playername.isEmpty() ) { | 230 | if ( playername.isEmpty() ) { |
223 | playername = "Player"; | 231 | playername = "Player"; |
224 | } | 232 | } |
225 | newgame->player0->changeItem(playername,0); | 233 | newgame->player0->changeItem(playername,0); |
226 | newgame->player1->setCurrentItem(1); | 234 | newgame->player1->setCurrentItem(1); |
227 | newgame->updateRuleSets(); | 235 | newgame->updateRuleSets(); |
228 | newgame->show(); | 236 | newgame->show(); |
229 | 237 | ||
230 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); | 238 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); |
231 | } | 239 | } |
232 | 240 | ||
233 | void WordGame::startGame() | 241 | void WordGame::startGame() |
234 | { | 242 | { |
235 | rules = newgame->ruleslist[newgame->rules->currentItem()]; | 243 | rules = newgame->ruleslist[newgame->rules->currentItem()]; |
236 | if ( loadRules(rules) ) { | 244 | if ( loadRules(rules) ) { |
237 | QStringList names; | 245 | QStringList names; |
238 | names.append(newgame->player0->currentText()); | 246 | names.append(newgame->player0->currentText()); |
239 | names.append(newgame->player1->currentText()); | 247 | names.append(newgame->player1->currentText()); |
240 | names.append(newgame->player2->currentText()); | 248 | names.append(newgame->player2->currentText()); |
241 | names.append(newgame->player3->currentText()); | 249 | names.append(newgame->player3->currentText()); |
242 | names.append(newgame->player4->currentText()); | 250 | names.append(newgame->player4->currentText()); |
243 | names.append(newgame->player5->currentText()); | 251 | names.append(newgame->player5->currentText()); |
244 | delete newgame; | 252 | delete newgame; |
245 | startGame(names); | 253 | startGame(names); |
246 | } else { | 254 | } else { |
247 | // error... | 255 | // error... |
248 | delete newgame; | 256 | delete newgame; |
249 | close(); | 257 | close(); |
250 | } | 258 | } |
251 | } | 259 | } |
252 | 260 | ||
253 | void WordGame::startGame(const QStringList& playerlist) | 261 | void WordGame::startGame(const QStringList& playerlist) |
254 | { | 262 | { |
255 | toolbar->show(); | 263 | toolbar->show(); |
256 | racks = new QWidgetStack(vbox); | 264 | racks = new QWidgetStack(vbox); |
257 | racks->setFixedHeight(TileItem::bigHeight()+2); | 265 | racks->setFixedHeight(TileItem::bigHeight()+2); |
258 | namelist.clear(); | 266 | namelist.clear(); |
259 | nplayers=0; | 267 | nplayers=0; |
260 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 268 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
261 | addPlayer(*it); | 269 | addPlayer(*it); |
262 | scoreinfo->init(namelist); | 270 | scoreinfo->init(namelist); |
263 | 271 | ||
264 | if ( nplayers ) { | 272 | if ( nplayers ) { |
265 | player=0; | 273 | player=0; |
266 | readyRack(player); | 274 | readyRack(player); |
267 | } | 275 | } |
268 | 276 | ||
269 | board->show(); | 277 | board->show(); |
270 | racks->show(); | 278 | racks->show(); |
271 | } | 279 | } |
272 | 280 | ||
273 | bool WordGame::loadRules(const QString &name) | 281 | bool WordGame::loadRules(const QString &name) |
274 | { | 282 | { |
275 | QString filename = Global::applicationFileName( "wordgame", name ); | 283 | QString filename = Global::applicationFileName( "wordgame", name ); |
276 | QFile file( filename ); | 284 | QFile file( filename ); |
277 | if ( !file.open( IO_ReadOnly ) ) | 285 | if ( !file.open( IO_ReadOnly ) ) |
278 | return FALSE; | 286 | return FALSE; |
279 | 287 | ||
280 | QTextStream ts( &file ); | 288 | QTextStream ts( &file ); |
281 | 289 | ||
282 | QString title = name; | 290 | QString title = name; |
283 | title.truncate( title.length() - 6 ); | 291 | title.truncate( title.length() - 6 ); |
284 | //setCaption( title ); | 292 | //setCaption( title ); |
285 | 293 | ||
286 | QString shapepixmap; | 294 | QString shapepixmap; |
287 | ts >> shapepixmap; | 295 | ts >> shapepixmap; |
288 | int htiles,vtiles; | 296 | int htiles,vtiles; |
289 | ts >> htiles >> vtiles; | 297 | ts >> htiles >> vtiles; |
290 | 298 | ||
291 | if ( htiles < 3 || vtiles < 3 ) | 299 | if ( htiles < 3 || vtiles < 3 ) |
292 | return FALSE; | 300 | return FALSE; |
293 | 301 | ||
294 | QString rule_shapes; | 302 | QString rule_shapes; |
295 | for (int i=0; i<vtiles; i++) { | 303 | for (int i=0; i<vtiles; i++) { |
296 | QString line; | 304 | QString line; |
297 | ts >> line; | 305 | ts >> line; |
298 | rule_shapes += line; | 306 | rule_shapes += line; |
299 | } | 307 | } |
300 | static int rule_effects[12]; | 308 | static int rule_effects[12]; |
301 | int re=0,e; | 309 | int re=0,e; |
302 | ts >> e; | 310 | ts >> e; |
303 | while ( e && re < 10 ) { | 311 | while ( e && re < 10 ) { |
304 | rule_effects[re] = e; | 312 | rule_effects[re] = e; |
305 | if ( re++ < 10 ) ts >> e; | 313 | if ( re++ < 10 ) ts >> e; |
306 | } | 314 | } |
307 | 315 | ||
308 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); | 316 | QImage shim = Opie::Core::OResource::loadImage("wordgame/wordgame_shapes"); |
309 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | 317 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); |
310 | QPixmap bgshapes; | 318 | QPixmap bgshapes; |
311 | bgshapes.convertFromImage(shim); | 319 | bgshapes.convertFromImage(shim); |
312 | 320 | ||
313 | rule_effects[re++] = 100; // default bonus | 321 | rule_effects[re++] = 100; // default bonus |
314 | board = new Board(bgshapes, htiles, vtiles, vbox); | 322 | board = new Board(bgshapes, htiles, vtiles, vbox); |
315 | board->setRules(rule_shapes, rule_effects); | 323 | board->setRules(rule_shapes, rule_effects); |
316 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 324 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
317 | 325 | ||
318 | bag = new Bag; | 326 | bag = new Bag; |
319 | 327 | ||
320 | int count; | 328 | int count; |
321 | ts >> count; | 329 | ts >> count; |
322 | while ( count ) { | 330 | while ( count ) { |
323 | QString text; | 331 | QString text; |
324 | int value; | 332 | int value; |
325 | ts >> text >> value; | 333 | ts >> text >> value; |
326 | if ( text == "_" ) | 334 | if ( text == "_" ) |
327 | text = ""; | 335 | text = ""; |
328 | 336 | ||
329 | Tile t(text, value); | 337 | Tile t(text, value); |
330 | for (int n=count; n--; ) | 338 | for (int n=count; n--; ) |
331 | bag->add(t); | 339 | bag->add(t); |
332 | 340 | ||
333 | ts >> count; | 341 | ts >> count; |
334 | } | 342 | } |
335 | 343 | ||
336 | return TRUE; | 344 | return TRUE; |
337 | } | 345 | } |
338 | 346 | ||
339 | 347 | ||
340 | NewGame::NewGame(QWidget* parent) : | 348 | NewGame::NewGame(QWidget* parent) : |
341 | NewGameBase(parent) | 349 | NewGameBase(parent) |
342 | { | 350 | { |
343 | } | 351 | } |
344 | 352 | ||
345 | void NewGame::updateRuleSets() | 353 | void NewGame::updateRuleSets() |
346 | { | 354 | { |
347 | rules->clear(); | 355 | rules->clear(); |
348 | 356 | ||
349 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); | 357 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); |
350 | QDir dir( rulesDir, "*.rules" ); | 358 | QDir dir( rulesDir, "*.rules" ); |
351 | ruleslist = dir.entryList(); | 359 | ruleslist = dir.entryList(); |
352 | if ( ruleslist.isEmpty() ) { | 360 | if ( ruleslist.isEmpty() ) { |
353 | // Provide a sample | 361 | // Provide a sample |
354 | QFile file( rulesDir + "Sample.rules" ); | 362 | QFile file( rulesDir + "Sample.rules" ); |
355 | if ( file.open( IO_WriteOnly ) ) { | 363 | if ( file.open( IO_WriteOnly ) ) { |
356 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); | 364 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); |
357 | file.close(); | 365 | file.close(); |
358 | updateRuleSets(); | 366 | updateRuleSets(); |
359 | } | 367 | } |
360 | return; | 368 | return; |
361 | } | 369 | } |
362 | int newest=0; | 370 | int newest=0; |
363 | int newest_age=INT_MAX; | 371 | int newest_age=INT_MAX; |
364 | QDateTime now = QDateTime::currentDateTime(); | 372 | QDateTime now = QDateTime::currentDateTime(); |
365 | QStringList::Iterator it; | 373 | QStringList::Iterator it; |
366 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { | 374 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { |
367 | QFileInfo fi((*it)); | 375 | QFileInfo fi((*it)); |
368 | int age = fi.lastModified().secsTo(now); | 376 | int age = fi.lastModified().secsTo(now); |
369 | QString name = *it; | 377 | QString name = *it; |
370 | name.truncate( name.length()-6 ); // remove extension | 378 | name.truncate( name.length()-6 ); // remove extension |
371 | rules->insertItem( name ); | 379 | rules->insertItem( name ); |
372 | if ( age < newest_age ) { | 380 | if ( age < newest_age ) { |
373 | newest_age = age; | 381 | newest_age = age; |
374 | newest = rules->count()-1; | 382 | newest = rules->count()-1; |
375 | } | 383 | } |
376 | } | 384 | } |
377 | rules->setCurrentItem(newest); | 385 | rules->setCurrentItem(newest); |
378 | } | 386 | } |
379 | 387 | ||
380 | Rules::Rules(QWidget* parent) : | 388 | Rules::Rules(QWidget* parent) : |
381 | RulesBase(parent,0,TRUE) | 389 | RulesBase(parent,0,TRUE) |
382 | { | 390 | { |
383 | } | 391 | } |
384 | 392 | ||
385 | void Rules::editRules() | 393 | void Rules::editRules() |
386 | { | 394 | { |
387 | if ( exec() ) { | 395 | if ( exec() ) { |
388 | // ### create a new set of rules | 396 | // ### create a new set of rules |
389 | emit rulesChanged(); | 397 | emit rulesChanged(); |
390 | } | 398 | } |
391 | } | 399 | } |
392 | 400 | ||
393 | void Rules::deleteRuleSet() | 401 | void Rules::deleteRuleSet() |
394 | { | 402 | { |
395 | // ### delete existing rule set | 403 | // ### delete existing rule set |
396 | emit rulesChanged(); | 404 | emit rulesChanged(); |
397 | } | 405 | } |
398 | 406 | ||
399 | void WordGame::addPlayer(const QString& name) | 407 | void WordGame::addPlayer(const QString& name) |
400 | { | 408 | { |
401 | if ( !name.isEmpty() ) { | 409 | if ( !name.isEmpty() ) { |
402 | int colon = name.find(':'); | 410 | int colon = name.find(':'); |
403 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; | 411 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; |
404 | addPlayer(name,cpu); | 412 | addPlayer(name,cpu); |
405 | } | 413 | } |
406 | } | 414 | } |
407 | 415 | ||
408 | void WordGame::addPlayer(const QString& name, int cpu) | 416 | void WordGame::addPlayer(const QString& name, int cpu) |
409 | { | 417 | { |
410 | Rack* r = new Rack(rack_tiles,racks); | 418 | Rack* r = new Rack(rack_tiles,racks); |
411 | r->setPlayerName(name); | 419 | r->setPlayerName(name); |
412 | r->setComputerization(cpu); | 420 | r->setComputerization(cpu); |
413 | racks->addWidget(r, nplayers); | 421 | racks->addWidget(r, nplayers); |
414 | refillRack(nplayers); | 422 | refillRack(nplayers); |
415 | namelist.append(name); | 423 | namelist.append(name); |
416 | 424 | ||
417 | ++nplayers; | 425 | ++nplayers; |
418 | } | 426 | } |
419 | 427 | ||
420 | void WordGame::nextPlayer() | 428 | void WordGame::nextPlayer() |
421 | { | 429 | { |
422 | if ( !refillRack(player) ) { | 430 | if ( !refillRack(player) ) { |
423 | endGame(); | 431 | endGame(); |
424 | } else { | 432 | } else { |
425 | player = (player+1)%nplayers; | 433 | player = (player+1)%nplayers; |
426 | scoreinfo->setBoldOne(player); | 434 | scoreinfo->setBoldOne(player); |
427 | readyRack(player); | 435 | readyRack(player); |
428 | } | 436 | } |
429 | } | 437 | } |
430 | 438 | ||
431 | bool WordGame::mayEndGame() | 439 | bool WordGame::mayEndGame() |
432 | { | 440 | { |
433 | int out=-1; | 441 | int out=-1; |
434 | int i; | 442 | int i; |
435 | for (i=0; i<nplayers; i++) | 443 | for (i=0; i<nplayers; i++) |
436 | if ( !rack(i)->count() ) | 444 | if ( !rack(i)->count() ) |
437 | out = i; | 445 | out = i; |
438 | if ( out<0 ) { | 446 | if ( out<0 ) { |
439 | if ( QMessageBox::warning(this,tr("End game"), | 447 | if ( QMessageBox::warning(this,tr("End game"), |
440 | tr("Do you want to end the game early?"), | 448 | tr("Do you want to end the game early?"), |
441 | tr("Yes"), tr("No") )!=0 ) | 449 | tr("Yes"), tr("No") )!=0 ) |
442 | { | 450 | { |
443 | return FALSE; | 451 | return FALSE; |
444 | } | 452 | } |
445 | } | 453 | } |
446 | return TRUE; | 454 | return TRUE; |
447 | } | 455 | } |
448 | 456 | ||
449 | void WordGame::endGame() | 457 | void WordGame::endGame() |
450 | { | 458 | { |
451 | if ( gameover ) { | 459 | if ( gameover ) { |
452 | close(); | 460 | close(); |
453 | return; | 461 | return; |
454 | } | 462 | } |
455 | 463 | ||
456 | if ( !mayEndGame() ) | 464 | if ( !mayEndGame() ) |
457 | return; | 465 | return; |
458 | int out=-1; | 466 | int out=-1; |
459 | int totalleft=0; | 467 | int totalleft=0; |
460 | int i; | 468 | int i; |
461 | for (i=0; i<nplayers; i++) { | 469 | for (i=0; i<nplayers; i++) { |
462 | Rack* r = rack(i); | 470 | Rack* r = rack(i); |
463 | int c = r->count(); | 471 | int c = r->count(); |
464 | if ( c ) { | 472 | if ( c ) { |
465 | int lose=0; | 473 | int lose=0; |
466 | for ( int j=0; j<c; j++ ) | 474 | for ( int j=0; j<c; j++ ) |
467 | lose += r->tileRef(j)->value(); | 475 | lose += r->tileRef(j)->value(); |
468 | totalleft += lose; | 476 | totalleft += lose; |
469 | scoreinfo->addScore(i,-lose); | 477 | scoreinfo->addScore(i,-lose); |
470 | } else { | 478 | } else { |
471 | out = i; | 479 | out = i; |
472 | } | 480 | } |
473 | } | 481 | } |
474 | int highest=0; | 482 | int highest=0; |
475 | int winner=0; | 483 | int winner=0; |
476 | for (i=0; i<nplayers; i++) { | 484 | for (i=0; i<nplayers; i++) { |
477 | int s = scoreinfo->playerScore(i); | 485 | int s = scoreinfo->playerScore(i); |
478 | if ( s > highest ) { | 486 | if ( s > highest ) { |
479 | highest = s; | 487 | highest = s; |
480 | winner = i; | 488 | winner = i; |
481 | } | 489 | } |
482 | } | 490 | } |
483 | if ( out >= 0 ) | 491 | if ( out >= 0 ) |
484 | scoreinfo->addScore(out,totalleft); | 492 | scoreinfo->addScore(out,totalleft); |
485 | scoreinfo->setBoldOne(winner); | 493 | scoreinfo->setBoldOne(winner); |
486 | gameover = TRUE; | 494 | gameover = TRUE; |
487 | done->setEnabled(TRUE); | 495 | done->setEnabled(TRUE); |
488 | reset->setEnabled(FALSE); | 496 | reset->setEnabled(FALSE); |
489 | } | 497 | } |
490 | 498 | ||
491 | void WordGame::endTurn() | 499 | void WordGame::endTurn() |
492 | { | 500 | { |
493 | if ( gameover ) { | 501 | if ( gameover ) { |
494 | openGameSelector(namelist); | 502 | openGameSelector(namelist); |
495 | } else { | 503 | } else { |
496 | if ( board->checkTurn() ) { | 504 | if ( board->checkTurn() ) { |
497 | if ( board->turnScore() >= 0 ) { | 505 | if ( board->turnScore() >= 0 ) { |
498 | scoreinfo->addScore(player,board->turnScore()); | 506 | scoreinfo->addScore(player,board->turnScore()); |
499 | board->finalizeTurn(); | 507 | board->finalizeTurn(); |
500 | } else { | 508 | } else { |
501 | QApplication::beep(); | 509 | QApplication::beep(); |
502 | } | 510 | } |
503 | nextPlayer(); | 511 | nextPlayer(); |
504 | } | 512 | } |
505 | } | 513 | } |
506 | } | 514 | } |
507 | 515 | ||
508 | void WordGame::resetTurn() | 516 | void WordGame::resetTurn() |
509 | { | 517 | { |
510 | board->resetRack(); | 518 | board->resetRack(); |
511 | } | 519 | } |
512 | 520 | ||
513 | void WordGame::passTurn() | 521 | void WordGame::passTurn() |
514 | { | 522 | { |
515 | // ######## trade? | 523 | // ######## trade? |
516 | nextPlayer(); | 524 | nextPlayer(); |
517 | } | 525 | } |
518 | 526 | ||
519 | bool WordGame::refillRack(int i) | 527 | bool WordGame::refillRack(int i) |
520 | { | 528 | { |
521 | Rack* r = rack(i); | 529 | Rack* r = rack(i); |
522 | while ( !bag->isEmpty() && !r->isFull() ) { | 530 | while ( !bag->isEmpty() && !r->isFull() ) { |
523 | r->addTile(bag->takeRandom()); | 531 | r->addTile(bag->takeRandom()); |
524 | } | 532 | } |
525 | return r->count() != 0; | 533 | return r->count() != 0; |
526 | } | 534 | } |
527 | 535 | ||
528 | void WordGame::readyRack(int i) | 536 | void WordGame::readyRack(int i) |
529 | { | 537 | { |
530 | Rack* r = rack(i); | 538 | Rack* r = rack(i); |
531 | racks->raiseWidget(i); | 539 | racks->raiseWidget(i); |
532 | board->setCurrentRack(r); | 540 | board->setCurrentRack(r); |
533 | 541 | ||
534 | done->setEnabled( !r->computerized() ); | 542 | done->setEnabled( !r->computerized() ); |
535 | reset->setEnabled( !r->computerized() ); | 543 | reset->setEnabled( !r->computerized() ); |
536 | 544 | ||
537 | if ( r->computerized() ) { | 545 | if ( r->computerized() ) { |
538 | cpu = new ComputerPlayer(board, r); | 546 | cpu = new ComputerPlayer(board, r); |
539 | aiheart->start(0); | 547 | aiheart->start(0); |
540 | } | 548 | } |
541 | } | 549 | } |
542 | 550 | ||
543 | Rack* WordGame::rack(int i) const | 551 | Rack* WordGame::rack(int i) const |
544 | { | 552 | { |
545 | return (Rack*)racks->widget(i); | 553 | return (Rack*)racks->widget(i); |
546 | } | 554 | } |
547 | 555 | ||
548 | void WordGame::think() | 556 | void WordGame::think() |
549 | { | 557 | { |
550 | if ( !cpu->step() ) { | 558 | if ( !cpu->step() ) { |
551 | delete cpu; | 559 | delete cpu; |
552 | cpu = 0; | 560 | cpu = 0; |
553 | aiheart->stop(); | 561 | aiheart->stop(); |
554 | if ( board->turnScore() < 0 ) | 562 | if ( board->turnScore() < 0 ) |
555 | passTurn(); | 563 | passTurn(); |
556 | else | 564 | else |
557 | endTurn(); | 565 | endTurn(); |
558 | } | 566 | } |
559 | } | 567 | } |
560 | 568 | ||
561 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : | 569 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : |
562 | board(b), rack(r), best(new const Tile*[rack_tiles]), | 570 | board(b), rack(r), best(new const Tile*[rack_tiles]), |
563 | best_blankvalues(new Tile[rack_tiles]) | 571 | best_blankvalues(new Tile[rack_tiles]) |
564 | { | 572 | { |
565 | best_score = -1; | 573 | best_score = -1; |
566 | across=FALSE; | 574 | across=FALSE; |
567 | dict=0; | 575 | dict=0; |
568 | } | 576 | } |
569 | 577 | ||
570 | ComputerPlayer::~ComputerPlayer() | 578 | ComputerPlayer::~ComputerPlayer() |
571 | { | 579 | { |
572 | delete [] best; | 580 | delete [] best; |
573 | delete [] best_blankvalues; | 581 | delete [] best_blankvalues; |
574 | } | 582 | } |
575 | 583 | ||
576 | bool ComputerPlayer::step() | 584 | bool ComputerPlayer::step() |
577 | { | 585 | { |
578 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() | 586 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() |
579 | : Global::fixedDawg().root(); | 587 | : Global::fixedDawg().root(); |
580 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); | 588 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); |
581 | const Tile* tiles[99]; // ### max board size | 589 | const Tile* tiles[99]; // ### max board size |
582 | uchar nletter[4095]; // QDawg only handles 0..4095 | 590 | uchar nletter[4095]; // QDawg only handles 0..4095 |
583 | memset(nletter,0,4096); | 591 | memset(nletter,0,4096); |
584 | for (int i=0; i<rack->count(); i++) { | 592 | for (int i=0; i<rack->count(); i++) { |
585 | const Tile* r = rack->tileRef(i); | 593 | const Tile* r = rack->tileRef(i); |
586 | if ( r->isBlank() ) | 594 | if ( r->isBlank() ) |
587 | nletter[0]++; | 595 | nletter[0]++; |
588 | else | 596 | else |
589 | nletter[r->text()[0].unicode()]++; | 597 | nletter[r->text()[0].unicode()]++; |
590 | } | 598 | } |
591 | Tile blankvalues[99]; // ### max blanks | 599 | Tile blankvalues[99]; // ### max blanks |
592 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); | 600 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); |
593 | if ( ++current.rx() == board->xTiles() ) { | 601 | if ( ++current.rx() == board->xTiles() ) { |
594 | current.rx() = 0; | 602 | current.rx() = 0; |
595 | if ( ++current.ry() == board->yTiles() ) { | 603 | if ( ++current.ry() == board->yTiles() ) { |
596 | if ( across ) { | 604 | if ( across ) { |
597 | if ( dict == 1 ) { | 605 | if ( dict == 1 ) { |
598 | if ( best_score >= 0 ) { | 606 | if ( best_score >= 0 ) { |
599 | rack->arrangeTiles(best,best_n); | 607 | rack->arrangeTiles(best,best_n); |
600 | rack->setBlanks(best_blankvalues); | 608 | rack->setBlanks(best_blankvalues); |
601 | board->scoreTurn(best_start, best_n, best_dir); | 609 | board->scoreTurn(best_start, best_n, best_dir); |
602 | board->showTurn(); | 610 | board->showTurn(); |
603 | } | 611 | } |
604 | return FALSE; | 612 | return FALSE; |
605 | } | 613 | } |
606 | dict++; | 614 | dict++; |
607 | across = FALSE; | 615 | across = FALSE; |
608 | current = QPoint(0,0); | 616 | current = QPoint(0,0); |
609 | } else { | 617 | } else { |
610 | across = TRUE; | 618 | across = TRUE; |
611 | current = QPoint(0,0); | 619 | current = QPoint(0,0); |
612 | } | 620 | } |
613 | } | 621 | } |
614 | } | 622 | } |
615 | return TRUE; | 623 | return TRUE; |
616 | } | 624 | } |
617 | 625 | ||
618 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) | 626 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) |
619 | { | 627 | { |
620 | if ( !node ) | 628 | if ( !node ) |
621 | return; | 629 | return; |
622 | QChar l = node->letter(); | 630 | QChar l = node->letter(); |
623 | const Tile* cur = board->tile(at); | 631 | const Tile* cur = board->tile(at); |
624 | if ( cur ) { | 632 | if ( cur ) { |
625 | if ( cur->text()[0] == l ) { | 633 | if ( cur->text()[0] == l ) { |
626 | bool nextok = board->contains(at+d); | 634 | bool nextok = board->contains(at+d); |
627 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) | 635 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) |
628 | noteChoice(tiles,n,d,blankvalues,blused); | 636 | noteChoice(tiles,n,d,blankvalues,blused); |
629 | if ( nextok ) | 637 | if ( nextok ) |
630 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 638 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
631 | // #### text()[1]... | 639 | // #### text()[1]... |
632 | } | 640 | } |
633 | } else { | 641 | } else { |
634 | if ( nletter[l.unicode()] || nletter[0] ) { | 642 | if ( nletter[l.unicode()] || nletter[0] ) { |
635 | int rc = rack->count(); | 643 | int rc = rack->count(); |
636 | ulong msk = 1; | 644 | ulong msk = 1; |
637 | for ( int x=0; x<rc; x++ ) { | 645 | for ( int x=0; x<rc; x++ ) { |
638 | if ( !(used&msk) ) { | 646 | if ( !(used&msk) ) { |
639 | const Tile* t = rack->tileRef(x); | 647 | const Tile* t = rack->tileRef(x); |
640 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s | 648 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s |
641 | bool nextok = board->contains(at+d); | 649 | bool nextok = board->contains(at+d); |
642 | tiles[n++] = t; | 650 | tiles[n++] = t; |
643 | if ( t->isBlank() ) | 651 | if ( t->isBlank() ) |
644 | blankvalues[blused++] = Tile(l,0); | 652 | blankvalues[blused++] = Tile(l,0); |
645 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) | 653 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) |
646 | noteChoice(tiles,n,d,blankvalues,blused); | 654 | noteChoice(tiles,n,d,blankvalues,blused); |
647 | used |= msk; // mark | 655 | used |= msk; // mark |
648 | nletter[t->text()[0].unicode()]--; | 656 | nletter[t->text()[0].unicode()]--; |
649 | if ( nextok ) | 657 | if ( nextok ) |
650 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 658 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
651 | n--; | 659 | n--; |
652 | nletter[t->text()[0].unicode()]++; | 660 | nletter[t->text()[0].unicode()]++; |
653 | if ( t->isBlank() ) { | 661 | if ( t->isBlank() ) { |
654 | // keep looking | 662 | // keep looking |
655 | blused--; | 663 | blused--; |
656 | used &= ~msk; // unmark | 664 | used &= ~msk; // unmark |
657 | } else { | 665 | } else { |
658 | break; | 666 | break; |
659 | } | 667 | } |
660 | } | 668 | } |
661 | } | 669 | } |
662 | msk <<= 1; | 670 | msk <<= 1; |
663 | } | 671 | } |
664 | } | 672 | } |
665 | // #### text()[1]... | 673 | // #### text()[1]... |
666 | } | 674 | } |
667 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); | 675 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); |
668 | } | 676 | } |
669 | 677 | ||
670 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) | 678 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) |
671 | { | 679 | { |
672 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); | 680 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); |
673 | /* | 681 | /* |
674 | if (s>0 || current==QPoint(5,1)){ | 682 | if (s>0 || current==QPoint(5,1)){ |
675 | QString st; | 683 | QString st; |
676 | for ( int i=0; i<n; i++ ) | 684 | for ( int i=0; i<n; i++ ) |
677 | st += tiles[i]->text(); | 685 | st += tiles[i]->text(); |
678 | odebug << "" << current.x() << "," << current.y() << ": " << st.latin1() << " (" << n << ") for " << s << "" << oendl; | 686 | odebug << "" << current.x() << "," << current.y() << ": " << st.latin1() << " (" << n << ") for " << s << "" << oendl; |
679 | } | 687 | } |
680 | */ | 688 | */ |
681 | if ( s > best_score ) { | 689 | if ( s > best_score ) { |
682 | int i; | 690 | int i; |
683 | for ( i=0; i<n; i++ ) | 691 | for ( i=0; i<n; i++ ) |
684 | best[i] = tiles[i]; | 692 | best[i] = tiles[i]; |
685 | for ( i=0; i<blused; i++ ) | 693 | for ( i=0; i<blused; i++ ) |
686 | best_blankvalues[i] = blankvalues[i]; | 694 | best_blankvalues[i] = blankvalues[i]; |
687 | best_n = n; | 695 | best_n = n; |
688 | best_blused = blused; | 696 | best_blused = blused; |
689 | best_score = s; | 697 | best_score = s; |
690 | best_dir = d; | 698 | best_dir = d; |
691 | best_start = current; | 699 | best_start = current; |
692 | } | 700 | } |
693 | } | 701 | } |
694 | 702 | ||
695 | int TileItem::smallWidth() | 703 | int TileItem::smallWidth() |
696 | { | 704 | { |
697 | return tile_smallw; | 705 | return tile_smallw; |
698 | } | 706 | } |
699 | 707 | ||
700 | int TileItem::smallHeight() | 708 | int TileItem::smallHeight() |
701 | { | 709 | { |
702 | return tile_smallh; | 710 | return tile_smallh; |
703 | } | 711 | } |
704 | 712 | ||
705 | int TileItem::bigWidth() | 713 | int TileItem::bigWidth() |
706 | { | 714 | { |
707 | return tile_bigw; | 715 | return tile_bigw; |
708 | } | 716 | } |
709 | 717 | ||
710 | int TileItem::bigHeight() | 718 | int TileItem::bigHeight() |
711 | { | 719 | { |
712 | return tile_bigh; | 720 | return tile_bigh; |
713 | } | 721 | } |
714 | 722 | ||
715 | void TileItem::setState( State state ) | 723 | void TileItem::setState( State state ) |
716 | { | 724 | { |
717 | hide(); | 725 | hide(); |
718 | s = state; | 726 | s = state; |
719 | show(); // ### use update() in Qt 3.0 | 727 | show(); // ### use update() in Qt 3.0 |
720 | } | 728 | } |
721 | 729 | ||
722 | void TileItem::setTile(const Tile& tile) | 730 | void TileItem::setTile(const Tile& tile) |
723 | { | 731 | { |
724 | hide(); | 732 | hide(); |
725 | t = tile; | 733 | t = tile; |
726 | show(); // ### use update() in Qt 3.0 | 734 | show(); // ### use update() in Qt 3.0 |
727 | } | 735 | } |
728 | 736 | ||
729 | void TileItem::setBig(bool b) | 737 | void TileItem::setBig(bool b) |
730 | { | 738 | { |
731 | big = b; | 739 | big = b; |
732 | } | 740 | } |
733 | 741 | ||
734 | void TileItem::drawShape(QPainter& p) | 742 | void TileItem::drawShape(QPainter& p) |
735 | { | 743 | { |
736 | static QFont *value_font=0; | 744 | static QFont *value_font=0; |
737 | static QFont *big_font=0; | 745 | static QFont *big_font=0; |
738 | static QFont *small_font=0; | 746 | static QFont *small_font=0; |
739 | if ( !value_font ) { | 747 | if ( !value_font ) { |
740 | value_font = new QFont("helvetica",8); | 748 | value_font = new QFont("helvetica",8); |
741 | if ( TileItem::bigWidth() < 20 ) { | 749 | if ( TileItem::bigWidth() < 20 ) { |
742 | big_font = new QFont("helvetica",12); | 750 | big_font = new QFont("helvetica",12); |
743 | small_font = new QFont("helvetica",8); | 751 | small_font = new QFont("helvetica",8); |
744 | } else { | 752 | } else { |
745 | big_font = new QFont("smoothtimes",17); | 753 | big_font = new QFont("smoothtimes",17); |
746 | small_font = new QFont("smoothtimes",10); | 754 | small_font = new QFont("smoothtimes",10); |
747 | } | 755 | } |
748 | } | 756 | } |
749 | 757 | ||
750 | QRect area(x(),y(),width(),height()); | 758 | QRect area(x(),y(),width(),height()); |
751 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); | 759 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); |
752 | p.drawRect(area); | 760 | p.drawRect(area); |
753 | if ( big ) { | 761 | if ( big ) { |
754 | p.setFont(*value_font); | 762 | p.setFont(*value_font); |
755 | QString n = QString::number(t.value()); | 763 | QString n = QString::number(t.value()); |
756 | int w = p.fontMetrics().width('1'); | 764 | int w = p.fontMetrics().width('1'); |
757 | int h = p.fontMetrics().height(); | 765 | int h = p.fontMetrics().height(); |
758 | w *= n.length(); | 766 | w *= n.length(); |
759 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); | 767 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); |
760 | p.drawText(valuearea,AlignCenter,n); | 768 | p.drawText(valuearea,AlignCenter,n); |
761 | p.setFont(*big_font); | 769 | p.setFont(*big_font); |
762 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); | 770 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); |
763 | } else { | 771 | } else { |
764 | p.setFont(*small_font); | 772 | p.setFont(*small_font); |
765 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); | 773 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); |
766 | } | 774 | } |
767 | if ( t.value() == 0 ) | 775 | if ( t.value() == 0 ) |
768 | p.setPen(darkGray); | 776 | p.setPen(darkGray); |
769 | p.drawText(area,AlignCenter,t.text().upper()); | 777 | p.drawText(area,AlignCenter,t.text().upper()); |
770 | } | 778 | } |
771 | 779 | ||
772 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : | 780 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : |
773 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), | 781 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), |
774 | parent) | 782 | parent) |
775 | { | 783 | { |
776 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); | 784 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); |
777 | grid = new TileItem*[w*h]; | 785 | grid = new TileItem*[w*h]; |
778 | memset(grid,0,w*h*sizeof(TileItem*)); | 786 | memset(grid,0,w*h*sizeof(TileItem*)); |
779 | setFrameStyle(0); | 787 | setFrameStyle(0); |
780 | setHScrollBarMode(AlwaysOff); | 788 | setHScrollBarMode(AlwaysOff); |
781 | setVScrollBarMode(AlwaysOff); | 789 | setVScrollBarMode(AlwaysOff); |
782 | current_rack = 0; | 790 | current_rack = 0; |
783 | shown_n = 0; | 791 | shown_n = 0; |
784 | } | 792 | } |
785 | 793 | ||
786 | Board::~Board() | 794 | Board::~Board() |
787 | { | 795 | { |
788 | delete canvas(); | 796 | delete canvas(); |
789 | } | 797 | } |
790 | 798 | ||
791 | QSize Board::sizeHint() const | 799 | QSize Board::sizeHint() const |
792 | { | 800 | { |
793 | return QSize(canvas()->width(),canvas()->height()); | 801 | return QSize(canvas()->width(),canvas()->height()); |
794 | } | 802 | } |
795 | 803 | ||
796 | void Board::writeConfig(Config& cfg) | 804 | void Board::writeConfig(Config& cfg) |
797 | { | 805 | { |
798 | QStringList t; | 806 | QStringList t; |
799 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 807 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
800 | for (int i=0; i<n; i++) | 808 | for (int i=0; i<n; i++) |
801 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); | 809 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); |
802 | cfg.writeEntry("Board",t,';'); | 810 | cfg.writeEntry("Board",t,';'); |
803 | } | 811 | } |
804 | 812 | ||
805 | void Board::readConfig(Config& cfg) | 813 | void Board::readConfig(Config& cfg) |
806 | { | 814 | { |
807 | clear(); | 815 | clear(); |
808 | QStringList t = cfg.readListEntry("Board",';'); | 816 | QStringList t = cfg.readListEntry("Board",';'); |
809 | int i=0; | 817 | int i=0; |
810 | int h=canvas()->tilesHorizontally(); | 818 | int h=canvas()->tilesHorizontally(); |
811 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { | 819 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { |
812 | if ( *it != "." ) { | 820 | if ( *it != "." ) { |
813 | QPoint p(i%h,i/h); | 821 | QPoint p(i%h,i/h); |
814 | setTile(p,Tile(*it)); | 822 | setTile(p,Tile(*it)); |
815 | } | 823 | } |
816 | i++; | 824 | i++; |
817 | } | 825 | } |
818 | canvas()->update(); | 826 | canvas()->update(); |
819 | } | 827 | } |
820 | 828 | ||
821 | void Board::clear() | 829 | void Board::clear() |
822 | { | 830 | { |
823 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 831 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
824 | for (int i=0; i<n; i++) { | 832 | for (int i=0; i<n; i++) { |
825 | delete grid[i]; | 833 | delete grid[i]; |
826 | grid[i]=0; | 834 | grid[i]=0; |
827 | } | 835 | } |
828 | } | 836 | } |
829 | 837 | ||
830 | 838 | ||
831 | void Board::setCurrentRack(Rack* r) | 839 | void Board::setCurrentRack(Rack* r) |
832 | { | 840 | { |
833 | turn_score = -1; | 841 | turn_score = -1; |
834 | current_rack = r; | 842 | current_rack = r; |
835 | } | 843 | } |
836 | 844 | ||
837 | void Board::resetRack() | 845 | void Board::resetRack() |
838 | { | 846 | { |
839 | unshowTurn(); | 847 | unshowTurn(); |
840 | canvas()->update(); | 848 | canvas()->update(); |
841 | } | 849 | } |
842 | 850 | ||
843 | void Board::contentsMousePressEvent(QMouseEvent* e) | 851 | void Board::contentsMousePressEvent(QMouseEvent* e) |
844 | { | 852 | { |
845 | dragstart = e->pos(); | 853 | dragstart = e->pos(); |
846 | } | 854 | } |
847 | 855 | ||
848 | void Board::contentsMouseMoveEvent(QMouseEvent* e) | 856 | void Board::contentsMouseMoveEvent(QMouseEvent* e) |
849 | { | 857 | { |
850 | if ( current_rack && !current_rack->computerized() ) { | 858 | if ( current_rack && !current_rack->computerized() ) { |
851 | QPoint d = e->pos() - dragstart; | 859 | QPoint d = e->pos() - dragstart; |
852 | if ( d.x() <= 0 && d.y() <= 0 ) { | 860 | if ( d.x() <= 0 && d.y() <= 0 ) { |
853 | // None | 861 | // None |
854 | resetRack(); | 862 | resetRack(); |
855 | } else { | 863 | } else { |
856 | int n; | 864 | int n; |
857 | QPoint start=boardPos(dragstart); | 865 | QPoint start=boardPos(dragstart); |
858 | QPoint end=boardPos(e->pos()); | 866 | QPoint end=boardPos(e->pos()); |
859 | QPoint diff=end-start; | 867 | QPoint diff=end-start; |
860 | QPoint dir; | 868 | QPoint dir; |
861 | if ( d.x() > d.y() ) { | 869 | if ( d.x() > d.y() ) { |
862 | n = diff.x()+1; | 870 | n = diff.x()+1; |
863 | dir = QPoint(1,0); | 871 | dir = QPoint(1,0); |
864 | } else { | 872 | } else { |
865 | n = diff.y()+1; | 873 | n = diff.y()+1; |
866 | dir = QPoint(0,1); | 874 | dir = QPoint(0,1); |
867 | } | 875 | } |
868 | 876 | ||
869 | unshowTurn(); | 877 | unshowTurn(); |
870 | 878 | ||
871 | // Subtract existing tiles from n | 879 | // Subtract existing tiles from n |
872 | QPoint t = start; | 880 | QPoint t = start; |
873 | for ( int i=n; i--; ) { | 881 | for ( int i=n; i--; ) { |
874 | if ( contains(t) && tile(t) ) | 882 | if ( contains(t) && tile(t) ) |
875 | n--; | 883 | n--; |
876 | t += dir; | 884 | t += dir; |
877 | } | 885 | } |
878 | 886 | ||
879 | // Move start back to real start | 887 | // Move start back to real start |
880 | while (contains(start-dir) && tile(start-dir)) | 888 | while (contains(start-dir) && tile(start-dir)) |
881 | start -= dir; | 889 | start -= dir; |
882 | 890 | ||
883 | scoreTurn(start, n, dir); | 891 | scoreTurn(start, n, dir); |
884 | showTurn(); | 892 | showTurn(); |
885 | } | 893 | } |
886 | } | 894 | } |
887 | } | 895 | } |
888 | 896 | ||
889 | void Board::finalizeTurn() | 897 | void Board::finalizeTurn() |
890 | { | 898 | { |
891 | int i=0; | 899 | int i=0; |
892 | QPoint at = shown_at; | 900 | QPoint at = shown_at; |
893 | while ( i<shown_n && contains(at) ) { | 901 | while ( i<shown_n && contains(at) ) { |
894 | if ( item(at) && item(at)->state() == TileItem::Floating ) { | 902 | if ( item(at) && item(at)->state() == TileItem::Floating ) { |
895 | current_rack->remove(item(at)->tile()); | 903 | current_rack->remove(item(at)->tile()); |
896 | setTileState(at,TileItem::Firm); | 904 | setTileState(at,TileItem::Firm); |
897 | i++; | 905 | i++; |
898 | } | 906 | } |
899 | at += shown_step; | 907 | at += shown_step; |
900 | } | 908 | } |
901 | canvas()->update(); | 909 | canvas()->update(); |
902 | } | 910 | } |
903 | 911 | ||
904 | void Board::unshowTurn() | 912 | void Board::unshowTurn() |
905 | { | 913 | { |
906 | int i=0; | 914 | int i=0; |
907 | QPoint at = shown_at; | 915 | QPoint at = shown_at; |
908 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { | 916 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { |
909 | if ( item(at) && item(at)->state() == TileItem::Floating ) { | 917 | if ( item(at) && item(at)->state() == TileItem::Floating ) { |
910 | unsetTile(at); | 918 | unsetTile(at); |
911 | i++; | 919 | i++; |
912 | } | 920 | } |
913 | at += shown_step; | 921 | at += shown_step; |
914 | } | 922 | } |
915 | } | 923 | } |
916 | 924 | ||
917 | void Board::showTurn() | 925 | void Board::showTurn() |
918 | { | 926 | { |
919 | unshowTurn(); | 927 | unshowTurn(); |
920 | QPoint at = shown_at; | 928 | QPoint at = shown_at; |
921 | int i=0; | 929 | int i=0; |
922 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { | 930 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { |
923 | if ( !tile(at) ) { | 931 | if ( !tile(at) ) { |
924 | Tile t = current_rack->tile(i); | 932 | Tile t = current_rack->tile(i); |
925 | setTile(at,t); | 933 | setTile(at,t); |
926 | setTileState(at,TileItem::Floating); | 934 | setTileState(at,TileItem::Floating); |
927 | i++; | 935 | i++; |
928 | } | 936 | } |
929 | at += shown_step; | 937 | at += shown_step; |
930 | } | 938 | } |
931 | canvas()->update(); | 939 | canvas()->update(); |
932 | } | 940 | } |
933 | 941 | ||
934 | int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const | 942 | int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const |
935 | { | 943 | { |
936 | int rule = rule_shape[idx(at)]-'0'; | 944 | int rule = rule_shape[idx(at)]-'0'; |
937 | int effect = rule_effect[rule]; | 945 | int effect = rule_effect[rule]; |
938 | int mult = effect&Multiplier; | 946 | int mult = effect&Multiplier; |
939 | if ( effect & MultiplyAll ) { | 947 | if ( effect & MultiplyAll ) { |
940 | all_mult *= mult; | 948 | all_mult *= mult; |
941 | return base; | 949 | return base; |
942 | } else { | 950 | } else { |
943 | return base * mult; | 951 | return base * mult; |
944 | } | 952 | } |
945 | } | 953 | } |
946 | 954 | ||
947 | bool Board::isStart(const QPoint& at) const | 955 | bool Board::isStart(const QPoint& at) const |
948 | { | 956 | { |
949 | int rule = rule_shape[idx(at)]-'0'; | 957 | int rule = rule_shape[idx(at)]-'0'; |
950 | int effect = rule_effect[rule]; | 958 | int effect = rule_effect[rule]; |
951 | return effect&Start; | 959 | return effect&Start; |
952 | } | 960 | } |
953 | 961 | ||
954 | bool Board::checkTurn() | 962 | bool Board::checkTurn() |
955 | { | 963 | { |
956 | if ( current_rack->computerized() ) | 964 | if ( current_rack->computerized() ) |
957 | return TRUE; // computer doesn't cheat, and has already set blanks. | 965 | return TRUE; // computer doesn't cheat, and has already set blanks. |
958 | 966 | ||
959 | QPoint at = shown_at; | 967 | QPoint at = shown_at; |
960 | int n = shown_n; | 968 | int n = shown_n; |
961 | QPoint d = shown_step; | 969 | QPoint d = shown_step; |
962 | const Tile* tiles[99]; | 970 | const Tile* tiles[99]; |
963 | Tile blankvalues[99]; | 971 | Tile blankvalues[99]; |
964 | if ( n > current_rack->count() ) | 972 | if ( n > current_rack->count() ) |
965 | n = current_rack->count(); | 973 | n = current_rack->count(); |
966 | 974 | ||
967 | QDialog check(this,0,TRUE); | 975 | QDialog check(this,0,TRUE); |
968 | (new QVBoxLayout(&check))->setAutoAdd(TRUE); | 976 | (new QVBoxLayout(&check))->setAutoAdd(TRUE); |
969 | 977 | ||
970 | QHBox mw(&check); | 978 | QHBox mw(&check); |
971 | new QLabel(tr("Blanks: "),&mw); | 979 | new QLabel(tr("Blanks: "),&mw); |
972 | 980 | ||
973 | int bl=0; | 981 | int bl=0; |
974 | QLineEdit* le[99]; | 982 | QLineEdit* le[99]; |
975 | for (int i=0; i<n; i++) { | 983 | for (int i=0; i<n; i++) { |
976 | tiles[i] = current_rack->tileRef(i); | 984 | tiles[i] = current_rack->tileRef(i); |
977 | if ( tiles[i]->isBlank() ) { | 985 | if ( tiles[i]->isBlank() ) { |
978 | QLineEdit *l = new QLineEdit(&mw); | 986 | QLineEdit *l = new QLineEdit(&mw); |
979 | le[bl++] = l; | 987 | le[bl++] = l; |
980 | l->setMaxLength(1); | 988 | l->setMaxLength(1); |
981 | l->setFixedSize(l->minimumSizeHint()); | 989 | l->setFixedSize(l->minimumSizeHint()); |
982 | } | 990 | } |
983 | } | 991 | } |
984 | 992 | ||
985 | QHBox btns(&check); | 993 | QHBox btns(&check); |
986 | connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept())); | 994 | connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept())); |
987 | connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject())); | 995 | connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject())); |
988 | 996 | ||
989 | if ( bl ) { | 997 | if ( bl ) { |
990 | retry: | 998 | retry: |
991 | if ( !check.exec() ) { | 999 | if ( !check.exec() ) { |
992 | unshowTurn(); | 1000 | unshowTurn(); |
993 | canvas()->update(); | 1001 | canvas()->update(); |
994 | return FALSE; | 1002 | return FALSE; |
995 | } | 1003 | } |
996 | 1004 | ||
997 | for (int b=0; b<bl; b++) { | 1005 | for (int b=0; b<bl; b++) { |
998 | QString v = le[b]->text(); | 1006 | QString v = le[b]->text(); |
999 | blankvalues[b]=Tile(v,0); | 1007 | blankvalues[b]=Tile(v,0); |
1000 | if ( v.length() != 1 ) | 1008 | if ( v.length() != 1 ) |
1001 | goto retry; | 1009 | goto retry; |
1002 | } | 1010 | } |
1003 | } | 1011 | } |
1004 | 1012 | ||
1005 | QStringList words; | 1013 | QStringList words; |
1006 | unshowTurn(); | 1014 | unshowTurn(); |
1007 | turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words); | 1015 | turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words); |
1008 | showTurn(); | 1016 | showTurn(); |
1009 | QStringList to_add; | 1017 | QStringList to_add; |
1010 | for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) { | 1018 | for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) { |
1011 | if ( !Global::fixedDawg().contains(*it) | 1019 | if ( !Global::fixedDawg().contains(*it) |
1012 | && !Global::dawg("WordGame").contains(*it) ) { | 1020 | && !Global::dawg("WordGame").contains(*it) ) { |
1013 | switch (QMessageBox::warning(this, tr("Unknown word"), | 1021 | switch (QMessageBox::warning(this, tr("Unknown word"), |
1014 | tr("<p>The word \"%1\" is not in the dictionary.").arg(*it), | 1022 | tr("<p>The word \"%1\" is not in the dictionary.").arg(*it), |
1015 | tr("Add"), tr("Ignore"), tr("Cancel"))) | 1023 | tr("Add"), tr("Ignore"), tr("Cancel"))) |
1016 | { | 1024 | { |
1017 | case 0: | 1025 | case 0: |
1018 | // ####### add to wordgame dictionary | 1026 | // ####### add to wordgame dictionary |
1019 | to_add.append(*it); | 1027 | to_add.append(*it); |
1020 | break; | 1028 | break; |
1021 | case 1: | 1029 | case 1: |
1022 | break; | 1030 | break; |
1023 | case 2: | 1031 | case 2: |
1024 | unshowTurn(); | 1032 | unshowTurn(); |
1025 | canvas()->update(); | 1033 | canvas()->update(); |
1026 | return FALSE; | 1034 | return FALSE; |
1027 | } | 1035 | } |
1028 | } | 1036 | } |
1029 | } | 1037 | } |
1030 | if ( to_add.count() ) | 1038 | if ( to_add.count() ) |
1031 | Global::addWords("WordGame",to_add); | 1039 | Global::addWords("WordGame",to_add); |
1032 | return TRUE; | 1040 | return TRUE; |
1033 | } | 1041 | } |
1034 | 1042 | ||
1035 | void Board::scoreTurn(const QPoint& at, int n, const QPoint& d) | 1043 | void Board::scoreTurn(const QPoint& at, int n, const QPoint& d) |
1036 | { | 1044 | { |
1037 | unshowTurn(); | 1045 | unshowTurn(); |
1038 | shown_at = at; | 1046 | shown_at = at; |
1039 | shown_n = n; | 1047 | shown_n = n; |
1040 | shown_step = d; | 1048 | shown_step = d; |
1041 | const Tile* tiles[99]; | 1049 | const Tile* tiles[99]; |
1042 | if ( n > current_rack->count() ) | 1050 | if ( n > current_rack->count() ) |
1043 | n = current_rack->count(); | 1051 | n = current_rack->count(); |
1044 | for (int i=0; i<n; i++) | 1052 | for (int i=0; i<n; i++) |
1045 | tiles[i] = current_rack->tileRef(i); | 1053 | tiles[i] = current_rack->tileRef(i); |
1046 | turn_score = score(at,tiles,n,0,d,FALSE,0); | 1054 | turn_score = score(at,tiles,n,0,d,FALSE,0); |
1047 | emit temporaryScore(turn_score); | 1055 | emit temporaryScore(turn_score); |
1048 | } | 1056 | } |
1049 | 1057 | ||
1050 | int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const | 1058 | int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const |
1051 | { | 1059 | { |
1052 | int total=0; | 1060 | int total=0; |
1053 | int totalsidetotal=0; | 1061 | int totalsidetotal=0; |
1054 | 1062 | ||
1055 | // words gets filled with words made | 1063 | // words gets filled with words made |
1056 | 1064 | ||
1057 | // mainword==0 -> | 1065 | // mainword==0 -> |
1058 | // Checks side words, but not main word | 1066 | // Checks side words, but not main word |
1059 | 1067 | ||
1060 | // -1 means words not in dict, or illegally positioned (eg. not connected) | 1068 | // -1 means words not in dict, or illegally positioned (eg. not connected) |
1061 | 1069 | ||
1062 | // text is assumed to fit on board. | 1070 | // text is assumed to fit on board. |
1063 | 1071 | ||
1064 | if ( words ) *words=QStringList(); | 1072 | if ( words ) *words=QStringList(); |
1065 | 1073 | ||
1066 | QPoint otherd(d.y(), d.x()); | 1074 | QPoint otherd(d.y(), d.x()); |
1067 | 1075 | ||
1068 | int all_mult = 1; | 1076 | int all_mult = 1; |
1069 | int bl=0; | 1077 | int bl=0; |
1070 | 1078 | ||
1071 | bool connected = FALSE; | 1079 | bool connected = FALSE; |
1072 | 1080 | ||
1073 | QString mainword=""; | 1081 | QString mainword=""; |
1074 | 1082 | ||
1075 | if ( contains(at-d) && tile(at-d) ) { | 1083 | if ( contains(at-d) && tile(at-d) ) { |
1076 | return -1; // preceeding tiles | 1084 | return -1; // preceeding tiles |
1077 | } | 1085 | } |
1078 | 1086 | ||
1079 | const Tile* t; | 1087 | const Tile* t; |
1080 | for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) { | 1088 | for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) { |
1081 | if ( t ) { | 1089 | if ( t ) { |
1082 | if ( checkdict || words ) mainword += t->text(); | 1090 | if ( checkdict || words ) mainword += t->text(); |
1083 | total += t->value(); | 1091 | total += t->value(); |
1084 | connected = TRUE; | 1092 | connected = TRUE; |
1085 | } else { | 1093 | } else { |
1086 | QString sideword; | 1094 | QString sideword; |
1087 | QString tt; | 1095 | QString tt; |
1088 | if ( tiles[i]->isBlank() ) { | 1096 | if ( tiles[i]->isBlank() ) { |
1089 | if ( blankvalue ) | 1097 | if ( blankvalue ) |
1090 | tt = blankvalue[bl++].text(); | 1098 | tt = blankvalue[bl++].text(); |
1091 | } else { | 1099 | } else { |
1092 | tt = tiles[i]->text(); | 1100 | tt = tiles[i]->text(); |
1093 | } | 1101 | } |
1094 | sideword=tt; | 1102 | sideword=tt; |
1095 | if ( checkdict || words ) mainword += tt; | 1103 | if ( checkdict || words ) mainword += tt; |
1096 | int side_mult = 1; | 1104 | int side_mult = 1; |
1097 | int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult); | 1105 | int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult); |
1098 | all_mult *= side_mult; | 1106 | all_mult *= side_mult; |
1099 | if ( !connected && isStart(at) ) | 1107 | if ( !connected && isStart(at) ) |
1100 | connected = TRUE; | 1108 | connected = TRUE; |
1101 | total += tilevalue; | 1109 | total += tilevalue; |
1102 | int sidetotal = tilevalue; | 1110 | int sidetotal = tilevalue; |
1103 | { | 1111 | { |
1104 | QPoint side = at-otherd; | 1112 | QPoint side = at-otherd; |
1105 | 1113 | ||
1106 | while ( contains(side) && (t=tile(side)) ) { | 1114 | while ( contains(side) && (t=tile(side)) ) { |
1107 | sidetotal += t->value(); | 1115 | sidetotal += t->value(); |
1108 | sideword.prepend(t->text()); | 1116 | sideword.prepend(t->text()); |
1109 | side -= otherd; | 1117 | side -= otherd; |
1110 | } | 1118 | } |
1111 | } | 1119 | } |
1112 | { | 1120 | { |
1113 | QPoint side = at+otherd; | 1121 | QPoint side = at+otherd; |
1114 | while ( contains(side) && (t=tile(side)) ) { | 1122 | while ( contains(side) && (t=tile(side)) ) { |
1115 | sidetotal += t->value(); | 1123 | sidetotal += t->value(); |
1116 | sideword.append(t->text()); | 1124 | sideword.append(t->text()); |
1117 | side += otherd; | 1125 | side += otherd; |
1118 | } | 1126 | } |
1119 | } | 1127 | } |
1120 | if ( sideword.length() > 1 ) { | 1128 | if ( sideword.length() > 1 ) { |
1121 | if ( words ) | 1129 | if ( words ) |
1122 | words->append(sideword); | 1130 | words->append(sideword); |
1123 | if ( checkdict && !Global::fixedDawg().contains(sideword) | 1131 | if ( checkdict && !Global::fixedDawg().contains(sideword) |
1124 | && !Global::dawg("WordGame").contains(sideword) ) | 1132 | && !Global::dawg("WordGame").contains(sideword) ) |
1125 | return -1; | 1133 | return -1; |
1126 | totalsidetotal += sidetotal * side_mult; | 1134 | totalsidetotal += sidetotal * side_mult; |
1127 | connected = TRUE; | 1135 | connected = TRUE; |
1128 | } | 1136 | } |
1129 | i++; | 1137 | i++; |
1130 | } | 1138 | } |
1131 | at += d; | 1139 | at += d; |
1132 | } | 1140 | } |
1133 | 1141 | ||
1134 | if ( words ) | 1142 | if ( words ) |
1135 | words->append(mainword); | 1143 | words->append(mainword); |
1136 | if ( checkdict && !Global::fixedDawg().contains(mainword) | 1144 | if ( checkdict && !Global::fixedDawg().contains(mainword) |
1137 | && !Global::dawg("WordGame").contains(mainword) ) | 1145 | && !Global::dawg("WordGame").contains(mainword) ) |
1138 | return -1; | 1146 | return -1; |
1139 | 1147 | ||
1140 | if ( n == rack_tiles ) | 1148 | if ( n == rack_tiles ) |
1141 | totalsidetotal += rack_tiles_bonus; | 1149 | totalsidetotal += rack_tiles_bonus; |
1142 | 1150 | ||
1143 | return connected ? totalsidetotal + total * all_mult : -1; | 1151 | return connected ? totalsidetotal + total * all_mult : -1; |
1144 | } | 1152 | } |
1145 | 1153 | ||
1146 | QPoint Board::boardPos(const QPoint& p) const | 1154 | QPoint Board::boardPos(const QPoint& p) const |
1147 | { | 1155 | { |
1148 | return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight()); | 1156 | return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight()); |
1149 | } | 1157 | } |
1150 | 1158 | ||
1151 | void Board::contentsMouseReleaseEvent(QMouseEvent*) | 1159 | void Board::contentsMouseReleaseEvent(QMouseEvent*) |
1152 | { | 1160 | { |
1153 | if ( current_rack ) { | 1161 | if ( current_rack ) { |
1154 | } | 1162 | } |
1155 | } | 1163 | } |
1156 | 1164 | ||
1157 | 1165 | ||
1158 | void Board::setRules(const QString& shapes, const int* effects) | 1166 | void Board::setRules(const QString& shapes, const int* effects) |
1159 | { | 1167 | { |
1160 | rule_shape=shapes; rule_effect=effects; | 1168 | rule_shape=shapes; rule_effect=effects; |
1161 | int i=0; | 1169 | int i=0; |
1162 | int maxre=0; | 1170 | int maxre=0; |
1163 | for (int y=0; y<yTiles(); y++) { | 1171 | for (int y=0; y<yTiles(); y++) { |
1164 | for (int x=0; x<xTiles(); x++) { | 1172 | for (int x=0; x<xTiles(); x++) { |
1165 | int re = shapes[i++]-'0'; | 1173 | int re = shapes[i++]-'0'; |
1166 | if ( re > maxre ) maxre = re; | 1174 | if ( re > maxre ) maxre = re; |
1167 | canvas()->setTile(x,y,re); | 1175 | canvas()->setTile(x,y,re); |
1168 | } | 1176 | } |
1169 | } | 1177 | } |
1170 | rack_tiles_bonus=effects[maxre+1]; | 1178 | rack_tiles_bonus=effects[maxre+1]; |
1171 | } | 1179 | } |
1172 | 1180 | ||
1173 | void Board::unsetTile(const QPoint& p) | 1181 | void Board::unsetTile(const QPoint& p) |
1174 | { | 1182 | { |
1175 | delete item(p); | 1183 | delete item(p); |
1176 | grid[idx(p)] = 0; | 1184 | grid[idx(p)] = 0; |
1177 | } | 1185 | } |
1178 | 1186 | ||
1179 | void Board::setTile(const QPoint& p, const Tile& t) | 1187 | void Board::setTile(const QPoint& p, const Tile& t) |
1180 | { | 1188 | { |
1181 | TileItem* it=item(p); | 1189 | TileItem* it=item(p); |
1182 | if ( !it ) { | 1190 | if ( !it ) { |
1183 | it = grid[idx(p)] = new TileItem(t,FALSE,canvas()); | 1191 | it = grid[idx(p)] = new TileItem(t,FALSE,canvas()); |
1184 | it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight()); | 1192 | it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight()); |
1185 | it->show(); | 1193 | it->show(); |
1186 | } else { | 1194 | } else { |
1187 | it->setTile(t); | 1195 | it->setTile(t); |
1188 | } | 1196 | } |
1189 | } | 1197 | } |
1190 | 1198 | ||
1191 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( | 1199 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( |
1192 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), | 1200 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), |
1193 | parent), | 1201 | parent), |
1194 | item(ntiles) | 1202 | item(ntiles) |
1195 | { | 1203 | { |
1196 | setLineWidth(1); | 1204 | setLineWidth(1); |
1197 | setFixedHeight(sizeHint().height()); | 1205 | setFixedHeight(sizeHint().height()); |
1198 | n = 0; | 1206 | n = 0; |
1199 | for (int i=0; i<ntiles; i++) | 1207 | for (int i=0; i<ntiles; i++) |
1200 | item[i]=0; | 1208 | item[i]=0; |
1201 | setHScrollBarMode(AlwaysOff); | 1209 | setHScrollBarMode(AlwaysOff); |
1202 | setVScrollBarMode(AlwaysOff); | 1210 | setVScrollBarMode(AlwaysOff); |
1203 | canvas()->setBackgroundColor(gray); | 1211 | canvas()->setBackgroundColor(gray); |
1204 | dragging = 0; | 1212 | dragging = 0; |
1205 | } | 1213 | } |
1206 | 1214 | ||
1207 | Rack::~Rack() | 1215 | Rack::~Rack() |
1208 | { | 1216 | { |
1209 | clear(); | 1217 | clear(); |
1210 | delete canvas(); | 1218 | delete canvas(); |
1211 | } | 1219 | } |
1212 | 1220 | ||
1213 | QSize Rack::sizeHint() const | 1221 | QSize Rack::sizeHint() const |
1214 | { | 1222 | { |
1215 | return QSize(-1,TileItem::bigHeight()+2); | 1223 | return QSize(-1,TileItem::bigHeight()+2); |
1216 | } | 1224 | } |
1217 | 1225 | ||
1218 | void Rack::clear() | 1226 | void Rack::clear() |
1219 | { | 1227 | { |
1220 | for (int i=0; i<n; i++) | 1228 | for (int i=0; i<n; i++) |
1221 | delete item[i]; | 1229 | delete item[i]; |
1222 | n=0; | 1230 | n=0; |
1223 | } | 1231 | } |
1224 | 1232 | ||
1225 | void Rack::writeConfig(Config& cfg) | 1233 | void Rack::writeConfig(Config& cfg) |
1226 | { | 1234 | { |
1227 | QStringList l; | 1235 | QStringList l; |
1228 | for (int i=0; i<n; i++) | 1236 | for (int i=0; i<n; i++) |
1229 | l.append(tile(i).key()); | 1237 | l.append(tile(i).key()); |
1230 | cfg.writeEntry("Tiles",l,';'); | 1238 | cfg.writeEntry("Tiles",l,';'); |
1231 | } | 1239 | } |
1232 | 1240 | ||
1233 | void Rack::readConfig(Config& cfg) | 1241 | void Rack::readConfig(Config& cfg) |
1234 | { | 1242 | { |
1235 | clear(); | 1243 | clear(); |
1236 | int x=0; | 1244 | int x=0; |
1237 | QStringList l = cfg.readListEntry("Tiles",';'); | 1245 | QStringList l = cfg.readListEntry("Tiles",';'); |
1238 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { | 1246 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { |
1239 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); | 1247 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); |
1240 | i->move(x++,0); | 1248 | i->move(x++,0); |
1241 | i->show(); | 1249 | i->show(); |
1242 | item[n++] = i; | 1250 | item[n++] = i; |
1243 | } | 1251 | } |
1244 | layoutTiles(); | 1252 | layoutTiles(); |
1245 | } | 1253 | } |
1246 | 1254 | ||
1247 | static int cmp_tileitem(const void *a, const void *b) | 1255 | static int cmp_tileitem(const void *a, const void *b) |
1248 | { | 1256 | { |
1249 | const TileItem* ia = *(TileItem**)a; | 1257 | const TileItem* ia = *(TileItem**)a; |
1250 | const TileItem* ib = *(TileItem**)b; | 1258 | const TileItem* ib = *(TileItem**)b; |
1251 | return int(ia->x() - ib->x()); | 1259 | return int(ia->x() - ib->x()); |
1252 | } | 1260 | } |
1253 | 1261 | ||
1254 | void Rack::layoutTiles() | 1262 | void Rack::layoutTiles() |
1255 | { | 1263 | { |
1256 | int w = TileItem::bigWidth()+2; | 1264 | int w = TileItem::bigWidth()+2; |
1257 | 1265 | ||
1258 | if ( dragging ) dragging->moveBy(dragging_adj,0); | 1266 | if ( dragging ) dragging->moveBy(dragging_adj,0); |
1259 | qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem); | 1267 | qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem); |
1260 | if ( dragging ) dragging->moveBy(-dragging_adj,0); | 1268 | if ( dragging ) dragging->moveBy(-dragging_adj,0); |
1261 | 1269 | ||
1262 | for (int i=0; i<n ;i++) | 1270 | for (int i=0; i<n ;i++) |
1263 | if ( item[i] == dragging ) { | 1271 | if ( item[i] == dragging ) { |
1264 | item[i]->setZ(1); | 1272 | item[i]->setZ(1); |
1265 | } else { | 1273 | } else { |
1266 | item[i]->move(i*w, 0); | 1274 | item[i]->move(i*w, 0); |
1267 | item[i]->setZ(0); | 1275 | item[i]->setZ(0); |
1268 | } | 1276 | } |
1269 | canvas()->update(); | 1277 | canvas()->update(); |
1270 | } | 1278 | } |
1271 | 1279 | ||
1272 | void Rack::setBlanks(const Tile* bv) | 1280 | void Rack::setBlanks(const Tile* bv) |
1273 | { | 1281 | { |
1274 | for (int j=0; j<n; j++) { | 1282 | for (int j=0; j<n; j++) { |
1275 | Tile tt = item[j]->tile(); | 1283 | Tile tt = item[j]->tile(); |
1276 | if ( tt.isBlank() ) { | 1284 | if ( tt.isBlank() ) { |
1277 | tt.setText(bv->text()); | 1285 | tt.setText(bv->text()); |
1278 | item[j]->setTile(tt); | 1286 | item[j]->setTile(tt); |
1279 | bv++; | 1287 | bv++; |
1280 | } | 1288 | } |
1281 | } | 1289 | } |
1282 | } | 1290 | } |
1283 | 1291 | ||
1284 | bool Rack::arrangeTiles(const Tile** s, int sn) | 1292 | bool Rack::arrangeTiles(const Tile** s, int sn) |
1285 | { | 1293 | { |
1286 | bool could = TRUE; | 1294 | bool could = TRUE; |
1287 | for (int j=0; j<n; j++) { | 1295 | for (int j=0; j<n; j++) { |
1288 | Tile tt = item[j]->tile(); | 1296 | Tile tt = item[j]->tile(); |
1289 | int f=-1; | 1297 | int f=-1; |
1290 | for (int i=0; i<sn && f<0; i++) { | 1298 | for (int i=0; i<sn && f<0; i++) { |
1291 | if (s[i] && *s[i] == tt ) { | 1299 | if (s[i] && *s[i] == tt ) { |
1292 | s[i]=0; | 1300 | s[i]=0; |
1293 | f=i; | 1301 | f=i; |
1294 | } | 1302 | } |
1295 | } | 1303 | } |
1296 | if ( f >= 0 ) { | 1304 | if ( f >= 0 ) { |
1297 | item[j]->move(f-999,0); | 1305 | item[j]->move(f-999,0); |
1298 | } else { | 1306 | } else { |
1299 | could = FALSE; | 1307 | could = FALSE; |
1300 | } | 1308 | } |
1301 | } | 1309 | } |
1302 | layoutTiles(); | 1310 | layoutTiles(); |
1303 | return could; | 1311 | return could; |
1304 | } | 1312 | } |
1305 | 1313 | ||
1306 | void Rack::addTile(const Tile& t) | 1314 | void Rack::addTile(const Tile& t) |
1307 | { | 1315 | { |
1308 | TileItem *i = new TileItem(t,TRUE,canvas()); | 1316 | TileItem *i = new TileItem(t,TRUE,canvas()); |
1309 | i->show(); | 1317 | i->show(); |
1310 | item[n++] = i; | 1318 | item[n++] = i; |
1311 | layoutTiles(); | 1319 | layoutTiles(); |
1312 | } | 1320 | } |
1313 | 1321 | ||
1314 | void Rack::remove(Tile t) | 1322 | void Rack::remove(Tile t) |
1315 | { | 1323 | { |
1316 | for (int i=0; i<n ;i++) | 1324 | for (int i=0; i<n ;i++) |
1317 | if ( item[i]->tile() == t ) { | 1325 | if ( item[i]->tile() == t ) { |
1318 | remove(i); | 1326 | remove(i); |
1319 | return; | 1327 | return; |
1320 | } | 1328 | } |
1321 | } | 1329 | } |
1322 | 1330 | ||
1323 | void Rack::remove(int i) | 1331 | void Rack::remove(int i) |
1324 | { | 1332 | { |
1325 | delete item[i]; | 1333 | delete item[i]; |
1326 | n--; | 1334 | n--; |
1327 | for (;i<n;i++) | 1335 | for (;i<n;i++) |
1328 | item[i]=item[i+1]; | 1336 | item[i]=item[i+1]; |
1329 | layoutTiles(); | 1337 | layoutTiles(); |
1330 | } | 1338 | } |
1331 | 1339 | ||
1332 | void Rack::resizeEvent(QResizeEvent* e) | 1340 | void Rack::resizeEvent(QResizeEvent* e) |
1333 | { | 1341 | { |
1334 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); | 1342 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); |
1335 | QCanvasView::resizeEvent(e); | 1343 | QCanvasView::resizeEvent(e); |
1336 | } | 1344 | } |
1337 | 1345 | ||
1338 | void Rack::contentsMousePressEvent(QMouseEvent* e) | 1346 | void Rack::contentsMousePressEvent(QMouseEvent* e) |
1339 | { | 1347 | { |
1340 | if ( computerized() ) | 1348 | if ( computerized() ) |
1341 | return; | 1349 | return; |
1342 | QCanvasItemList list = canvas()->collisions(e->pos()); | 1350 | QCanvasItemList list = canvas()->collisions(e->pos()); |
1343 | if (list.count()) { | 1351 | if (list.count()) { |
1344 | dragging = list.first(); | 1352 | dragging = list.first(); |
1345 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); | 1353 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); |
1346 | } else { | 1354 | } else { |
1347 | dragging = 0; | 1355 | dragging = 0; |
1348 | } | 1356 | } |
1349 | } | 1357 | } |
1350 | 1358 | ||
1351 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) | 1359 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) |
1352 | { | 1360 | { |
1353 | if ( computerized() ) | 1361 | if ( computerized() ) |
1354 | return; | 1362 | return; |
1355 | //int w = TileItem::bigWidth()+2; | 1363 | //int w = TileItem::bigWidth()+2; |
1356 | if ( dragging ) { | 1364 | if ( dragging ) { |
1357 | dragging_adj = TileItem::bigWidth()/2; | 1365 | dragging_adj = TileItem::bigWidth()/2; |
1358 | if ( dragging->x() > e->x()-dragstart.x() ) | 1366 | if ( dragging->x() > e->x()-dragstart.x() ) |
1359 | dragging_adj = -dragging_adj; | 1367 | dragging_adj = -dragging_adj; |
1360 | dragging->move(e->x()-dragstart.x(),0); | 1368 | dragging->move(e->x()-dragstart.x(),0); |
1361 | layoutTiles(); | 1369 | layoutTiles(); |
1362 | } | 1370 | } |
1363 | } | 1371 | } |
1364 | 1372 | ||
1365 | void Rack::contentsMouseReleaseEvent(QMouseEvent* e) | 1373 | void Rack::contentsMouseReleaseEvent(QMouseEvent* /*e*/) |
1366 | { | 1374 | { |
1367 | if ( computerized() ) | 1375 | if ( computerized() ) |
1368 | return; | 1376 | return; |
1369 | if ( dragging ) { | 1377 | if ( dragging ) { |
1370 | dragging=0; | 1378 | dragging=0; |
1371 | layoutTiles(); | 1379 | layoutTiles(); |
1372 | } | 1380 | } |
1373 | } | 1381 | } |
1374 | 1382 | ||
1375 | Tile::Tile(const QString& key) | 1383 | Tile::Tile(const QString& key) |
1376 | { | 1384 | { |
1377 | int a=key.find('@'); | 1385 | int a=key.find('@'); |
1378 | txt = key.left(a); | 1386 | txt = key.left(a); |
1379 | val = key.mid(a+1).toInt(); | 1387 | val = key.mid(a+1).toInt(); |
1380 | blank = txt.isEmpty(); | 1388 | blank = txt.isEmpty(); |
1381 | } | 1389 | } |
1382 | 1390 | ||
1383 | QString Tile::key() const | 1391 | QString Tile::key() const |
1384 | { | 1392 | { |
1385 | return txt+"@"+QString::number(val); | 1393 | return txt+"@"+QString::number(val); |
1386 | } | 1394 | } |
1387 | 1395 | ||
1388 | Bag::Bag() | 1396 | Bag::Bag() |
1389 | { | 1397 | { |
1390 | tiles.setAutoDelete(TRUE); | 1398 | tiles.setAutoDelete(TRUE); |
1391 | } | 1399 | } |
1392 | 1400 | ||
1393 | void Bag::writeConfig(Config& cfg) | 1401 | void Bag::writeConfig(Config& cfg) |
1394 | { | 1402 | { |
1395 | QStringList t; | 1403 | QStringList t; |
1396 | for (QListIterator<Tile> it(tiles); it; ++it) | 1404 | for (QListIterator<Tile> it(tiles); it; ++it) |
1397 | t.append((*it)->key()); | 1405 | t.append((*it)->key()); |
1398 | cfg.writeEntry("Tiles",t,';'); | 1406 | cfg.writeEntry("Tiles",t,';'); |
1399 | } | 1407 | } |
1400 | 1408 | ||
1401 | void Bag::readConfig(Config& cfg) | 1409 | void Bag::readConfig(Config& cfg) |
1402 | { | 1410 | { |
1403 | tiles.clear(); | 1411 | tiles.clear(); |
1404 | QStringList t = cfg.readListEntry("Tiles",';'); | 1412 | QStringList t = cfg.readListEntry("Tiles",';'); |
1405 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) | 1413 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) |
1406 | add(Tile(*it)); | 1414 | add(Tile(*it)); |
1407 | } | 1415 | } |
1408 | 1416 | ||
1409 | void Bag::add(const Tile& t) | 1417 | void Bag::add(const Tile& t) |
1410 | { | 1418 | { |
1411 | tiles.append(new Tile(t)); | 1419 | tiles.append(new Tile(t)); |
1412 | } | 1420 | } |
1413 | 1421 | ||
1414 | Tile Bag::takeRandom() | 1422 | Tile Bag::takeRandom() |
1415 | { | 1423 | { |
1416 | Tile* rp = tiles.take(random()%tiles.count()); | 1424 | Tile* rp = tiles.take(random()%tiles.count()); |
1417 | Tile r=*rp; | 1425 | Tile r=*rp; |
1418 | return r; | 1426 | return r; |
1419 | } | 1427 | } |
1420 | 1428 | ||
1421 | ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) : | 1429 | ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) : |
1422 | QLabel("<P>",parent,name,fl) | 1430 | QLabel("<P>",parent,name,fl) |
1423 | { | 1431 | { |
1424 | score=0; | 1432 | score=0; |
1425 | msgtimer = new QTimer(this); | 1433 | msgtimer = new QTimer(this); |
1426 | connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores())); | 1434 | connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores())); |
1427 | setBackgroundMode( PaletteButton ); | 1435 | setBackgroundMode( PaletteButton ); |
1428 | } | 1436 | } |
1429 | 1437 | ||
1430 | ScoreInfo::~ScoreInfo() | 1438 | ScoreInfo::~ScoreInfo() |
1431 | { | 1439 | { |
1432 | if ( score ) delete [] score; | 1440 | if ( score ) delete [] score; |
1433 | } | 1441 | } |
1434 | 1442 | ||
1435 | void ScoreInfo::writeConfig(Config& cfg) | 1443 | void ScoreInfo::writeConfig(Config& cfg) |
1436 | { | 1444 | { |
1437 | QStringList l; | 1445 | QStringList l; |
1438 | for (int i=0; i<(int)names.count(); i++) | 1446 | for (int i=0; i<(int)names.count(); i++) |
1439 | l.append(QString::number(score[i])); | 1447 | l.append(QString::number(score[i])); |
1440 | cfg.writeEntry("Scores",l,';'); | 1448 | cfg.writeEntry("Scores",l,';'); |
1441 | } | 1449 | } |
1442 | 1450 | ||
1443 | void ScoreInfo::readConfig(Config& cfg) | 1451 | void ScoreInfo::readConfig(Config& cfg) |
1444 | { | 1452 | { |
1445 | QStringList l = cfg.readListEntry("Scores",';'); | 1453 | QStringList l = cfg.readListEntry("Scores",';'); |
1446 | int i=0; | 1454 | int i=0; |
1447 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it ) | 1455 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it ) |
1448 | score[i++]=(*it).toInt(); | 1456 | score[i++]=(*it).toInt(); |
1449 | showScores(); | 1457 | showScores(); |
1450 | } | 1458 | } |
1451 | 1459 | ||
1452 | 1460 | ||
1453 | QSize ScoreInfo::sizeHint() const | 1461 | QSize ScoreInfo::sizeHint() const |
1454 | { | 1462 | { |
1455 | return QSize(QLabel::sizeHint().width(),fontMetrics().height()); | 1463 | return QSize(QLabel::sizeHint().width(),fontMetrics().height()); |
1456 | } | 1464 | } |
1457 | 1465 | ||
1458 | void ScoreInfo::init(const QStringList& namelist) | 1466 | void ScoreInfo::init(const QStringList& namelist) |
1459 | { | 1467 | { |
1460 | names = namelist; | 1468 | names = namelist; |
1461 | if ( score ) delete [] score; | 1469 | if ( score ) delete [] score; |
1462 | score = new int[names.count()]; | 1470 | score = new int[names.count()]; |
1463 | memset(score,0,sizeof(int)*names.count()); | 1471 | memset(score,0,sizeof(int)*names.count()); |
1464 | boldone = -1; | 1472 | boldone = -1; |
1465 | showScores(); | 1473 | showScores(); |
1466 | } | 1474 | } |
1467 | 1475 | ||
1468 | void ScoreInfo::addScore(int player, int change) | 1476 | void ScoreInfo::addScore(int player, int change) |
1469 | { | 1477 | { |
1470 | score[player] += change; | 1478 | score[player] += change; |
1471 | showScores(); | 1479 | showScores(); |
1472 | } | 1480 | } |
1473 | 1481 | ||
1474 | void ScoreInfo::setBoldOne(int b) | 1482 | void ScoreInfo::setBoldOne(int b) |
1475 | { | 1483 | { |
1476 | boldone=b; | 1484 | boldone=b; |
1477 | showScores(); | 1485 | showScores(); |
1478 | } | 1486 | } |
1479 | 1487 | ||
1480 | void ScoreInfo::showScores() | 1488 | void ScoreInfo::showScores() |
1481 | { | 1489 | { |
1482 | QString r="<p>"; | 1490 | QString r="<p>"; |
1483 | int i=0; | 1491 | int i=0; |
1484 | //int spl=(names.count()+1)/2; // 2 lines | 1492 | //int spl=(names.count()+1)/2; // 2 lines |
1485 | for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) { | 1493 | for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) { |
1486 | if ( i==boldone ) r += "<b>"; | 1494 | if ( i==boldone ) r += "<b>"; |
1487 | QString n = *it; | 1495 | QString n = *it; |
1488 | n.replace(QRegExp(":.*"),""); | 1496 | n.replace(QRegExp(":.*"),""); |
1489 | r += n; | 1497 | r += n; |
1490 | r += ":"; | 1498 | r += ":"; |
1491 | r += QString::number(score[i]); | 1499 | r += QString::number(score[i]); |
1492 | if ( i==boldone ) r += "</b>"; | 1500 | if ( i==boldone ) r += "</b>"; |
1493 | 1501 | ||
1494 | ++i; | 1502 | ++i; |
1495 | ++it; | 1503 | ++it; |
1496 | if ( it != names.end() ) | 1504 | if ( it != names.end() ) |
1497 | r += " "; | 1505 | r += " "; |
1498 | } | 1506 | } |
1499 | setText(r); | 1507 | setText(r); |
1500 | } | 1508 | } |
1501 | 1509 | ||
1502 | void ScoreInfo::showTemporaryScore(int amount) | 1510 | void ScoreInfo::showTemporaryScore(int amount) |
1503 | { | 1511 | { |
1504 | if ( amount < 0 ) | 1512 | if ( amount < 0 ) |
1505 | setText(tr("<P>Invalid move")); | 1513 | setText(tr("<P>Invalid move")); |
1506 | else | 1514 | else |
1507 | setText(tr("<P>Score: ")+QString::number(amount)); | 1515 | setText(tr("<P>Score: ")+QString::number(amount)); |
1508 | msgtimer->start(3000,TRUE); | 1516 | msgtimer->start(3000,TRUE); |
1509 | } | 1517 | } |
1510 | 1518 | ||
diff --git a/noncore/games/zlines/ballpainter.cpp b/noncore/games/zlines/ballpainter.cpp index 622ec29..e7596c4 100644 --- a/noncore/games/zlines/ballpainter.cpp +++ b/noncore/games/zlines/ballpainter.cpp | |||
@@ -1,132 +1,132 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | ballpainter.cpp - description | 2 | ballpainter.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | #include <qpe/resource.h> | 20 | #include <opie2/oresource.h> |
21 | 21 | ||
22 | #include "ballpainter.h" | 22 | #include "ballpainter.h" |
23 | //#include "shotcounter.h" | 23 | //#include "shotcounter.h" |
24 | #include <qpainter.h> | 24 | #include <qpainter.h> |
25 | //#include <qcolor.h> | 25 | //#include <qcolor.h> |
26 | 26 | ||
27 | 27 | ||
28 | #define PIXSIZE 21 | 28 | #define PIXSIZE 21 |
29 | 29 | ||
30 | int colorLinesArr[NCOLORS] = | 30 | int colorLinesArr[NCOLORS] = |
31 | {0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080}; | 31 | {0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080}; |
32 | // 0x00bbggrr | 32 | // 0x00bbggrr |
33 | // red , green , blue , yellow , violet , cyan , brown | 33 | // red , green , blue , yellow , violet , cyan , brown |
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | BallPainter::BallPainter() | 37 | BallPainter::BallPainter() |
38 | : QObject() | 38 | : QObject() |
39 | { | 39 | { |
40 | createPixmap(); | 40 | createPixmap(); |
41 | } | 41 | } |
42 | 42 | ||
43 | BallPainter::~BallPainter() | 43 | BallPainter::~BallPainter() |
44 | { | 44 | { |
45 | } | 45 | } |
46 | 46 | ||
47 | QPixmap* BallPainter::pixmap( enum Pixmaps pix ) | 47 | QPixmap* BallPainter::pixmap( enum Pixmaps pix ) |
48 | { | 48 | { |
49 | QString name; | 49 | QString name; |
50 | switch(pix) { | 50 | switch(pix) { |
51 | case Field: | 51 | case Field: |
52 | name = QString::fromLatin1("zlines/field"); | 52 | name = QString::fromLatin1("zlines/field"); |
53 | break; | 53 | break; |
54 | case Balls: | 54 | case Balls: |
55 | name = QString::fromLatin1("zlines/balls"); | 55 | name = QString::fromLatin1("zlines/balls"); |
56 | break; | 56 | break; |
57 | case Fire: | 57 | case Fire: |
58 | name = QString::fromLatin1("zlines/fire"); | 58 | name = QString::fromLatin1("zlines/fire"); |
59 | break; | 59 | break; |
60 | } | 60 | } |
61 | 61 | ||
62 | return new QPixmap(Resource::loadPixmap(name) ); | 62 | return new QPixmap(Opie::Core::OResource::loadPixmap(name) ); |
63 | } | 63 | } |
64 | 64 | ||
65 | void BallPainter::createPixmap() | 65 | void BallPainter::createPixmap() |
66 | { | 66 | { |
67 | // warning( kapp->kde_datadir() +"/klines/data/balls.bmp"); | 67 | // warning( kapp->kde_datadir() +"/klines/data/balls.bmp"); |
68 | backgroundPix = pixmap(Field); | 68 | backgroundPix = pixmap(Field); |
69 | QPixmap *balls = pixmap(Balls); | 69 | QPixmap *balls = pixmap(Balls); |
70 | QPixmap *fire = pixmap(Fire); | 70 | QPixmap *fire = pixmap(Fire); |
71 | if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() ) | 71 | if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() ) |
72 | fatal("Cannot open data files.\nHave you correctly installed klines?"); | 72 | fatal("Cannot open data files.\nHave you correctly installed klines?"); |
73 | 73 | ||
74 | warning("Pixsize %i", PIXSIZE); | 74 | warning("Pixsize %i", PIXSIZE); |
75 | for(int c=0; c<NCOLORS; c++) | 75 | for(int c=0; c<NCOLORS; c++) |
76 | { | 76 | { |
77 | for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++) | 77 | for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++) |
78 | { | 78 | { |
79 | imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE); | 79 | imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE); |
80 | QPainter p(imgCash[c][t]); | 80 | QPainter p(imgCash[c][t]); |
81 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); | 81 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); |
82 | p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE); | 82 | p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE); |
83 | } | 83 | } |
84 | for(int t=0; t < FIREPIX ; t++) | 84 | for(int t=0; t < FIREPIX ; t++) |
85 | { | 85 | { |
86 | firePix[t] = new QPixmap(CELLSIZE, CELLSIZE); | 86 | firePix[t] = new QPixmap(CELLSIZE, CELLSIZE); |
87 | QPainter p(firePix[t]); | 87 | QPainter p(firePix[t]); |
88 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); | 88 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); |
89 | p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE); | 89 | p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | delete balls; | 92 | delete balls; |
93 | delete fire; | 93 | delete fire; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | QPixmap* BallPainter::GetBall(int color, int animstep, int panim) | 97 | QPixmap* BallPainter::GetBall(int color, int animstep, int panim) |
98 | { | 98 | { |
99 | // return backgroundPix; | 99 | // return backgroundPix; |
100 | 100 | ||
101 | if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL ) | 101 | if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL ) |
102 | { | 102 | { |
103 | // warning("BallPainter::Background"); | 103 | // warning("BallPainter::Background"); |
104 | return backgroundPix; | 104 | return backgroundPix; |
105 | } | 105 | } |
106 | if ( panim == ANIM_JUMP ) | 106 | if ( panim == ANIM_JUMP ) |
107 | { | 107 | { |
108 | if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) ) | 108 | if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) ) |
109 | return backgroundPix; | 109 | return backgroundPix; |
110 | else | 110 | else |
111 | return imgCash[color][animstep]; | 111 | return imgCash[color][animstep]; |
112 | } | 112 | } |
113 | else if ( panim == ANIM_BURN ) | 113 | else if ( panim == ANIM_BURN ) |
114 | { | 114 | { |
115 | if ( animstep < FIREBALLS ) | 115 | if ( animstep < FIREBALLS ) |
116 | return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1]; | 116 | return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1]; |
117 | else if ( animstep < FIREBALLS + FIREPIX ) | 117 | else if ( animstep < FIREBALLS + FIREPIX ) |
118 | return firePix[animstep - FIREBALLS]; | 118 | return firePix[animstep - FIREBALLS]; |
119 | } | 119 | } |
120 | else if ( panim == ANIM_BORN ) | 120 | else if ( panim == ANIM_BORN ) |
121 | { | 121 | { |
122 | if ( animstep < BOOMBALLS ) | 122 | if ( animstep < BOOMBALLS ) |
123 | return imgCash[color][animstep + PIXTIME]; | 123 | return imgCash[color][animstep + PIXTIME]; |
124 | else | 124 | else |
125 | return imgCash[color][NORMALBALL]; | 125 | return imgCash[color][NORMALBALL]; |
126 | } | 126 | } |
127 | // rest is not imlemented yet | 127 | // rest is not imlemented yet |
128 | return imgCash[color][NORMALBALL]; | 128 | return imgCash[color][NORMALBALL]; |
129 | 129 | ||
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||