Beispiel #1
0
void ChipsAnimate::startAnimate(int from, int to,
                                const CChips& chips,
                                int sound)
{
    stopAnimate();

    sound_ = sound;

    CTableView* pV = CTableView::Instance();
    pView_ = pV;
    ASSERT(pView_);

    chips_ = chips;
    Player* pFrom = pV->getPlayer(from);
    Player* pTo = pV->getPlayer(to);
    if (pFrom && pTo)
    {
        player_ = from;
        msecs_ = Global::GetAnimationTime() / 2;
        ticks_ = 0;
        // Animation does not go to the pot right away,
        // chips move to the pot only after betting round
        // ends.
        start_ = pFrom->getChipStartPos();
        end_ = pFrom->getChipBetPos();
        //end_ = pTo->getChipPos();
        pos_ = start_;

        CDC* pDC = pView_->GetDC();
        if (pDC)
        {
            Chips::Instance().startAnimate(pDC, chips_, start_);
            pView_->ReleaseDC(pDC);
        }

        // Fix up the 'end' position so the bottom left corner
        // of the rectangle will hit there
        CSize s = Chips::Instance().getAnimationBufferSize();
        end_.y -= (s.cy - Chips::Height_);
    }
}
Beispiel #2
0
void PDUShowdown::execute(Base::GameState*)
{
  CTableView* pView = CTableView::Instance();

  if (pView)
  {
    Player* pPlayer = pView->getPlayer(player_);
    if (pPlayer)
    {
      if (num_cards_ == 0)
      { //
        // Player mucks hand - do muck hand animation
        // unless its the local player
        //
        if (!pView->isLocalPlayer(player_))
        {
          pView->InvalidateRect(pPlayer->getCardPaintArea(Player::AllCards));
          pPlayer->empty();
          GameLogic::Instance().setNextState(
              new StateShowdown(player_, pPlayer->numCards()));
        }
      }
      else
      { //
        // Show player's cards
        //
        pView->InvalidateRect(pPlayer->getCardPaintArea(Player::AllCards));
        CardEntry* pC = pCards_;
        for (int i = 0; i < num_cards_; i++, pC++)
          pPlayer->setCard(i, Card((Base::Suit)pC->suit_, pC->value_));
        pPlayer->setShowAll(TRUE);
      }

      pView->InvalidateRect(
        pPlayer->getCardPaintArea(Player::AllCards));

      if (message_)
        pPlayer->setActionText(message_);
      else
        pPlayer->setActionText("");
    }
  }
}
Beispiel #3
0
//
// This PDU is always sent at the start of hand.
//
// The dealer is set twice to make sure the old
// blind positions are erased and new positions
// painted correctly.
//
// The player states are reset to sit-in.
//
void PDUButton::execute(Base::GameState* pState)
{
  CTableView* pView = CTableView::Instance();
  if (pView)
  { 
    pView->resetCards(true);
    pView->setDealer(dealerslot_, true);

    static bool is_first_button = true;
    if (!is_first_button)
    {
      for (int i = 0; i < 10; i++)
      {
        Player* pP = pView->getPlayer(i);
        if (pP)
        {
          if (pP->getChips() > 0 &&
              pP->getState() != Base::AllIn)
          {
            pP->setState(Base::SitIn);
            pP->setActionText("", true);
          }
          else
          {
            pP->setState(Base::SitOut);
          }
        }
      }
    }
    else
      is_first_button = true;

    pView->setDealer(dealerslot_, true);
    pView->Invalidate();
  }

  if (GameLogic::Instance().currentState() == NULL)
  { // Set the next state already!
    GameLogic::Instance().setNextState(new StatePromptPostBlind(10, 0, 0));
  }
}
Beispiel #4
0
void PDUPlayerInfo::execute(GameState*)
{
  CString msg;
  CTableView* pTable = CTableView::Instance();
  ASSERT(pTable);
  CChatView* pChat = CChatView::Instance();
  int num_players_b4_pdu = pTable->numPlayers();

  if (pTable)
  {
    int num_players = num_players_b4_pdu;

    PlayerInfo* pP = pPlayers_;
    if (pP != NULL)
    {
      for (int i = 0; i < num_players_; i++)
      {
        CString namesz = MakeString(pP->username_);
        Player* p = pTable->getPlayer(pP->slot_);
        bool wasThere = false;
        if (p && p->getName() == namesz)
          wasThere = true;

        pTable->addPlayer(namesz, CChips_n(pP->chips_).ntohl(), pP->slot_);

        // Set initial player state
        if (pP->state_ & PLAYER_STATE_ACTIVE)
          pTable->setState(pP->slot_, Base::SitIn);
        else
          pTable->setState(pP->slot_, Base::SitOut);

        Player* pPlayer = pTable->getPlayer(pP->slot_);

        ASSERT(pPlayer);
        if (pPlayer)
        {
          if (pP->state_ & PLAYER_STATE_ZOMBIE)
            pPlayer->setState(Base::Zombie);

          CString citysz = MakeString(pP->city_);
          pPlayer->setHomeCity(citysz);
          pTable->InvalidateRect(&pPlayer->getArea());  
        }

        if (pChat && !wasThere)
        {
          CString msg;
          msg.Format(g_szPlayerJoined, (LPCSTR)namesz, pP->slot_ + 1);
          pChat->addDealerMessage(msg, CChatView::CF_GameNormal);
        }
        
        pP++;
      }
    }

    // make a full redraw if original player
    // count was 0
    if (num_players == 0)
      pTable->Invalidate();
  }

  if (num_players_b4_pdu == 0)
  {
    // Send initial sit in status
    BOOL b = GameLogic::SitOut();
    if (Global::TableServer())
    {
      if (b)
        Global::TableServer()->sendPlaySitOutPDU();
      else
        Global::TableServer()->sendPlaySitInPDU();
    }

    // Send initial muck hand status
    b = GameLogic::HideHand();
    if (Global::TableServer())
    {
      if (b)
        Global::TableServer()->sendPlayHideCardsPDU();
      else
        Global::TableServer()->sendPlayShowCardsPDU();
    }

    // Done, start waiting for new hand to start
    GameLogic::Instance().setNextState(new StateWait());
  }
}
Beispiel #5
0
void PDUActionEcho::execute(GameState* pS)
{
  // Call the corresponding routine to
  // visualize the action.

  CTableView* pView = CTableView::Instance();
  if (!pView) return;
  Player* pPlayer = pView->getPlayer(slot_);
  if (!pPlayer) return;

  if (pS)
  { // Let the current state know of the action
    pS->onCommand(MAKEWPARAM(ID_PDU_ACTIONECHO, 0),
                  reinterpret_cast<LPARAM>(this));
  }

  // Get the state anew because actionecho handling might
  // have destroyed it
  pS = GameLogic::Instance().currentState();

  if (action_ == PDUAction::Call)
  { 
    Base::ImplementCall(pPlayer, slot_, amount_);
  }
  else if (action_ == PDUAction::Raise)
  {     
    CChips bet;
    if (pS)
    { // Ask state the current bet
      pS->onCommand(MAKEWPARAM(ID_PDU_GETBET, 0),
                    reinterpret_cast<LPARAM>(&bet));
    }

    Base::ImplementRaise(pPlayer, slot_, bet, amount_);
  }
  else if (action_ == PDUAction::Fold)
  {
    Base::ImplementFold(pPlayer, slot_);

    if (pView->isLocalPlayer(slot_) && Base::GameLogic::LeaveTable())
    { // User has clicked the Leave Table button
      // - send logout now
      Base::SetStatusText(pView, _T("Leaving table..."));
      if (Global::TableServer()) 
        Global::TableServer()->sendSetupTableLogout();
    }
  }
  else if (action_ == PDUAction::Ante)
  {
    Base::ImplementAnte(pPlayer, slot_, amount_);
  }
  else if (action_ == PDUAction::SitOut)
  {
    Base::ImplementSitOut(slot_, pPlayer);

    if (pView->isLocalPlayer(slot_) && Base::GameLogic::LeaveTable())
    { // User has clicked the Leave Table button
      // - send logout now
      Base::SetStatusText(pView, _T("Leaving table..."));
      if (Global::TableServer()) 
        Global::TableServer()->sendSetupTableLogout();
    }
  }
  else
  {
    CString s;
    s.Format("*** Action Echo PDU: unrecognized action: %d", action_);
    PDU_DEBUG(s);
  }
}
Beispiel #6
0
void PDUAnnounce::execute(GameState*)
{
  CTableView* pTable = CTableView::Instance();

  bool msgOnly = (winner_ == ANNOUNCE_FLAG_MSG);

  if (!msgOnly && pTable)
  {
    // Tell the current state to quit animations if any
    GameState* state = GameLogic::Instance().currentState();
    if (state)
      state->onCommand(MAKEWPARAM(ID_STOPANIMATION, 0), 0);
    pTable->endBettingRound(true);
  }

  CChatView* pChat = CChatView::Instance();
  if (pChat && pTable)
  {
    CString name("unknown");
    Base::Player* p = pTable->getPlayer(winner_);
    if (p)
    {
      name = p->getName();
      pTable->showWinner(winner_, 3000); // animate 3 secs
    }

    // Replace newlines with spaces
    CString s(message_);    
    for (int i = 0; i < s.GetLength(); i++)
    {
      if (s[i] == '\n' || s[i] == '\r')
        s.SetAt(i, ' ');
    }

    if (msgOnly)
      pChat->addDealerMessage(s, CChatView::CF_GameNormal);
    else
      pChat->addDealerMessage(s, CChatView::CF_Fatal);

    if (!msgOnly)
    {
      CChips chipsInPot = pTable->resetPot();

      if (pTable->isLocalPlayer(winner_))
      {
        if (chipsInPot > 100)
          SndMan::Instance()->playSound(SndMan::SM_RakeInLarge);
        else
          SndMan::Instance()->playSound(SndMan::SM_RakeInSmall);
      }
      else
      {
        SndMan::Instance()->playSound(SndMan::SM_Show);
      }
    }

#ifdef SHOW_ANNOUNCEMENT_RECT_
    // The announcement rectangle is not currently used.
    pTable->announce(message_);
#endif
  }  

  if (!msgOnly && GameLogic::LeaveTable())
  { // User has clicked the Leave Table button
    // - send logout now
    if (pTable)
      Base::SetStatusText(pTable, _T("Leaving table..."));
    if (Global::TableServer()) 
      Global::TableServer()->sendSetupTableLogout();
  }
}