示例#1
0
void kpok::out()
{
  // weWillAdjustLabel->hide();
  emit clearStatusBar();

  m_game.bet(oldBet_raise - findHumanPlayer()->getCurrentBet());
  findHumanPlayer()->changeBet(oldBet_raise 
			       - findHumanPlayer()->getCurrentBet());
  paintCash();

  // Go to next state immediately.  (Previously we told the user to
  // click the action button.)
  drawClick();
  //drawButton->setText(i18n("&End Round"));
}
示例#2
0
void kpok::drawClick()
{
  if (!drawButton->isEnabled())
    return;

  // If this is the start of a new round, then deal new cards.
  if (m_game.getState() == StateStartRound) {
    drawButton->setEnabled(false);
    betBox->setEnabled(false);
    newRound();
  }
  else if (m_game.getState() == StateBet1) { // bet
    emit showClickToHold(false);

    bet();
    if (m_game.getState() == StateExchangeCards) {// should be set in bet()
      drawClick();
    }
  }
  else if (m_game.getState() == StateRaise1) { // continue bet
    bet();
    if (m_game.getState() == StateExchangeCards) {// should be set in bet()
      drawClick();
    }
  }
  else if (m_game.getState() == StateExchangeCards) { // exchange cards
    drawButton->setEnabled(false);
    playerBox[0]->setHeldEnabled(false);
    betBox->setEnabled(false);
    bool skip[PokerHandSize];
    for (int i = 0; i < PokerHandSize; i++)
      skip[i] = false;

    for (int i = 0; i < m_game.getNumActivePlayers(); i++) {
      if (!m_game.getActivePlayer(i)->getHuman())
	m_game.getActivePlayer(i)->exchangeCards(skip);
      else {
	for (int i = 0; i < PokerHandSize; i++) {
	  skip[i] = playerBox[0]->getHeld(i);
	  if (!skip[i])
	    playerBox[0]->paintDeck(i);
	}
      }
      drawCards(m_game.getActivePlayer(i), skip);
    }

    if (playerBox[0]->getHeld(0))
      drawTimer->start(0, TRUE);
    else
      drawTimer->start(drawDelay, TRUE);
  }
  else if (m_game.getState() == StateBet2) { // raise
    setBetButtonEnabled(false);
    bet();

    if (m_game.getState() == StateSee)//should be set in bet()->if no one has raised
      drawClick();
  }
  else if (m_game.getState() == StateRaise2) {
    bet();
    if (m_game.getState() == StateSee)
      drawClick();
  }
  else if (m_game.getState() == StateSee)
    winner();
}
示例#3
0
void kpok::initWindow()
{
  m_blinking    = true;
  m_blinkStat   = 0;
  m_blinkingBox = 0;

  // General font stuff.  Define myFixedFont and wonFont.
  QFont myFixedFont;
  myFixedFont.setPointSize(12);
  QFont wonFont;
  wonFont.setPointSize(14);
  wonFont.setBold(true);

  topLayout = new QVBoxLayout(this, BORDER);
  QVBoxLayout* topInputLayout = new QVBoxLayout;
  topLayout->addLayout(topInputLayout);

  QHBoxLayout* betLayout = new QHBoxLayout;
  inputLayout = new QHBoxLayout;
  inputLayout->addLayout(betLayout);
  topInputLayout->addLayout(inputLayout);

  // The draw button
  drawButton = new QPushButton(this);
  drawButton->setText(i18n("&Deal"));
  connect(drawButton, SIGNAL(clicked()), this, SLOT(drawClick()));
  inputLayout->addWidget(drawButton);
  inputLayout->addStretch(1);

  // The waving text
  QFont  waveFont;
  waveFont.setPointSize(16);
  waveFont.setBold(true);
  QFontMetrics  tmp(waveFont);

  // The widget where the winner is announced.
  mWonWidget = new QWidget(this);
  inputLayout->addWidget(mWonWidget, 2);
  mWonWidget->setMinimumHeight(50); //FIXME hardcoded value for the wave
  mWonWidget->setMinimumWidth(tmp.width(i18n("You won %1").arg(KGlobal::locale()->formatMoney(100))) + 20); // workaround for width problem in wave
  QHBoxLayout* wonLayout = new QHBoxLayout(mWonWidget);
  wonLayout->setAutoAdd(true);

  wonLabel = new QLabel(mWonWidget);
  wonLabel->setFont(wonFont);
  wonLabel->setAlignment(AlignCenter);
  wonLabel->hide();
  inputLayout->addStretch(1);

  // The pot view
  potLabel = new QLabel(this);
  potLabel->setFont(myFixedFont);
  potLabel->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
  inputLayout->addWidget(potLabel, 0, AlignCenter);

  // Label widget in the lower left.
  clickToHold = new QLabel(this);
  clickToHold->hide();

  // Timers
  blinkTimer = new QTimer(this);
  connect( blinkTimer, SIGNAL(timeout()), SLOT(bTimerEvent()) );

  waveTimer = new QTimer(this);
  connect( waveTimer, SIGNAL(timeout()), SLOT(waveTimerEvent()) );

  drawTimer = new QTimer(this);
  connect (drawTimer, SIGNAL(timeout()), SLOT(drawCardsEvent()) );

  // and now the betUp/Down Buttons
  betBox = new BetBox(this, 0);
  betLayout->addWidget(betBox);
  connect(betBox, SIGNAL(betChanged(int)), this, SLOT(betChange(int)));
  connect(betBox, SIGNAL(betAdjusted()),   this, SLOT(adjustBet()));
  connect(betBox, SIGNAL(fold()),          this, SLOT(out()));

  // some tips 
  QToolTip::add(drawButton, i18n("Continue the round"));
  QToolTip::add(potLabel, i18n("The current pot"));

  // Load all cards into pixmaps first -> in the constructor.
  cardImages = new CardImages(this, 0);

  // The configuration
  KConfig* conf = kapp->config();
  conf->setGroup("General");

  // Load the card deck.
  if (conf->readBoolEntry("RandomDeck", true)) {
    cardImages->loadDeck(KCardDialog::getRandomDeck());
  } else {
    cardImages->loadDeck(conf->readPathEntry("DeckPath", KCardDialog::getDefaultDeck()));
  }
  if (conf->readBoolEntry("RandomCardDir", true)) {
    cardImages->loadCards(KCardDialog::getRandomCardDir());
  } else {
    cardImages->loadCards(conf->readPathEntry("CardPath",
				  KCardDialog::getDefaultCardDir()));
  }
}
示例#4
0
kpok::kpok(QWidget *parent, const char *name) 
: QWidget(parent, name)
{
	int w;
	char version[270];
	
       	setFixedSize(420,220);	

        locale = kapp->getLocale();
	
	sprintf(version, "%s %s", kapp->getCaption(), KPOKER_VERSION);
	setCaption( version );
	
	
	QString bitmapdir = kapp->kde_datadir() + QString("/kpoker/pics/");
	
	kacc = new KAccel( this );
	KStdAccel stdacc; // Access to standard accelerators
	/* KKeyCode initialization */
	kacc->insertItem(i18n("Quit"), "Quit", stdacc.quit());
	kacc->insertItem(i18n("New game"), "New", "F2");
	kacc->insertItem(i18n("Help"), "Help", stdacc.help());
	// kacc->insertItem(i18n("Ok dialog"), "ok", "Return"); ??
	// kacc->insertItem(i18n("Cancel dialog"), "dialog", "Escape"); ??
	
	/* connections */
	kacc->connectItem("Quit", qApp, SLOT(quit()));
	kacc->connectItem("New", this, SLOT(initPoker()));
	
	QFont myFixedFont("Helvetica",12);

	drawButton = new QPushButton(this,0);
	
	drawButton->setText(locale->translate("Draw !"));
	drawButton->setGeometry(210-drawButton->sizeHint().width() / 2,CLHDistFromTop,drawButton->sizeHint().width(),drawButton->sizeHint().height());
	connect( drawButton, SIGNAL(clicked()), this, SLOT( drawClick() ) );
	
	for (w=0;w < 5; w++)
	  {
		  CardFrames[w] = new QFrame(this, 0);
		  CardFrames[w]->setGeometry(cardHDist+w*(cardHDist+cardWidth),cardDistFromTop,cardWidth +2,cardHeight +2);
		  CardFrames[w]->setFrameStyle(QFrame::Panel | QFrame::Sunken);
	  }
	
	
	QFont wonFont("Helvetica", 14, QFont::Bold);
	wonLabel = new QLabel(this, 0);
	
	wonLabel->hide();
	wonLabel->setFont(wonFont);
	wonLabel->setAutoResize(true);
	wonLabel->move(this->width() /2  - wonLabel->width() / 2, wonLabelVDist);
	
	
	QFont clickToHoldFont("Helvetica", 11);
	clickToHold = new QLabel(this,0);
	
	clickToHold->hide();
	clickToHold->setFont(clickToHoldFont);
	clickToHold->setAutoResize(true);
	clickToHold->setText(locale->translate("Click a card to hold it"));
	clickToHold->move(this->width() /2  - clickToHold->width() / 2, clickToHoldVDist);
	
	
	/* load all cards into pixmaps */	
	
	cardImage = new CardImages(this,0);
	cardImage->hide();
	cardImage->loadCards(bitmapdir);
	
	for (w=0;w<5;w++) {
		cardW[w] = new CardWidget(CardFrames[w], 0);
		connect( cardW[w], SIGNAL(clicked()), cardW[w], SLOT( ownClick() ) );
		connect( cardW[w], SIGNAL(pClicked(CardWidget *)), this, SLOT(frameClick(CardWidget *)));
	}
	
	for (w=0; w<5;w++) {
		heldLabels[w] = new QLabel(this, 0);
		heldLabels[w]->hide();
		heldLabels[w]->setFont(myFixedFont);	       
		heldLabels[w]->setAutoResize(true);
		heldLabels[w]->setText(locale->translate("Held"));
		heldLabels[w]->move(
				    ((cardWidth+2) /2 - heldLabels[w]->width() /2) +
				    cardHDist+w*(cardHDist + cardWidth), cardDistFromTop -15
				    );
		cardW[w]->heldLabel = heldLabels[w];
	}
	cashFrame = new QFrame(this,0);
	cashFrame->setGeometry(CLHBorderDistance, CLHDistFromTop, CLHWidth, 30);
	cashFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
	cashLabel= new QLabel(cashFrame,0);
	cashLabel->setAutoResize(true);
        cashLabel->setFont(myFixedFont);
	
	LHFrame = new QFrame(this,0);
	LHFrame->setGeometry(this->width() - CLHBorderDistance - CLHWidth, CLHDistFromTop, CLHWidth, 30);
	LHFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
	
	LHLabel= new QLabel(LHFrame,0);
	LHLabel->setAutoResize(true);
        LHLabel->setFont(myFixedFont);
	
	for (w=0; w<= highestCard / 4; w++)
	    cardHelp[w*4+1]=cardHelp[w*4+2]=cardHelp[w*4+3]=cardHelp[w*4+4]=w;
	
	blinkTimer = new QTimer(this);
	connect( blinkTimer, SIGNAL(timeout()), SLOT(bTimerEvent()) );
	blinkStat=0;

	waveTimer = new QTimer(this);
	connect( waveTimer, SIGNAL(timeout()), SLOT(waveTimerEvent()) );
	
	drawTimer = new QTimer(this);
	connect (drawTimer, SIGNAL(timeout()), SLOT(drawCardsEvent()) );
	
	

	srandom(time(NULL));
	
	QToolTip::add( drawButton,locale->translate("draw new cards"));
	QToolTip::add( LHLabel,locale->translate("your last hand"));
        QToolTip::add( LHFrame,locale->translate("your last hand"));
	QToolTip::add( cashLabel,locale->translate("money left"));
	QToolTip::add( cashFrame,locale->translate("money left"));
	
	initPoker();
	initSound();
}