Exemplo n.º 1
0
bool kpok::loadGame(KConfig* conf)
{
  int numPlayers = DEFAULT_PLAYERS;

  // conf->setGroup("Save");
  numPlayers = conf->readNumEntry("players", -1);

  if (numPlayers > 0) {
    for (int i = 0; i < numPlayers; i++) {
      QString buf = conf->readEntry(QString("Name_%1").arg(i),
				    "Player");
      m_players[i].setName(buf);
      bool human = conf->readBoolEntry(QString("Human_%1").arg(i),
				       false);
      if (human)
	m_players[i].setHuman(); // i == 0
      int cash = conf->readNumEntry(QString("Cash_%1").arg(i),
				    START_MONEY);
      m_players[i].setCash(cash);
      m_game.setDirty();
    }
    initPoker(numPlayers);

    // after initPoker because initPoker does a default initialization
    // of lastHandText
    conf->setGroup("Save");
    lastHandText = conf->readEntry("lastHandText", "");

    return true;
  }

  return false;
}
Exemplo n.º 2
0
void kpok::drawCardsEvent()
{
   int testResult;

   cardW[drawStat]->show();
   cardW[drawStat]->paintCard(cards[drawStat],0,0);

   if (!cardW[drawStat]->queryHeld())
      playSound("cardflip.wav");

   if (drawStat == 4) { /* just did last card */
      drawButton->setEnabled(true);
      drawStat=0;
      if (status == 1) {
         testResult=testHand();
         switch (testResult) {
         case 1 : if (foundCards[0].cardType >= 17) {
               foundCards[0].cardType=0; foundCards[1].cardType=0; displayWin(locale->translate("nothing"),0); break;
            }
            displayWin(locale->translate("One Pair"),5);  break;
         case 2 : displayWin(locale->translate("Two Pairs"), 10); break;
         case 3 : displayWin(locale->translate("3 of a kind"), 15); break;
         case 4 : displayWin(locale->translate("Full House"), 40); break;
         case 6 : displayWin(locale->translate("4 of a kind"), 125); break;
         case 7 : displayWin(locale->translate("Straight"),20); break;
         case 8 : displayWin(locale->translate("Flush"),25); break;
         case 9 : displayWin(locale->translate("Straight Flush"),250); break;
         case 10 : displayWin(locale->translate("Royal Flush"),2000); break;

         default: displayWin(locale->translate("nothing"),0); break;
         }

         startBlinking();
         status = 0;

         if (getCash() < cashPerRound) {
            KMsgBox::message(0,locale->translate("You Lost"), 
                             locale->translate("Oops - you went bankrupt.\n"),
                             KMsgBox::EXCLAMATION,locale->translate("New game"));
            initPoker();
         }

      } else {
         clickToHold->show();
         status =1;
      }

   } else { /* only inc drawStat if not done with displaying */
      drawStat++;
      /* look at next card and if it is held instantly call drawCardEvent again */
      if (cardW[drawStat]->queryHeld())
         drawTimer->start(0,TRUE);
      else
         drawTimer->start(drawDelay,TRUE);
   }
}
Exemplo n.º 3
0
bool kpok::readEntriesAndInitPoker()
{
  NewGameDlg  *newGameDlg = NULL;
  KConfig     *conf       = kapp->config();
  int          numPlayers = DEFAULT_PLAYERS;

  conf->setGroup("NewGameDlg");
  bool showNewGameDlg = conf->readBoolEntry("showNewGameDlgOnStartup", false);
  bool aborted        = false;
  bool oldGame        = false;

  if (showNewGameDlg) {
    newGameDlg = new NewGameDlg(this);
    if (!newGameDlg->exec())
      return false; // exit game
  }

  if (!aborted && (!showNewGameDlg || showNewGameDlg &&
		   newGameDlg->readFromConfigFile())) {
    // Try starting an old game.
    //kdDebug() << "Trying to load old game" << endl;
    oldGame = loadGame();
    if (oldGame)
      return true;
  }

  if (!aborted && showNewGameDlg && !oldGame) {
    // Don't use config file - just take the values from the dialog.
    // (This is also config - the dialog defaults are from config.)
    numPlayers = newGameDlg->getPlayers();
    if (numPlayers <= 0)
      aborted = true;

    for (int i = 0; i < numPlayers; i++) {
      m_players[i].setName(newGameDlg->name(i));
      m_players[i].setCash(newGameDlg->money());
      m_game.setDirty();
    }
  }
  initPoker(numPlayers);

  if (newGameDlg != 0) {
    delete newGameDlg;
  }

  return true;
}
Exemplo n.º 4
0
void kpok::newGame()
{
  NewGameDlg* newGameDlg;

  // Get a "New Game" dialog.
  lastHandText = "";
  newGameDlg = new NewGameDlg(this);
  newGameDlg->hideReadingFromConfig();

  if (newGameDlg->exec()) {
    stopBlinking();
    stopDrawing();
    stopWave();

    // Delete the old values.
    for (unsigned int i = 0; i < m_numPlayers; i++)
      delete playerBox[i];
    delete[] playerBox;// necessary?

    int numPlayers = newGameDlg->getPlayers();

    // Most things will be done in initPoker.
    initPoker(numPlayers);

    // Set/show the name and money of all players.
    for (unsigned int i = 0; i < m_numPlayers; i++) {
      m_players[i].setName(newGameDlg->name(i));
      playerBox[i]->showName();
      m_players[i].setCash((newGameDlg->money() >= m_game.getMinBet())
			   ? newGameDlg->money() : START_MONEY);
      m_game.setDirty();
    }

    // Show the money for all players and the pot.
    paintCash();

    // Activate the Draw button.
    drawButton->setText(i18n("&Deal"));
    drawButton->setEnabled(true);
  }

  delete newGameDlg;
}
Exemplo n.º 5
0
PokerWindow::PokerWindow() :   KTopLevelWidget()
{
        int i;

	locale = kapp->getLocale();
	
	_kpok = new kpok(this,0);
	setView( _kpok, FALSE );
	_kpok->show();
	
	
	menu = new KMenuBar(this, "_mainMenu" );
	menu->show();
	
	
	filePopup = new QPopupMenu(0,"fpopup");
	filePopup->insertItem(locale->translate("&New game"),_kpok,SLOT(initPoker()));
	filePopup->insertSeparator();
	filePopup->insertItem(locale->translate("&Quit"), qApp, SLOT(quit()));

       	optionsPopup = new QPopupMenu(0,"oppup");
	
	soId = optionsPopup->insertItem(locale->translate("&Sound"), this, SLOT(toggleSound()));
	optionsPopup->setCheckable(TRUE);

	QPopupMenu *help = kapp->getHelpMenu(true, QString(i18n("Poker"))
					 + " " + KPOKER_VERSION + " released " + KPOKER_RELEASE_DATE
                                         + i18n("\n\nby Jochen Tuchbreiter")
                                         + " ([email protected])"
					 + i18n("\n\nFor a list of credits see helpfile")
					 + i18n("\nSuggestions, bug reports etc. are welcome")
					     );

	menu->insertItem(locale->translate("&File"), filePopup);
	menu->insertItem(locale->translate("&Options"), optionsPopup);
	
	menu->insertSeparator();
	menu->insertItem(locale->translate("&Help"), help);

	setMenu( menu );

	if (_kpok->initSound() == 1) {
	  optionsPopup->setItemChecked(soId, TRUE);
	}
	else {
	  optionsPopup->setItemEnabled(soId, FALSE);
	}
	conf = kapp->getConfig();

	if (conf !=0) {
	  if ((i = conf->readNumEntry("Sound", -1)) != -1) {
	    if (i==0) {
	      optionsPopup->setItemChecked(soId, FALSE);
	      _kpok->setSound(0);
	    }
	    if (i==1) {
	      optionsPopup->setItemChecked(soId, TRUE);
	      _kpok->setSound(1);
            	    }
	  }
	}
}
Exemplo n.º 6
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();
}