| 1 | // $Header$ |
|---|
| 2 | /*************************************************************************** |
|---|
| 3 | * Copyright (C) 2006 by Guy Rutenberg * |
|---|
| 4 | * guyrutenberg@gmail.com * |
|---|
| 5 | * * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 7 | * it under the terms of the GNU General Public License as published by * |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 9 | * (at your option) any later version. * |
|---|
| 10 | * * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, * |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 14 | * GNU General Public License for more details. * |
|---|
| 15 | * * |
|---|
| 16 | * You should have received a copy of the GNU General Public License * |
|---|
| 17 | * along with this program; if not, write to the * |
|---|
| 18 | * Free Software Foundation, Inc., * |
|---|
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | /*********************************************** |
|---|
| 23 | * This File contains the definitions * |
|---|
| 24 | * of MainFrame's functions * |
|---|
| 25 | ***********************************************/ |
|---|
| 26 | |
|---|
| 27 | //#define DEBUG |
|---|
| 28 | |
|---|
| 29 | #include <wx/wx.h> |
|---|
| 30 | |
|---|
| 31 | #include "MainFrame.h" |
|---|
| 32 | #include "wxDynamicBitmap.h" |
|---|
| 33 | #include "ObjectsID.h" |
|---|
| 34 | #include "HighScoreDialog.h" |
|---|
| 35 | #include "SettingsDialog.h" |
|---|
| 36 | #include <iostream> |
|---|
| 37 | #include <sstream> |
|---|
| 38 | #include <cstdlib> |
|---|
| 39 | #include <wx/version.h> |
|---|
| 40 | |
|---|
| 41 | //include the images for the dice |
|---|
| 42 | #include "one.xpm" |
|---|
| 43 | #include "two.xpm" |
|---|
| 44 | #include "three.xpm" |
|---|
| 45 | #include "four.xpm" |
|---|
| 46 | #include "five.xpm" |
|---|
| 47 | #include "six.xpm" |
|---|
| 48 | |
|---|
| 49 | //include the icon file |
|---|
| 50 | #include "Icon.h" |
|---|
| 51 | |
|---|
| 52 | //default values |
|---|
| 53 | #define SPACE_SIZE 1 |
|---|
| 54 | #define DEF_HIGHSCORESIZE 20 |
|---|
| 55 | #define OY_VERSION "1.7.0" |
|---|
| 56 | |
|---|
| 57 | MainFrame::MainFrame(const wxString& title, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE) |
|---|
| 58 | : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, size, style) |
|---|
| 59 | { |
|---|
| 60 | //give the frame an icon |
|---|
| 61 | SetIcon(wxIcon(ICON)); |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | std::ostringstream sstr; |
|---|
| 65 | |
|---|
| 66 | m_settingsdb = new SettingsDB(); //Get the settings database connection |
|---|
| 67 | m_highscoredb = new HighScoreTableDB(); |
|---|
| 68 | |
|---|
| 69 | //DATABASE initialization |
|---|
| 70 | if (m_settingsdb->GetKey("highscoresize") == "") { //check if we need to create a new high score table |
|---|
| 71 | m_highscoredb->SetSize(DEF_HIGHSCORESIZE); |
|---|
| 72 | sstr<<DEF_HIGHSCORESIZE<<std::flush; |
|---|
| 73 | m_settingsdb->SetKey("highscoresize", sstr.str()); |
|---|
| 74 | } else { |
|---|
| 75 | int highscoresize = atoi((m_settingsdb->GetKey("highscoresize")).c_str()); |
|---|
| 76 | //m_highscoredb->SetSize((highscoresize>0)?highscoresize:DEF_HIGHSCORESIZE); |
|---|
| 77 | m_highscoredb->SetSize(highscoresize); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | if (m_settingsdb->GetKey("animate") == "Yes") { |
|---|
| 81 | m_animate = true; |
|---|
| 82 | } else if (m_settingsdb->GetKey("animate") == "No") { |
|---|
| 83 | m_animate = false; |
|---|
| 84 | } else { |
|---|
| 85 | m_settingsdb->SetKey("animate", "Yes"); |
|---|
| 86 | m_animate = true; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | // END Database initialization |
|---|
| 90 | |
|---|
| 91 | bitmap_dices[0] = new wxBitmap(one_xpm); |
|---|
| 92 | bitmap_dices[1] = new wxBitmap(two_xpm); |
|---|
| 93 | bitmap_dices[2] = new wxBitmap(three_xpm); |
|---|
| 94 | bitmap_dices[3] = new wxBitmap(four_xpm); |
|---|
| 95 | bitmap_dices[4] = new wxBitmap(five_xpm); |
|---|
| 96 | bitmap_dices[5] = new wxBitmap(six_xpm); |
|---|
| 97 | |
|---|
| 98 | //randomize the random-number generator based on the time |
|---|
| 99 | srand( (unsigned)time( NULL ) ); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | /*****Create and initialize the menu bar******/ |
|---|
| 103 | |
|---|
| 104 | /*Create the menus*/ |
|---|
| 105 | wxMenu *gameMenu = new wxMenu; //create File menu |
|---|
| 106 | wxMenu *helpMenu = new wxMenu; //create Help menu |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | //insert menu items into menu Help |
|---|
| 110 | helpMenu->Append(ID_CHECK_FOR_UPDATES, wxT("&Check for Updates"), |
|---|
| 111 | wxT("Check for new version of the game via the web")); |
|---|
| 112 | helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), |
|---|
| 113 | wxT("Show about dialog")); |
|---|
| 114 | |
|---|
| 115 | //insert menu items into menu File |
|---|
| 116 | gameMenu->Append(ID_NEWGAME,wxT("&New Game\tF2"),wxT("Start a new game")); |
|---|
| 117 | //create the undo button and make it disabled |
|---|
| 118 | gameMenu->Append(ID_UNDO,wxT("&Undo"),wxT("Undo the last move")); |
|---|
| 119 | gameMenu->Append(ID_SHOWHIGHSCORE,wxT("High &Scores"),wxT("Show high-scores table")); |
|---|
| 120 | gameMenu->Append(ID_SETTINGS,wxT("Settings"),wxT("Show settings dialog")); |
|---|
| 121 | gameMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), |
|---|
| 122 | wxT("Quit this program")); |
|---|
| 123 | |
|---|
| 124 | // Declare the menu-bar and append the freshly created menus to the menu bar... |
|---|
| 125 | wxMenuBar *menuBar = new wxMenuBar(); |
|---|
| 126 | menuBar->Append(gameMenu, wxT("&Game")); |
|---|
| 127 | menuBar->Append(helpMenu, wxT("&Help")); |
|---|
| 128 | |
|---|
| 129 | // ... and attach this menu bar to the frame |
|---|
| 130 | SetMenuBar(menuBar); |
|---|
| 131 | |
|---|
| 132 | /***End menu-bar ***/ |
|---|
| 133 | wxPanel* panel = new wxPanel(this, ID_PANEL, |
|---|
| 134 | wxDefaultPosition, wxDefaultSize); |
|---|
| 135 | |
|---|
| 136 | wxBoxSizer *topSizer = new wxBoxSizer( wxHORIZONTAL ); |
|---|
| 137 | wxBoxSizer *sectionsSizer = new wxBoxSizer( wxVERTICAL ); |
|---|
| 138 | wxBoxSizer *diceSizer = new wxBoxSizer( wxVERTICAL ); |
|---|
| 139 | |
|---|
| 140 | wxSizer *uppersection = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Upper Section") ), wxVERTICAL); |
|---|
| 141 | wxSizer *lowersection = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Lower Section") ), wxVERTICAL); |
|---|
| 142 | |
|---|
| 143 | wxFlexGridSizer* uppergrid = new wxFlexGridSizer(9, 2, 0, 0); |
|---|
| 144 | wxFlexGridSizer* lowergrid = new wxFlexGridSizer(9, 2, 0, 0); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | uppergrid->Add(new wxButton(panel,ID_ACES,wxT("Aces")),0,wxALL,SPACE_SIZE); |
|---|
| 148 | uppergrid->Add(new wxTextCtrl(panel, ID_ACESTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 149 | uppergrid->Add(new wxButton(panel,ID_TWOS,wxT("Twos")),0,wxALL,SPACE_SIZE); |
|---|
| 150 | uppergrid->Add(new wxTextCtrl(panel, ID_TWOSTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 151 | uppergrid->Add(new wxButton(panel,ID_THREES,wxT("Threes")),0,wxALL,SPACE_SIZE); |
|---|
| 152 | uppergrid->Add(new wxTextCtrl(panel, ID_THREESTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 153 | uppergrid->Add(new wxButton(panel,ID_FOURS,wxT("Fours")),0,wxALL,SPACE_SIZE); |
|---|
| 154 | uppergrid->Add(new wxTextCtrl(panel, ID_FOURSTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 155 | uppergrid->Add(new wxButton(panel,ID_FIVES,wxT("Fives")),0,wxALL,SPACE_SIZE); |
|---|
| 156 | uppergrid->Add(new wxTextCtrl(panel, ID_FIVESTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 157 | uppergrid->Add(new wxButton(panel,ID_SIXES,wxT("Sixes")),0,wxALL,SPACE_SIZE); |
|---|
| 158 | uppergrid->Add(new wxTextCtrl(panel, ID_SIXESTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 159 | uppergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Total score:")),0,wxALL,SPACE_SIZE); |
|---|
| 160 | uppergrid->Add(new wxTextCtrl(panel, ID_UPPERSECTIONTOTAL),1,wxALL,SPACE_SIZE); |
|---|
| 161 | uppergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Bonus:")),0,wxALL,SPACE_SIZE); |
|---|
| 162 | uppergrid->Add(new wxTextCtrl(panel, ID_BONUS),1,wxALL,SPACE_SIZE); |
|---|
| 163 | uppergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Total of upper section:")),0,wxALL,SPACE_SIZE); |
|---|
| 164 | uppergrid->Add(new wxTextCtrl(panel, ID_UPPERTOTAL),1,wxALL,SPACE_SIZE); |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | lowergrid->Add(new wxButton(panel,ID_THREEOFAKIND,wxT("3 of a kind")),0,wxALL,SPACE_SIZE); |
|---|
| 168 | lowergrid->Add(new wxTextCtrl(panel, ID_THREEOFAKINDTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 169 | lowergrid->Add(new wxButton(panel,ID_FOUROFAKIND,wxT("4 of a kind")),0,wxALL,SPACE_SIZE); |
|---|
| 170 | lowergrid->Add(new wxTextCtrl(panel, ID_FOUROFAKINDTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 171 | lowergrid->Add(new wxButton(panel,ID_FULLHOUSE,wxT("Full House")),0,wxALL,SPACE_SIZE); |
|---|
| 172 | lowergrid->Add(new wxTextCtrl(panel, ID_FULLHOUSETEXT),1,wxALL,SPACE_SIZE); |
|---|
| 173 | lowergrid->Add(new wxButton(panel,ID_SMALLSEQUENCE,wxT("Sequence of 4")),0,wxALL,SPACE_SIZE); |
|---|
| 174 | lowergrid->Add(new wxTextCtrl(panel, ID_SMALLSEQUENCETEXT),1,wxALL,SPACE_SIZE); |
|---|
| 175 | lowergrid->Add(new wxButton(panel,ID_LARGESEQUENCE,wxT("Sequence of 5")),0,wxALL,SPACE_SIZE); |
|---|
| 176 | lowergrid->Add(new wxTextCtrl(panel, ID_LARGESEQUENCETEXT),1,wxALL,SPACE_SIZE); |
|---|
| 177 | lowergrid->Add(new wxButton(panel,ID_YAHTZEE,wxT("Yahtzee")),0,wxALL,SPACE_SIZE); |
|---|
| 178 | lowergrid->Add(new wxTextCtrl(panel, ID_YAHTZEETEXT),1,wxALL,SPACE_SIZE); |
|---|
| 179 | lowergrid->Add(new wxButton(panel,ID_CHANCE,wxT("Chance")),0,wxALL,SPACE_SIZE); |
|---|
| 180 | lowergrid->Add(new wxTextCtrl(panel, ID_CHANCETEXT),1,wxALL,SPACE_SIZE); |
|---|
| 181 | lowergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Yahtzee Bonus")),0,wxALL,SPACE_SIZE); |
|---|
| 182 | lowergrid->Add(new wxTextCtrl(panel, ID_YAHTZEEBONUSTEXT),1,wxALL,SPACE_SIZE); |
|---|
| 183 | lowergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Total of lower section:")),0,wxALL,SPACE_SIZE); |
|---|
| 184 | lowergrid->Add(new wxTextCtrl(panel, ID_LOWERTOTAL),1,wxALL,SPACE_SIZE); |
|---|
| 185 | lowergrid->Add(new wxStaticText(panel, wxID_ANY, wxT("Grand Total:")),0,wxALL,SPACE_SIZE); |
|---|
| 186 | lowergrid->Add(new wxTextCtrl(panel, ID_GRANDTOTAL),1,wxALL,SPACE_SIZE); |
|---|
| 187 | |
|---|
| 188 | uppersection->Add(uppergrid); |
|---|
| 189 | lowersection->Add(lowergrid); |
|---|
| 190 | sectionsSizer->Add(uppersection,0,wxALL,5); |
|---|
| 191 | sectionsSizer->Add(lowersection,0,wxALL,5); |
|---|
| 192 | |
|---|
| 193 | diceSizer->Add(new wxDynamicBitmap(panel,ID_DICE1,*bitmap_dices[0]),0,wxALL,3); |
|---|
| 194 | diceSizer->Add(new wxCheckBox(panel, ID_DICE1KEEP, wxT("Keep")),0,wxBOTTOM,10); |
|---|
| 195 | diceSizer->Add(new wxDynamicBitmap(panel,ID_DICE2,*bitmap_dices[1]),0,wxALL,3); |
|---|
| 196 | diceSizer->Add(new wxCheckBox(panel, ID_DICE2KEEP, wxT("Keep")),0,wxBOTTOM,10); |
|---|
| 197 | diceSizer->Add(new wxDynamicBitmap(panel,ID_DICE3,*bitmap_dices[2]),0,wxALL,3); |
|---|
| 198 | diceSizer->Add(new wxCheckBox(panel, ID_DICE3KEEP, wxT("Keep")),0,wxBOTTOM,10); |
|---|
| 199 | diceSizer->Add(new wxDynamicBitmap(panel,ID_DICE4,*bitmap_dices[3]),0,wxALL,3); |
|---|
| 200 | diceSizer->Add(new wxCheckBox(panel, ID_DICE4KEEP, wxT("Keep")),0,wxBOTTOM,10); |
|---|
| 201 | diceSizer->Add(new wxDynamicBitmap(panel,ID_DICE5,*bitmap_dices[4]),0,wxALL,3); |
|---|
| 202 | diceSizer->Add(new wxCheckBox(panel, ID_DICE5KEEP, wxT("Keep")),0,wxBOTTOM,10); |
|---|
| 203 | diceSizer->Add(new wxButton(panel, ID_ROLL, wxT("Roll")),0,wxALL,3); |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | topSizer->Add(sectionsSizer); |
|---|
| 207 | topSizer->Add(diceSizer); |
|---|
| 208 | |
|---|
| 209 | panel->SetSizer(topSizer); |
|---|
| 210 | |
|---|
| 211 | topSizer->Fit(this); |
|---|
| 212 | topSizer->SetSizeHints(this); |
|---|
| 213 | |
|---|
| 214 | //make the text boxes uneditable to the user |
|---|
| 215 | wxTextCtrl *textctrl; |
|---|
| 216 | for(int i = ID_ACESTEXT;i<=ID_GRANDTOTAL;i++) { |
|---|
| 217 | textctrl = (wxTextCtrl*) FindWindow(i); |
|---|
| 218 | textctrl->SetEditable(false); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | //disable the undo button |
|---|
| 222 | (GetMenuBar()->FindItem(ID_UNDO))->Enable(false); |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | /***************************************/ |
|---|
| 228 | /********* Declare Event Table *********/ |
|---|
| 229 | /***************************************/ |
|---|
| 230 | |
|---|
| 231 | /***Connect Menu items***/ |
|---|
| 232 | Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnQuit)); |
|---|
| 233 | Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAbout)); |
|---|
| 234 | Connect(ID_CHECK_FOR_UPDATES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnCheckForUpdates)); |
|---|
| 235 | Connect(ID_NEWGAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnNewGame)); |
|---|
| 236 | Connect(ID_UNDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnUndo)); |
|---|
| 237 | Connect(ID_SHOWHIGHSCORE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnShowHighscore)); |
|---|
| 238 | Connect(ID_SETTINGS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnSettings)); |
|---|
| 239 | Connect(ID_ROLL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnRollButton)); |
|---|
| 240 | |
|---|
| 241 | Connect(ID_ACES,ID_SIXES, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnUpperButtons)); |
|---|
| 242 | Connect(ID_THREEOFAKIND, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::On3ofakindButton)); |
|---|
| 243 | Connect(ID_FOUROFAKIND, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::On4ofakindButton)); |
|---|
| 244 | Connect(ID_FULLHOUSE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnFullHouseButton)); |
|---|
| 245 | Connect(ID_SMALLSEQUENCE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnSmallSequenceButton)); |
|---|
| 246 | Connect(ID_LARGESEQUENCE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnLargeSequenceButton)); |
|---|
| 247 | Connect(ID_YAHTZEE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnYahtzeeButton)); |
|---|
| 248 | Connect(ID_CHANCE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnChanceButton)); |
|---|
| 249 | |
|---|
| 250 | /*** End of Event Table ***/ |
|---|
| 251 | |
|---|
| 252 | ResetRolls(); |
|---|
| 253 | ClearDiceHash(); |
|---|
| 254 | m_yahtzee = false; |
|---|
| 255 | m_yahtzeebonus = false; |
|---|
| 256 | m_numofplaysleft = 13; |
|---|
| 257 | |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | /*********EVENT PROCCESSING FUNCTIONS********/ |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | void MainFrame::OnAbout(wxCommandEvent& event) |
|---|
| 264 | { |
|---|
| 265 | wxString msg; |
|---|
| 266 | wxString sqliteversion = wxString(sqlite3_version,wxConvUTF8); |
|---|
| 267 | msg.Printf(wxT("Open Yahtzee %s\nCopyright (C) 2006 by Guy Rutenberg\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.\n\nOpen Yahtzee was built against:\nwxWidgets %i.%i\n"),wxT(OY_VERSION),wxMAJOR_VERSION,wxMINOR_VERSION); |
|---|
| 268 | msg += wxT("SQLite ") + sqliteversion; |
|---|
| 269 | |
|---|
| 270 | wxMessageBox(msg, wxT("About Open Yahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | void MainFrame::OnCheckForUpdates (wxCommandEvent& event){ |
|---|
| 274 | |
|---|
| 275 | wxString path; |
|---|
| 276 | wxPathList path_list; |
|---|
| 277 | wxString link = wxT("http://openyahtzee.sourceforge.net/update.php?version="); |
|---|
| 278 | |
|---|
| 279 | link += wxT(OY_VERSION); |
|---|
| 280 | |
|---|
| 281 | if (!wxLaunchDefaultBrowser(link)){ |
|---|
| 282 | //if builtin function doesn't work search for couple of browsers manually. see |
|---|
| 283 | //http://linux-consulting.buanzo.com.ar/2006/05/wxwidgets-code-to-launch-browser.html |
|---|
| 284 | |
|---|
| 285 | // variable declarations |
|---|
| 286 | wxArrayString browsers; |
|---|
| 287 | wxPathList path_list; |
|---|
| 288 | bool BrowserWasFound = false; |
|---|
| 289 | unsigned int i = 0; |
|---|
| 290 | wxString path; |
|---|
| 291 | |
|---|
| 292 | // Add directories to wxPathList's search path from PATH environment variable |
|---|
| 293 | path_list.AddEnvList(wxT("PATH")); |
|---|
| 294 | |
|---|
| 295 | // Add browsers filenames. First item = most priority |
|---|
| 296 | browsers.Add(wxT("firefox")); |
|---|
| 297 | browsers.Add(wxT("firefox-bin")); |
|---|
| 298 | browsers.Add(wxT("mozilla")); |
|---|
| 299 | browsers.Add(wxT("mozilla-bin")); |
|---|
| 300 | browsers.Add(wxT("opera")); |
|---|
| 301 | browsers.Add(wxT("konqueror")); |
|---|
| 302 | browsers.Add(wxT("epiphany")); |
|---|
| 303 | |
|---|
| 304 | for (i = 0; i < browsers.GetCount(); i++) { |
|---|
| 305 | path = path_list.FindAbsoluteValidPath(browsers[i]); |
|---|
| 306 | if (path.IsEmpty()) { |
|---|
| 307 | continue; |
|---|
| 308 | } else { |
|---|
| 309 | BrowserWasFound = true; |
|---|
| 310 | break; |
|---|
| 311 | } |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | browsers.Clear(); |
|---|
| 315 | |
|---|
| 316 | if (BrowserWasFound) { |
|---|
| 317 | path += wxT(" "); |
|---|
| 318 | path += link; |
|---|
| 319 | ::wxExecute(path); |
|---|
| 320 | } else { |
|---|
| 321 | wxMessageBox(wxT("No browser has been found."),wxT("OpenYahtzee")); |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | void MainFrame::OnQuit(wxCommandEvent& event) |
|---|
| 329 | { |
|---|
| 330 | // Destroy the frame |
|---|
| 331 | Close(); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | void MainFrame::OnNewGame(wxCommandEvent& event) |
|---|
| 335 | { |
|---|
| 336 | |
|---|
| 337 | ResetRolls(); |
|---|
| 338 | ClearDiceHash(); |
|---|
| 339 | m_yahtzee = false; |
|---|
| 340 | m_numofplaysleft = 13; |
|---|
| 341 | |
|---|
| 342 | for (int i = ID_ACESTEXT; i<= ID_GRANDTOTAL; i++) |
|---|
| 343 | ((wxTextCtrl*) FindWindow(i))->Clear(); |
|---|
| 344 | for (int i = ID_ACES; i<= ID_CHANCE; i++) |
|---|
| 345 | ((wxButton*) FindWindow(i))->Enable(true); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | ///This function handles the undo events |
|---|
| 349 | void MainFrame::OnUndo(wxCommandEvent& event) |
|---|
| 350 | { |
|---|
| 351 | m_rolls = m_rollsundo; |
|---|
| 352 | |
|---|
| 353 | //after the user scored the button was enabled, check if it should be disabled |
|---|
| 354 | if (m_rolls <= 0) //we don't have remaining rolls |
|---|
| 355 | ((wxButton*) FindWindow(ID_ROLL)) -> Enable(false); |
|---|
| 356 | |
|---|
| 357 | //restore the 'keep' checkboxes |
|---|
| 358 | for (int i=0; i<5; i++) |
|---|
| 359 | ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> Enable(true); |
|---|
| 360 | |
|---|
| 361 | //reset the users last choice |
|---|
| 362 | FindWindow(m_lastmove)->Enable(true); |
|---|
| 363 | |
|---|
| 364 | //clear the score; |
|---|
| 365 | ((wxTextCtrl*)FindWindow(ID_ACESTEXT + (m_lastmove - ID_ACES)))->SetValue(wxT("")); |
|---|
| 366 | |
|---|
| 367 | //undo also the yahtzee bonus if needed |
|---|
| 368 | if (m_yahtzeebonus) { |
|---|
| 369 | long temp; |
|---|
| 370 | wxString tempstr; |
|---|
| 371 | |
|---|
| 372 | tempstr = ((wxTextCtrl*) FindWindow(ID_YAHTZEEBONUSTEXT)) -> GetValue(); |
|---|
| 373 | tempstr.ToLong(&temp,10); |
|---|
| 374 | temp -= 100; //this line reduces the points given for the yahtzee bonus |
|---|
| 375 | tempstr.Printf(wxT("%i"),temp); |
|---|
| 376 | ((wxTextCtrl*) FindWindow(ID_YAHTZEEBONUSTEXT)) -> SetValue(tempstr); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | (GetMenuBar()->FindItem(ID_UNDO))->Enable(false); |
|---|
| 380 | //cancel the counting for the choice that was canceled |
|---|
| 381 | m_numofplaysleft++; |
|---|
| 382 | } |
|---|
| 383 | ///This function enables the undo button and stores the last move |
|---|
| 384 | inline void MainFrame::EnableUndo(int id) |
|---|
| 385 | { |
|---|
| 386 | if (m_numofplaysleft) { |
|---|
| 387 | (GetMenuBar()->FindItem(ID_UNDO))->Enable(true); |
|---|
| 388 | m_lastmove = id; |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | void MainFrame::OnShowHighscore(wxCommandEvent& event) |
|---|
| 393 | { |
|---|
| 394 | HighScoreDialog *dialog = new HighScoreDialog(this,wxID_ANY,m_highscoredb); |
|---|
| 395 | dialog->ShowModal(); |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | void MainFrame::OnSettings( wxCommandEvent& event) |
|---|
| 399 | { |
|---|
| 400 | SettingsDialog *dialog = new SettingsDialog(this,wxID_ANY); |
|---|
| 401 | SettingsDialogData data; |
|---|
| 402 | std::ostringstream sstr; |
|---|
| 403 | |
|---|
| 404 | data.highscoresize = m_highscoredb->GetSize(); |
|---|
| 405 | |
|---|
| 406 | data.animate = (m_settingsdb->GetKey("animate")=="Yes")?true:false; |
|---|
| 407 | |
|---|
| 408 | dialog->SetData(data); |
|---|
| 409 | if(dialog->ShowModal()==wxID_OK) { //user saved Changes |
|---|
| 410 | data = dialog->GetData(); |
|---|
| 411 | |
|---|
| 412 | if(data.reset) |
|---|
| 413 | m_highscoredb->SetSize(0); |
|---|
| 414 | |
|---|
| 415 | sstr<<data.highscoresize<<std::flush; |
|---|
| 416 | m_settingsdb->SetKey("highscoresize",sstr.str()); |
|---|
| 417 | |
|---|
| 418 | m_highscoredb->SetSize(data.highscoresize); |
|---|
| 419 | |
|---|
| 420 | if (data.animate){ |
|---|
| 421 | m_settingsdb->SetKey("animate","Yes"); |
|---|
| 422 | |
|---|
| 423 | } else { |
|---|
| 424 | m_settingsdb->SetKey("animate","No"); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | void MainFrame::OnRollButton (wxCommandEvent& event) |
|---|
| 431 | { |
|---|
| 432 | //roll the dice... |
|---|
| 433 | if (m_animate) { |
|---|
| 434 | int dice_throws[5] = {0,0,0,0,0}; |
|---|
| 435 | for (int i=0; i<5; i++) { //set the number of rolls for each dice |
|---|
| 436 | if (!((wxCheckBox*) FindWindow(i + ID_DICE1KEEP))->IsChecked()) { |
|---|
| 437 | dice_throws[i] = (rand()%15)+3; //ensures the number is at least one. |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | while (dice_throws[0] || dice_throws[1] || dice_throws[2] || dice_throws[3] || dice_throws[4]) { |
|---|
| 441 | for (int i=0 ; i<5; i++){ |
|---|
| 442 | if(dice_throws[i]){ |
|---|
| 443 | dice_throws[i]--; |
|---|
| 444 | dice[i] = rand()%6; |
|---|
| 445 | ((wxDynamicBitmap*) FindWindow(i + ID_DICE1)) -> SetBitmap(*bitmap_dices[dice[i]]); |
|---|
| 446 | } |
|---|
| 447 | } |
|---|
| 448 | ::wxMilliSleep(200); |
|---|
| 449 | } |
|---|
| 450 | } else { |
|---|
| 451 | for (int i=0; i<5; i++) { |
|---|
| 452 | if (!((wxCheckBox*) FindWindow(i + ID_DICE1KEEP))->IsChecked()) { |
|---|
| 453 | dice[i] = rand()%6; |
|---|
| 454 | ((wxStaticBitmap*) FindWindow(i + ID_DICE1)) -> SetBitmap(*bitmap_dices[dice[i]]); |
|---|
| 455 | } |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | //Clear old dice-hash and create a new one |
|---|
| 460 | ClearDiceHash(); |
|---|
| 461 | for (int i=0; i<5; i++) |
|---|
| 462 | dicehash[dice[i]] += 1; |
|---|
| 463 | |
|---|
| 464 | //if out of rolls disable the roll butoon |
|---|
| 465 | m_rolls -= 1; |
|---|
| 466 | #ifndef DEBUG |
|---|
| 467 | if (m_rolls <= 0) |
|---|
| 468 | ((wxButton*) FindWindow(ID_ROLL)) -> Enable(false); |
|---|
| 469 | #endif |
|---|
| 470 | |
|---|
| 471 | //enable the keep checkboxes |
|---|
| 472 | for (int i=0; i<5; i++) |
|---|
| 473 | ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> Enable(true); |
|---|
| 474 | |
|---|
| 475 | //we rolled the dices so undoing isn't allowed |
|---|
| 476 | (GetMenuBar()->FindItem(ID_UNDO))->Enable(false); |
|---|
| 477 | m_yahtzeebonus = false; //if we scored yahtzee bonus before we don't care anymore. |
|---|
| 478 | |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | void MainFrame::OnUpperButtons (wxCommandEvent& event) |
|---|
| 482 | { |
|---|
| 483 | wxString out; |
|---|
| 484 | int temp; |
|---|
| 485 | if(m_rolls < 3){ |
|---|
| 486 | YahtzeeBonus(); |
|---|
| 487 | temp = dicehash[(event.GetId() - ID_ACES)] * (event.GetId() - ID_ACES + 1); |
|---|
| 488 | |
|---|
| 489 | out.Printf(wxT("%i"),temp); |
|---|
| 490 | ((wxTextCtrl*) FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT))->SetValue(out); |
|---|
| 491 | |
|---|
| 492 | PostScore(event.GetId()); |
|---|
| 493 | } |
|---|
| 494 | else |
|---|
| 495 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | void MainFrame::On3ofakindButton(wxCommandEvent& event) |
|---|
| 499 | { |
|---|
| 500 | if(m_rolls>=3) { |
|---|
| 501 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 502 | return; |
|---|
| 503 | } |
|---|
| 504 | YahtzeeBonus(); |
|---|
| 505 | bool three = false; |
|---|
| 506 | wxString out; |
|---|
| 507 | int temp = 0; |
|---|
| 508 | |
|---|
| 509 | //check for the conditions of scoring |
|---|
| 510 | for (int i=0; i<6; i++) |
|---|
| 511 | if (dicehash[i] >= 3) |
|---|
| 512 | three = true; |
|---|
| 513 | if (three){ |
|---|
| 514 | for(int i = 0; i<5; i++) |
|---|
| 515 | temp += dice[i]+1; |
|---|
| 516 | |
|---|
| 517 | out.Printf(wxT("%i"),temp); |
|---|
| 518 | ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetValue(out); |
|---|
| 519 | } else |
|---|
| 520 | ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetValue(wxT("0")); |
|---|
| 521 | |
|---|
| 522 | PostScore(event.GetId()); |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | void MainFrame::On4ofakindButton(wxCommandEvent& event) |
|---|
| 526 | { |
|---|
| 527 | if(m_rolls>=3) { |
|---|
| 528 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 529 | return; |
|---|
| 530 | } |
|---|
| 531 | YahtzeeBonus(); |
|---|
| 532 | bool four = false; |
|---|
| 533 | wxString out; |
|---|
| 534 | int temp = 0; |
|---|
| 535 | |
|---|
| 536 | //check for the conditions of scoring |
|---|
| 537 | for (int i=0; i<6; i++) |
|---|
| 538 | if (dicehash[i] >= 4) |
|---|
| 539 | four = true; |
|---|
| 540 | if (four){ |
|---|
| 541 | for(int i = 0; i<5; i++) |
|---|
| 542 | temp += dice[i]+1; |
|---|
| 543 | |
|---|
| 544 | out.Printf(wxT("%i"),temp); |
|---|
| 545 | ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetValue(out); |
|---|
| 546 | } else |
|---|
| 547 | ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetValue(wxT("0")); |
|---|
| 548 | |
|---|
| 549 | PostScore(event.GetId()); |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | void MainFrame::OnFullHouseButton(wxCommandEvent& event) |
|---|
| 553 | { |
|---|
| 554 | if(m_rolls>=3) { |
|---|
| 555 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 556 | return; |
|---|
| 557 | } |
|---|
| 558 | YahtzeeBonus(); |
|---|
| 559 | bool two = false; |
|---|
| 560 | bool three = false; |
|---|
| 561 | |
|---|
| 562 | //check for the conditions of scoring |
|---|
| 563 | for (int i=0; i<6; i++) |
|---|
| 564 | if (dicehash[i] == 2) |
|---|
| 565 | two = true; |
|---|
| 566 | for (int i=0; i<6; i++) |
|---|
| 567 | if (dicehash[i] == 3) |
|---|
| 568 | three = true; |
|---|
| 569 | if (two && three) |
|---|
| 570 | ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetValue(wxT("25")); |
|---|
| 571 | else |
|---|
| 572 | ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetValue(wxT("0")); |
|---|
| 573 | |
|---|
| 574 | PostScore(event.GetId()); |
|---|
| 575 | } |
|---|
| 576 | |
|---|
| 577 | void MainFrame::OnSmallSequenceButton(wxCommandEvent& event) |
|---|
| 578 | { |
|---|
| 579 | if(m_rolls>=3) { |
|---|
| 580 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 581 | return; |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | YahtzeeBonus(); |
|---|
| 585 | bool sequence = false; |
|---|
| 586 | //check for the conditions of scoring |
|---|
| 587 | if ( (dicehash[0]>=1 && dicehash[1]>=1 && dicehash[2]>=1 && dicehash[3]>=1) || |
|---|
| 588 | (dicehash[1]>=1 && dicehash[2]>=1 && dicehash[3]>=1 && dicehash[4]>=1) || |
|---|
| 589 | (dicehash[2]>=1 && dicehash[3]>=1 && dicehash[4]>=1 && dicehash[5]>=1)) |
|---|
| 590 | sequence = true; |
|---|
| 591 | if (sequence) |
|---|
| 592 | ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetValue(wxT("30")); |
|---|
| 593 | else |
|---|
| 594 | ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetValue(wxT("0")); |
|---|
| 595 | |
|---|
| 596 | PostScore(event.GetId()); |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | void MainFrame::OnLargeSequenceButton(wxCommandEvent& event) |
|---|
| 600 | { |
|---|
| 601 | if(m_rolls>=3) { |
|---|
| 602 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 603 | return; |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | YahtzeeBonus(); |
|---|
| 607 | bool sequence = false; |
|---|
| 608 | //check for the conditions of scoring |
|---|
| 609 | if ( (dicehash[0]==1 && dicehash[1]==1 && dicehash[2]==1 && dicehash[3]==1 && dicehash[4]==1) || |
|---|
| 610 | (dicehash[1]==1 && dicehash[2]==1 && dicehash[3]==1 && dicehash[4]==1 && dicehash[5]==1)) |
|---|
| 611 | sequence = true; |
|---|
| 612 | if (sequence) |
|---|
| 613 | ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetValue(wxT("40")); |
|---|
| 614 | else |
|---|
| 615 | ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetValue(wxT("0")); |
|---|
| 616 | |
|---|
| 617 | PostScore(event.GetId()); |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | void MainFrame::OnYahtzeeButton(wxCommandEvent& event) |
|---|
| 621 | { |
|---|
| 622 | if(m_rolls>=3) { |
|---|
| 623 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 624 | return; |
|---|
| 625 | } |
|---|
| 626 | //give the score |
|---|
| 627 | if ((dice[0]==dice[1]) && (dice[1]==dice[2]) && (dice[1]==dice[3]) && (dice[1]==dice[4])){ |
|---|
| 628 | ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetValue(wxT("50")); |
|---|
| 629 | m_yahtzee=true; |
|---|
| 630 | } else |
|---|
| 631 | ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetValue(wxT("0")); |
|---|
| 632 | |
|---|
| 633 | PostScore(event.GetId()); |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | void MainFrame::OnChanceButton (wxCommandEvent& event) |
|---|
| 637 | { |
|---|
| 638 | wxString out; |
|---|
| 639 | int temp = 0; |
|---|
| 640 | if(m_rolls < 3){ |
|---|
| 641 | YahtzeeBonus(); |
|---|
| 642 | for(int i = 0; i<5; i++) |
|---|
| 643 | temp += dice[i]+1; |
|---|
| 644 | |
|---|
| 645 | out.Printf(wxT("%i"),temp); |
|---|
| 646 | ((wxTextCtrl*) FindWindow(ID_CHANCETEXT))->SetValue(out); |
|---|
| 647 | |
|---|
| 648 | PostScore(event.GetId()); |
|---|
| 649 | } |
|---|
| 650 | else |
|---|
| 651 | wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("OpenYahtzee"), wxOK | wxICON_INFORMATION, this); |
|---|
| 652 | |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | //******************************************** |
|---|
| 656 | //****** General Functions ****** |
|---|
| 657 | //******************************************** |
|---|
| 658 | |
|---|
| 659 | void MainFrame::ClearDiceHash() |
|---|
| 660 | { |
|---|
| 661 | for (int i=0; i<6; i++) |
|---|
| 662 | dicehash[i] = 0; |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | void MainFrame::ResetRolls() |
|---|
| 666 | { |
|---|
| 667 | m_rollsundo = m_rolls; |
|---|
| 668 | m_rolls = 3; |
|---|
| 669 | ((wxButton*) FindWindow(ID_ROLL)) -> Enable(true); |
|---|
| 670 | for (int i=0; i<5; i++){ |
|---|
| 671 | ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> SetValue(false); |
|---|
| 672 | ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> Enable(false); |
|---|
| 673 | } |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | void MainFrame::YahtzeeBonus() |
|---|
| 677 | { |
|---|
| 678 | long temp; |
|---|
| 679 | wxString tempstr; |
|---|
| 680 | |
|---|
| 681 | //if the player didn't have any yathzees yet he can't have the bonus; |
|---|
| 682 | if (!m_yahtzee) |
|---|
| 683 | return; |
|---|
| 684 | if ((dice[0]==dice[1]) && (dice[1]==dice[2]) && (dice[1]==dice[3]) && (dice[1]==dice[4])) { |
|---|
| 685 | tempstr = ((wxTextCtrl*) FindWindow(ID_YAHTZEEBONUSTEXT)) -> GetValue(); |
|---|
| 686 | tempstr.ToLong(&temp,10); |
|---|
| 687 | temp += 100; |
|---|
| 688 | tempstr.Printf(wxT("%i"),temp); |
|---|
| 689 | ((wxTextCtrl*) FindWindow(ID_YAHTZEEBONUSTEXT)) -> SetValue(tempstr); |
|---|
| 690 | m_yahtzeebonus = true; |
|---|
| 691 | } |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | void MainFrame::EndofGame() |
|---|
| 695 | { |
|---|
| 696 | if(m_numofplaysleft>0) |
|---|
| 697 | return; |
|---|
| 698 | |
|---|
| 699 | wxString tempstr; |
|---|
| 700 | long temp; |
|---|
| 701 | long upperscore = 0; |
|---|
| 702 | long lowerscore = 0; |
|---|
| 703 | |
|---|
| 704 | for (int i = ID_ACESTEXT; i<=ID_SIXESTEXT; i++){ |
|---|
| 705 | tempstr = ((wxTextCtrl*) FindWindow(i)) -> GetValue(); |
|---|
| 706 | tempstr.ToLong(&temp,10); |
|---|
| 707 | upperscore +=temp; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | tempstr.Printf(wxT("%i"),upperscore); |
|---|
| 711 | ((wxTextCtrl*) FindWindow(ID_UPPERSECTIONTOTAL)) -> SetValue(tempstr); |
|---|
| 712 | |
|---|
| 713 | //check for bonus |
|---|
| 714 | if(upperscore>=63) { |
|---|
| 715 | ((wxTextCtrl*) FindWindow(ID_BONUS)) -> SetValue(wxT("35")); |
|---|
| 716 | upperscore +=35; |
|---|
| 717 | } else |
|---|
| 718 | ((wxTextCtrl*) FindWindow(ID_BONUS)) -> SetValue(wxT("0")); |
|---|
| 719 | |
|---|
| 720 | tempstr.Printf(wxT("%i"),upperscore); |
|---|
| 721 | ((wxTextCtrl*) FindWindow(ID_UPPERTOTAL)) -> SetValue(tempstr); |
|---|
| 722 | |
|---|
| 723 | //calculate total on lower section |
|---|
| 724 | for (int i = ID_THREEOFAKINDTEXT; i<=ID_YAHTZEEBONUSTEXT; i++) { |
|---|
| 725 | tempstr = ((wxTextCtrl*) FindWindow(i)) -> GetValue(); |
|---|
| 726 | tempstr.ToLong(&temp,10); |
|---|
| 727 | lowerscore +=temp; |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | tempstr.Printf(wxT("%i"),lowerscore); |
|---|
| 731 | ((wxTextCtrl*) FindWindow(ID_LOWERTOTAL)) -> SetValue(tempstr); |
|---|
| 732 | tempstr.Printf(wxT("%i"),upperscore + lowerscore); |
|---|
| 733 | ((wxTextCtrl*) FindWindow(ID_GRANDTOTAL)) -> SetValue(tempstr); |
|---|
| 734 | |
|---|
| 735 | //disable the roll button; |
|---|
| 736 | ((wxButton*) FindWindow(ID_ROLL)) -> Enable(false); |
|---|
| 737 | |
|---|
| 738 | tempstr.Printf(wxT("Your final score is %i points!"),lowerscore+upperscore); |
|---|
| 739 | wxMessageBox(tempstr, wxT("Game Ended"), wxOK | wxICON_INFORMATION, this); |
|---|
| 740 | |
|---|
| 741 | //submit to high score |
|---|
| 742 | HighScoreHandler(lowerscore+upperscore); |
|---|
| 743 | |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | void MainFrame::HighScoreHandler(int score) |
|---|
| 747 | { |
|---|
| 748 | int place; |
|---|
| 749 | std::string name,date; |
|---|
| 750 | wxCommandEvent newevent; |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | place = m_highscoredb->IsHighScore(score); |
|---|
| 754 | |
|---|
| 755 | if(!place) //if the score didn't make it to the highscore table do nothing |
|---|
| 756 | return; |
|---|
| 757 | HighScoreInfo *infodialog = new HighScoreInfo(this,place); |
|---|
| 758 | infodialog->ShowModal(); |
|---|
| 759 | |
|---|
| 760 | name = infodialog->GetName().mb_str(); |
|---|
| 761 | |
|---|
| 762 | //get the date |
|---|
| 763 | wxDateTime now = wxDateTime::Now(); |
|---|
| 764 | date = now.FormatISOTime().mb_str(); |
|---|
| 765 | date +=" "; |
|---|
| 766 | date += now.FormatDate().mb_str(); |
|---|
| 767 | |
|---|
| 768 | m_highscoredb->SendHighScore(name,date,score); |
|---|
| 769 | |
|---|
| 770 | //now show the high score table |
|---|
| 771 | newevent.SetId(ID_SHOWHIGHSCORE); |
|---|
| 772 | newevent.SetEventType(wxEVT_COMMAND_MENU_SELECTED); |
|---|
| 773 | ProcessEvent(newevent); |
|---|
| 774 | |
|---|
| 775 | } |
|---|
| 776 | |
|---|
| 777 | ///this function handles all the post scoring stuff such as disabling the right button. |
|---|
| 778 | void MainFrame::PostScore(int id) |
|---|
| 779 | { |
|---|
| 780 | //now after the scoring reset the rolls |
|---|
| 781 | ResetRolls(); |
|---|
| 782 | |
|---|
| 783 | //and disable the button |
|---|
| 784 | FindWindow(id)->Enable(false); |
|---|
| 785 | m_numofplaysleft--; |
|---|
| 786 | EnableUndo(id); |
|---|
| 787 | EndofGame(); |
|---|
| 788 | } |
|---|