📄 buraco.cpp
字号:
menuSort->set_sensitive (false); menuSort2->set_sensitive (false); newPile.drag_dest_unset (); if (aDNDHand.size ()) for (unsigned int i (0); i < hands[0].size (); ++i) unregisterHandDND (*hands[0][i]); Check3 (aDNDHand.empty ()); if (aDNDTable.size ()) { for (unsigned int i (0); i < tablePiles[0].size (); ++i) { Check3 (tablePiles[0][i]); for (unsigned int j (0); j < tablePiles[0][i]->size (); ++j) unregisterTableDND (*(*tablePiles[0][i])[j]); } aDNDTable[NULL].disconnect (); aDNDTable.erase (NULL); } Check3 (aDNDTable.empty ()); if (dumpedTop.connected ()) dumpedTop.disconnect (); if (stapleTop.connected ()) stapleTop.disconnect ();}//-----------------------------------------------------------------------------/// Callback after clicking on a card in the hand/// \param iCard: Offset of card in hand//-----------------------------------------------------------------------------void Buraco::cardSelected (unsigned int iCard) { TRACE5 ("Buraco::cardSelected (unsigned int) - Position " << iCard); Check1 (iCard < hands[0].size ()); Check1 (gameStatus () == PLAYING); // Check if all piles are valid if (!humanPilesOK ()) { Gtk::MessageDialog dlg (_("Every pile on the table must have at least 3 cards!"), Gtk::MESSAGE_ERROR); dlg.set_title (_("Invalid move")); dlg.run (); return; } if (getConnectionMgr ().getMode () != YGP::ConnectionMgr::NONE) { // Send played card to all clients (if any) std::ostringstream msg; msg << "Play=" << hands[0][iCard]->id () << ";Target=1"; if (getConnectionMgr ().getMode () == YGP::ConnectionMgr::CLIENT) ignoreNextMsg = true; broadcastMessage (msg.str ()); } unregisterHandDND (*hands[0][iCard]); dumped.append (hands[0].remove (iCard)); menuUndo->set_sensitive (false); // If the player has no more cards left (except of jokers): Give him the // reserve if (containsOnlyJoker (hands[0])) if (!reserve[0].empty ()) addBuraco (0); else if (hands[0].empty ()) { points[0] += 100; endGame (); return; } gStatus.startTurn = 1; gStatus.startGame = 0; setNextPlayer (1); displayTurn (1); makeNextMoves ();}//-----------------------------------------------------------------------------/// Callback after clicking on the staple//-----------------------------------------------------------------------------void Buraco::stapleSelected () { TRACE5 ("Buraco::stapleSelected ()"); Check3 (staple.size ()); Check2 (dumped.size ()); Check3 (stapleTop.connected ()); Check3 (dumpedTop.connected ()); if (getConnectionMgr ().getMode () != YGP::ConnectionMgr::NONE) { // Send played card to all clients (if any) std::ostringstream msg; msg << "Play=" << staple.getTopCard ().id () << ";Target=2"; if (getConnectionMgr ().getMode () == YGP::ConnectionMgr::CLIENT) ignoreNextMsg = true; broadcastMessage (msg.str ()); } dumpedTop.disconnect (); stapleTop.disconnect (); // Move top card to human and enable the cards in his hand, when idle // (means: *after* this signalhandler termintes) Glib::signal_idle ().connect (bind_return (mem_fun (*this, &Buraco::doStapleSelected), false));}//-----------------------------------------------------------------------------/// Delayed callback after clicking on the staple//-----------------------------------------------------------------------------void Buraco::doStapleSelected () { TRACE5 ("Buraco::doStapleSelected ()"); Check2 (staple.size ()); Check2 (dumped.size ()); if (gameStatus () == STOPPED) { dumped.append (staple.removeTopCard ()); enableHuman (); } else { dumped.getTopCard ().show (); unsigned int player (currentPlayer ()); hands[player].append (staple.removeTopCard ()); if (!player) enableHumanHand (); }}//-----------------------------------------------------------------------------/// Callback after clicking on the dumped staple//-----------------------------------------------------------------------------void Buraco::dumpedSelected () { TRACE5 ("Buraco::dumpedSelected ()"); Check3 (dumped.size ()); Check3 (stapleTop.connected ()); Check3 (dumpedTop.connected ()); dumpedTop.disconnect (); stapleTop.disconnect (); if (gameStatus () != STOPPED) { if (!gStatus.startGame) try { CardWidget& card (dumped.getTopCard ()); if (isJoker (card)) throw _("You can't pick up monos!"); if (!pileHasFittingPair (hands[0], dumped.getTopCard ())) throw _("You need a fitting pair to pick up the pile of dumped cards!"); // Don't allow picking up the pile, if that would force the game // to end without having neither buraco nor reserve if (((dumped.size () + hands[0].size ()) < 5) && (points[0] < 200) && reserve[0].empty ()) throw _("Picking up the staple would leave you without cards\n" "and you can't end the game now!"); } catch (Glib::ustring& e) { Gtk::MessageDialog dlg (e, Gtk::MESSAGE_ERROR); dlg.set_title (_("Invalid move")); dlg.run (); enableHuman (); return; } if (getConnectionMgr ().getMode () != YGP::ConnectionMgr::NONE) { // Send played card to all clients (if any) std::ostringstream msg; msg << "Play=" << dumped.getTopCard ().id () << ";Target=3"; if (getConnectionMgr ().getMode () == YGP::ConnectionMgr::CLIENT) ignoreNextMsg = true; broadcastMessage (msg.str ()); } // Special handling of player starting the game and can choose one of the // first two cards CardWidget& card (dumped.removeTopCard ()); card.show (); if (gStatus.startGame) { Check3 (dumped.size () == 0); hands[0].append (card); } else { Check3 (pileHasFittingPair (hands[0], card)); if (getConnectionMgr ().getMode () != YGP::ConnectionMgr::NONE) { // Send played card to all clients (if any) std::ostringstream msg; msg << "Play=" << card.id () << ";Target=" << (tablePiles[0].size () << 16) + 100; if (getConnectionMgr ().getMode () == YGP::ConnectionMgr::CLIENT) ++ignoreNextMsg; broadcastMessage (msg.str ()); } BuracoPile& pile (makeNewPile (0 & 1)); // Create new pile pile.setTopCard (card); // with picked up card acceptCards = hands[0].size ();; if (dumped.size ()) movePile (hands[0], dumped); } // Enable the cards in humans hand, when idle (means: *after* this // signalhandler terminates) Glib::signal_idle ().connect (bind_return (mem_fun (*this, &Buraco::enableHumanHand), false)); } else { staple.append (dumped.removeTopCard ()); enableHuman (); }}//-----------------------------------------------------------------------------/// Action after picking up the card from the dumped staple//-----------------------------------------------------------------------------void Buraco::doDumpedSelected () { TRACE5 ("Buraco::doDumpedSelected () - " << gStatus.startGame); Check3 (dumped.size ()); Check3 (gameStatus () == PLAYING); unsigned int player (currentPlayer ()); dumped.getTopCard ().show (); movePile (hands[player], dumped);}//-----------------------------------------------------------------------------/// Enables a card in the hand of the player//-----------------------------------------------------------------------------void Buraco::enableCard (unsigned int pos) { TRACE9 ("Buraco::enableCard (unsigned int) - Enabling card " << pos); Check1 (pos < hands[0].size ()); activeCards.push_back (hands[0][pos]->signal_clicked ().connect (bind (mem_fun (*this, (&Buraco::cardSelected)), pos)));}//-----------------------------------------------------------------------------/// Prepares the card for drag磏磀rop/// \param iCard: Number of card in hand//-----------------------------------------------------------------------------void Buraco::registerHandDND (unsigned int iCard) { Check1 (iCard < hands[0].size ()); TRACE9 ("Buraco::registerHandDND (unsigned int) - Card: " << iCard << " (" << *hands[0][iCard] << " = " << hands[0][iCard] << ')'); CardWidget& card (*hands[0][iCard]); Check3 (aDNDHand.find (&card) == aDNDHand.end ()); // Card accepts drops from hand and drags from table card.drag_dest_set (dndType, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_MOVE); card.drag_source_set (dndType, Gdk::ModifierType (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK), Gdk::ACTION_MOVE); card.drag_source_set_icon (card.getImage ()); aDNDHand[&card].connReceive = card.signal_drag_data_received ().connect (bind (mem_fun (*this, &Buraco::cardDropped), iCard)); aDNDHand[&card].connGet = card.signal_drag_data_get ().connect (bind (mem_fun (*this, &Buraco::getDropData), iCard));}//-----------------------------------------------------------------------------/// Stops the drag磏磀rop abilities of the passed card/// \param card: Card to unregister of dnd//-----------------------------------------------------------------------------void Buraco::unregisterHandDND (CardWidget& card) { TRACE9 ("Buraco::unregisterHandDND (CardWidget&) - Card: " << card << " -> Address: " << &card); Check1 (aDNDHand.size ()); std::map<CardWidget*, CONNECTIONS>::iterator i (aDNDHand.find (&card)); Check1 (i != aDNDHand.end ()); card.drag_dest_unset (); card.drag_source_unset (); i->second.connReceive.disconnect (); i->second.connGet.disconnect (); aDNDHand.erase (i);}//-----------------------------------------------------------------------------/// Prepares the passed region of cards for drag磏磀rop/// \param pile: Pile whose cards should be registered/// \param start: Number of first card to prepare for DND/// \param end: Number of last card to prepare for DND/// \pre: \c start < \c end; \c end <= Number of cards//-----------------------------------------------------------------------------void Buraco::registerTableDND (unsigned int pile, unsigned int start, unsigned int end) { TRACE9 ("Buraco::registerTableDND (unsigned int, unsigned int, unsigned int)" << " - " << pile << '[' << start << '-' << end << ']'); Check1 (pile < tablePiles[0].size ()); Check1 (start <= end); Check1 (end < tablePiles[0][pile]->size ()); ICardPile& tmp (*tablePiles[0][pile]); pile <<= 8; for (; start <= end; ++start) { CardWidget& card (*tmp[start]); unregisterTableDND (card); registerTableDND (card, pile + start); }}//-----------------------------------------------------------------------------/// Prepares the card for drag磏磀rop/// \param card: Card to register/// \param nr: Number of card in pile//-----------------------------------------------------------------------------void Buraco::registerTableDND (CardWidget& card, unsigned int nr) { TRACE9 ("Buraco::registerTableDND (CardWidget&, unsigned int) - " << card << " = " << std::hex << nr << " - " << &card << std::dec); // Card accepts drops from hand and drags from table card.drag_dest_set (dndType, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_MOVE); aDNDTable[&card] = card.signal_drag_data_received ().connect (bind (mem_fun (*this, &Buraco::cardDroppedOnTable), nr));}//-----------------------------------------------------------------------------/// Stops the drag磏磀rop abilities of the passed card/// \param card: Card to de-register//-----------------------------------------------------------------------------void Buraco::unregisterTableDND (CardWidget& card) { TRACE9 ("Buraco::unregisterTableDND (unsigned int) - Card: " << card << " - " << &card ); Check1 (aDNDTable.size () > 1); std::map<CardWidget*, SigC::Connection>::iterator i (aDNDTable.find (&card)); Check1 (i != aDNDTable.end ()); card.drag_dest_unset (); i->second.disconnect (); aDNDTable.erase (i);}//-----------------------------------------------------------------------------/// Callback after dropping a card (within the hand)/// \param pContext: Context of the drag (contains things like source,/// \param target, action, ...)/// \param data: Describes the thing which was dropped/// \param info: Describes the type of data (should be 0)/// \param time: Timestamp of the drag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -