⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardcol.cpp

📁 一个扑克牌游戏集合的源码,包含了很多基本c-c++语言应用
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   grpAction->add (Gtk::Action::create ("Options", _("_Options")));   grpAction->add (Gtk::Action::create ("ChgGame", _("_Change game")));   Gtk::RadioButtonGroup grpGames;#ifdef WITH_BURACO   grpAction->add (apMenus[BURACO] = Gtk::RadioAction::create (grpGames, "Buraco", _("_Buraco")),		   Gtk::AccelKey (_("<ctl>B")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::BURACO));#endif#ifdef WITH_HEARTS   grpAction->add (apMenus[HEARTS] = Gtk::RadioAction::create (grpGames, "Hearts", _("_Hearts")),		   Gtk::AccelKey (_("<ctl>H")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::HEARTS));#endif#ifdef WITH_MACHIAVELLI   grpAction->add (apMenus[MACHIAVELLI] = Gtk::RadioAction::create (grpGames, "Machiavelli", _("_Machiavelli")),		   Gtk::AccelKey (_("<ctl>M")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::MACHIAVELLI));#endif#ifdef WITH_ROVHULT   // xgettext: For translations: Write the Rovhult as o-slash   grpAction->add (apMenus[ROVHULT] = Gtk::RadioAction::create (grpGames, "Rovhult", _("_Rovhult")),		   Gtk::AccelKey (_("<ctl>R")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::ROVHULT));#endif#ifdef WITH_SGTMAYOR   grpAction->add (apMenus[SGTMAYOR] = Gtk::RadioAction::create (grpGames, "SgtMayor", _("_Sgt. Mayor")),		   Gtk::AccelKey (_("<ctl>Y")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::SGTMAYOR));#endif#ifdef WITH_TWOPART   grpAction->add (apMenus[TWOPART] = Gtk::RadioAction::create (grpGames, "Twopart", _("_Twopart")),		   Gtk::AccelKey (_("<ctl>T")),		   bind (mem_fun (*this, &CardgameCollection::changeGame), (int)GameTypes::TWOPART));#endif   grpAction->add (Gtk::Action::create ("ChgDecks", _("Change _decks ...")),		   Gtk::AccelKey (_("<ctl>D")),		   mem_fun (*this, &CardgameCollection::showChangeDeckDlg));   grpAction->add (Gtk::Action::create ("ChgNames", _("Change _names ...")),		   Gtk::AccelKey (_("<ctl>C")),		   mem_fun (*this, &CardgameCollection::changeNames));   grpAction->add (Gtk::Action::create ("Prefs", Gtk::Stock::PREFERENCES),		   Gtk::AccelKey (_("F9")),		   mem_fun (*this, &CardgameCollection::editPreferences));   grpAction->add (Gtk::Action::create ("SavePrefs", Gtk::Stock::SAVE,					_("_Save preferences")),		   mem_fun (*this, &CardgameCollection::savePreferences));#if TRACELEVEL >= 1   grpAction->add (Gtk::Action::create ("Debug", "_Debug"),		   Gtk::AccelKey ("<ctl>G"),		   mem_fun (*this, &CardgameCollection::toggleDebug));#endif   addHelpMenu (ui);   ui += "</menubar></ui>";   mgrUI->insert_action_group (grpAction);   add_accel_group (mgrUI->get_accel_group ());   mgrUI->add_ui_from_string (ui);   getClient ().pack_start (*mgrUI->get_widget("/Menu"), Gtk::PACK_SHRINK);   ((Gtk::MenuItem*)(mgrUI->get_widget("/Menu/Help")))->set_right_justified ();   Check3 (apMenus[NEW]); Check3 (apMenus[END]);   apMenus[NEW]->set_sensitive (false);   apMenus[END]->set_sensitive (false);   status.show ();   getClient ().pack_end (status, Gtk::PACK_SHRINK);   show ();#ifdef HAVE_LIBPTHREAD   mxGuiCmd.lock ();#endif   Glib::signal_idle ().connect       (bind_return (mem_fun (*this, &CardgameCollection::loadCards), false));   makePlayer ();#ifdef HAVE_LIBPTHREAD   autoConnect (options);#endif}//----------------------------------------------------------------------------/// Creates the default player in the game; basing on the names read from the/// INI file//----------------------------------------------------------------------------void CardgameCollection::makePlayer () {   Check3 (options.names.size ());   std::vector<Glib::ustring>::iterator i (options.names.begin ());   aPlayer.push_back (new Human (*i));   while (++i != options.names.end ())       aPlayer.push_back (new ComputerPlayer (*i));}//-----------------------------------------------------------------------------/// Destructor//-----------------------------------------------------------------------------CardgameCollection::~CardgameCollection () {   TRACE9 ("CardgameCollection::~CardgameCollection ()");   if (game) {      game->clean ();      delete game;   }   for (std::vector<Player*>::iterator i (aPlayer.begin ());        i != aPlayer.end (); ++i)      delete *i;#ifdef HAVE_LIBPTHREAD   removeCommThreads ();#endif}//-----------------------------------------------------------------------------/// Starts a game; if the type has changed also deleting the old one//-----------------------------------------------------------------------------void CardgameCollection::startGame () {   TRACE6 ("CardgameCollection::startGame () - Old game type " << oldGame           << " -> New: " << actGame);   // Check if the game has been changed; if so destroy the old one   unsigned int oldDecks (0), oldJoker (0);   if (game) {      oldDecks = game->numberOfDecks ();      oldJoker = game->numberOfJokers ();      if (oldGame != actGame) {	 // Remove menubar and update GUI to not interfere with new game	 game->removeMenus (mgrUI);	 Glib::RefPtr<Glib::MainContext> ctx (Glib::MainContext::get_default ());	 while (ctx->iteration (false)) ;         getClient ().remove (*game);         delete game;      }   }   if (oldGame != actGame) {      oldGame = actGame;      switch (oldGame) {#ifdef WITH_ROVHULT      case GameTypes::ROVHULT:         game = new TGame<Rovhult, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif#ifdef WITH_TWOPART      case GameTypes::TWOPART:         game = new TGame<Twopart, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif#ifdef WITH_HEARTS      case GameTypes::HEARTS:         game = new TGame<Hearts, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif#ifdef WITH_BURACO      case GameTypes::BURACO:         game = new TGame<Buraco, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif#ifdef WITH_MACHIAVELLI      case GameTypes::MACHIAVELLI:         game = new TGame<Machiavelli, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif#ifdef WITH_SGTMAYOR      case GameTypes::SGTMAYOR:         game = new TGame<SgtMayor, CardgameCollection>            (*this, &CardgameCollection::gameEvents);         break;#endif      default:         Check (0);      }      game->addMenus (mgrUI);   }   // Change number of jokers if necessary   if (oldJoker != game->numberOfJokers ()) {      TRACE5 ("CardgameCollection::startGame () - Re-adding jokers "              << oldJoker << "->" << game->numberOfJokers ());      for (unsigned int i (0); i < oldJoker; ++i)         cardFaces.delImage (cardFaces.size () - 1);      for (unsigned int i (0); i < game->numberOfJokers (); ++i)         cardFaces.addImage (xpmJoker);   }   // Change number of decks if necessary   if ((oldDecks != game->numberOfDecks ())       || (oldJoker != game->numberOfJokers ())) {      TRACE5 ("CardgameCollection::startGame () - Changing carddecks "              << oldDecks << "->" << game->numberOfDecks ());      cards.clear ();      for (unsigned int i (0); i < game->numberOfDecks (); ++i)         cards.addPacket (cardFaces);   }   Check3 (game);   Glib::ustring name (GameTypes::get ()[actGame]);   name += " - " PACKAGE " V" PRG_RELEASE;   set_title (name);#ifdef SAVE_GAME   if (options.gameFile.size () && options.load) {      std::ifstream input (options.gameFile.c_str ());      char buffer[1024];      input.getline (buffer, sizeof (buffer));      game->setCardOrder (buffer);   }#endif   if (cmgr.getMode () != YGP::ConnectionMgr::CLIENT) {      game->start ();#ifdef SAVE_GAME      if (options.gameFile.size () && !options.load) {         std::ofstream output (options.gameFile.c_str ());         output << game->getCardOrder ();      }#endif      game->clearCardOrder ();   }   else      game->setGameStatus (Game::NONE);}//-----------------------------------------------------------------------------/// Starts a new game; running games are ended//-----------------------------------------------------------------------------void CardgameCollection::newGame () {   TRACE7 ("CardgameCollection::newGame () - New; Game running: "	   << (game && game->isRunning () ? "Yes" : "No"));   if (game && game->isRunning ()) {      Gtk::MessageDialog dlg (_("A game is already running. Do you really"				" want to end it and start another?"), false,			      Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);      dlg.set_title (PACKAGE);      if (dlg.run () == Gtk::RESPONSE_YES) {	 restart = true;	 Glib::signal_idle ().connect	    (bind_return (mem_fun (*this, &CardgameCollection::restartGame), false));      }   }   else {#ifdef HAVE_LIBPTHREAD      if (stopClientWaiting ())#endif	 startGame ();   }}//-----------------------------------------------------------------------------/// Ends a running game//-----------------------------------------------------------------------------void CardgameCollection::endGame () {   Check3 (game && game->isRunning ());   Gtk::MessageDialog dlg (_("Do you really want to end the game?"),			   false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);   dlg.set_title (PACKAGE);   if (dlg.run () == Gtk::RESPONSE_YES) {      restart = false;      restartGame ();   }}//-----------------------------------------------------------------------------/// Changes the type of the next game/// \param game: Type of the next game//-----------------------------------------------------------------------------void CardgameCollection::changeGame (int game) {   TRACE9 ("CardgameCollection::changeGame (games) - " << game);   Check3 ((unsigned int)game < GameTypes::LAST);   actGame = game;}//-----------------------------------------------------------------------------/// Opens a dialog allowing to change the card decks//-----------------------------------------------------------------------------void CardgameCollection::showChangeDeckDlg () {   DeckSelectDlg& dlg (*DeckSelectDlg::create (options.decks, options.back));   dlg.get_window ()->set_transient_for (get_window ());   dlg.setDecks.connect (mem_fun (this, &CardgameCollection::changeDecks));}//-----------------------------------------------------------------------------/// Opens a dialog allowing to change the names of the players//-----------------------------------------------------------------------------void CardgameCollection::changeNames () {   PlayerDlg* dlg (PlayerDlg::create (aPlayer));   dlg->sigCommit.connect (mem_fun (*this, &CardgameCollection::changePlayernames));   dlg->get_window ()->set_transient_for (get_window ());}//-----------------------------------------------------------------------------/// Edits the preferences//-----------------------------------------------------------------------------void CardgameCollection::editPreferences () {   Settings::create (get_window (), options)#ifdef HAVE_LIBPTHREAD      ->sigCommit.connect (mem_fun (*this, &CardgameCollection::sendSettings))#endif      ;}//-----------------------------------------------------------------------------/// Saves the settings//-----------------------------------------------------------------------------void CardgameCollection::savePreferences () {   TRACE2 ("CardgameCollection::savePreferences () - Save file " << options.pNameINIFile);   std::ofstream inifile (options.pNameINIFile);   if (inifile) {      options.strType = GameTypes::get ()[options.type];      YGP::INIFile::write (inifile, "Game", options);      for (unsigned int i (0); i < aPlayer.size (); ++i)	 options.names[i] = aPlayer[i]->getName ();      YGP::INIList<Glib::ustring>::write (inifile, "Player", options.names);#ifdef WITH_BURACO      YGP::INIFile::writeSectionHeader (inifile, "Buraco");      inifile << "Cards=" << BuracoCards::get ()[Buraco::CARDS2DEAL]	      << "\nEndPoints=" << Buraco::ENDPOINTS << '\n';#endif#ifdef WITH_HEARTS      inifile << '\n';      YGP::INIFile::writeSectionHeader (inifile, "Hearts");      inifile << "EndPoints=" << Hearts::ENDPOINTS << '\n';#endif#ifdef WITH_ROVHULT      inifile << '\n';      YGP::INIFile::writeSectionHeader (inifile, "Rovhult");      inifile << "CardNuke=" << CardValue::get ()[Rovhult::cardNuke]	      << "\nCardReverse=" << CardValue::get ()[Rovhult::cardReverse]	      << "\nCardSkip=" << CardValue::get ()[Rovhult::cardSkip] << '\n';#endif#ifdef WITH_SGTMAYOR      inifile << '\n';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -