void kpok::updateLHLabel() { if (!lastHandText.isEmpty()) setHand(lastHandText); else if (m_game.getNumActivePlayers() > 1) setHand(i18n("Nobody"), false); else setHand(i18n("Nothing")); }
void kpok::displayWin(const QString& hand, int cashWon) { QString buf; setHand(hand); m_game.getActivePlayer(0)->setCash(m_game.getActivePlayer(0)->getCash() + cashWon); m_game.setDirty(); paintCash(); if (cashWon) { playSound("win.wav"); buf = i18n("You won %1!").arg(KGlobal::locale()->formatMoney(cashWon)); } else { playSound("lose.wav"); buf = i18n("Game Over"); // locale } wonLabel->setText(buf); if (!cashWon) wonLabel->show(); else { wonLabel->hide(); startWave(); } drawButton->setText(i18n("&Deal New Round")); }
void kpok::displayWin(const char *hand, int cashWon) { char buf[200]; setHand(hand); setCash(getCash() + cashWon); if (cashWon) { playSound("win.wav"); sprintf(buf,"%s %d !",locale->translate("You won $"), cashWon); // locale } else { playSound("lose.wav"); sprintf(buf,locale->translate("Game Over")); // locale } wonLabel->setText(buf); wonLabel->move(this->width() / 2 - wonLabel->width() / 2, wonLabelVDist); if (!cashWon) { wonLabel->show(); } else { wonLabel->hide(); startWave(); } }
void kpok::displayWinner_Computer(PokerPlayer* winner, bool othersPassed) { // Determine the box that contains the winner. for (unsigned int i = 0; i < m_numPlayers; i++) { if (&m_players[i] == winner) m_blinkingBox = i; } // Give the pot to the winner. winner->setCash(winner->getCash() + m_game.getPot()); m_game.setDirty(); // Generate a string with winner info and show it. QString label; if (winner->getHuman()) label = i18n("You won %1").arg(KGlobal::locale()->formatMoney(m_game.getPot())); else label = i18n("%1 won %2").arg(winner->getName()).arg(KGlobal::locale()->formatMoney(m_game.getPot())); wonLabel->setText(label); // Start the waving motion of the text. QFont waveFont; waveFont.setBold(true); waveFont.setPointSize(16); QFontMetrics tmp(waveFont); mWonWidget->setMinimumWidth(tmp.width(label) + 20); // Play a suitable sound. if (winner->getHuman()) { playSound("win.wav"); wonLabel->hide(); startWave(); } else { playSound("lose.wav"); wonLabel->show(); } m_game.clearPot(); m_game.setState(StateStartRound); drawButton->setEnabled(true); setHand(winner->getName(), false); paintCash(); // Only start blinking if player 1 is still in. if (m_game.isActivePlayer(&m_players[0]) && !othersPassed) startBlinking(); drawButton->setText(i18n("&Deal New Round")); }
void kpok::switchToOnePlayerRules() { KMessageBox::information(0, i18n("You are the only player with money!\n" "Switching to one player rules..."), i18n("You Won")); // Hide all computer players. for (unsigned int i = 1; i < m_numPlayers; i++) { playerBox[i]->hide(); } m_game.setType(SinglePlayer); betBox->hide(); potLabel->hide(); playerBox[0]->singlePlayerGame(cashPerRound); setHand(i18n("Nothing")); }
void QwtAnalogClock::initClock() { setWrapping( true ); setReadOnly( true ); setOrigin( 270.0 ); setRange( 0.0, 60.0 * 60.0 * 12.0 ); // seconds setScale( -1, 5, 60.0 * 60.0 ); setScaleComponents( QwtAbstractScaleDraw::Ticks | QwtAbstractScaleDraw::Labels ); setScaleTicks( 1, 0, 8 ); scaleDraw()->setSpacing( 8 ); QColor knobColor = palette().color( QPalette::Active, QPalette::Text ); knobColor = knobColor.dark( 120 ); QColor handColor; int width; for ( int i = 0; i < NHands; i++ ) { if ( i == SecondHand ) { width = 2; handColor = knobColor.dark( 120 ); } else { width = 8; handColor = knobColor; } QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle( QwtDialSimpleNeedle::Arrow, true, handColor, knobColor ); hand->setWidth( width ); d_hand[i] = NULL; setHand( ( Hand )i, hand ); } }
void kpok::initPoker() { status=0; int w; for (w=0;w<5;w++) { cards[w]=0; cardW[w]->heldLabel->hide(); cardW[w]->show(); cardW[w]->paintCard(cards[w],0,0); } wonLabel->hide(); clickToHold->hide(); drawStat=0; cleanFoundCard(); setCash(100); setHand(locale->translate("nothing")); waveActive = 0; fCount =0; }
int main (){ int seed = 1000; int r,i; int result = 0; bool pass = true; int p=0; int handPos; int k[10] = { adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall }; struct gameState G; printf("TESTING VILLAGE CARD\n"); for(p=0; p<MAX_PLAYERS; p++){ switch(p){ case 0: printf("Testing for village card at index 0 of hand\n"); break; case 1: printf("Testing for village card at last index of hand\n"); break; case 2: printf("Normal testing mode\n"); break; case 3: printf("Normal testing mode\n"); break; } memset(&G, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(MAX_PLAYERS, k, seed, &G); // initialize a new game //set deck for each player setDeck(&G); //change each player's hand, with at least 1 village card setHand(&G); //set handpos of village card for(i=0; i< G.handCount[p]; i++){ if(G.hand[p][i] == village){ handPos = i; } } result = checkVillage(p, &G, handPos); if (result == -1){ pass = false; } if (pass == true){ printf("ALL TESTS PASSED!\n"); }else{ printf("FAILURES\n"); } } return 0; }
//Actual test void test(){ struct gameState g; struct gameState *game = &g; int player = 1; int counter = 1; int treasureCounter, i; int tempHand[MAX_HAND]; srand(time(NULL)); int r = rand(); //Initial check if(setHand(game, copper, r, 1)){ printf("%d: Error setting DECK.\n", counter); } if(setHand(game, estate, r, 0)){ printf("%d: Error setting HAND.\n", counter); } if(adventurerMethod(game, tempHand, player) != 0){ printf("%d: Error unknown.\n", counter); counter++; } else{ treasureCounter = 0; for(i=0;i<game->handCount[player];i++){ if(game->hand[player][i] == copper){ treasureCounter++; } } if(treasureCounter != 2){ printf("%d: adventureMethod(): FAIL, error initial, tcount - %d.\n", counter, treasureCounter); } else{ printf("%d: adventurerMethod(): PASSED initial.\n", counter); } counter++; } //Second check, large deck, only last cards are copper if(setHand(game, copper, r, 2)){ printf("%d: Error setting DECK.\n", counter); } if(setHand(game, estate, r, 0)){ printf("%d: Error setting HAND.\n", counter); } if(adventurerMethod(game, tempHand, player) != 0){ printf("%d: Error unknown.\n", counter); counter++; } else{ treasureCounter = 0; for(i=0;i<game->handCount[player];i++){ if(game->hand[player][i] == copper){ treasureCounter++; } } if(treasureCounter != 2){ printf("%d: adventureMethod(): FAIL, large deck, last are copper, tcount - %d.\n", counter, treasureCounter); } else{ printf("%d: adventurerMethod(): PASSED large deck.\n", counter); } counter++; } //Third check, random deck, only last cards are copper if(setHand(game, copper, r, 3)){ printf("%d: Error setting DECK.\n", counter); } if(setHand(game, estate, r, 0)){ printf("%d: Error setting HAND.\n", counter); } if(adventurerMethod(game, tempHand, player) != 0){ printf("%d: Error unknown.\n", counter); counter++; } else{ treasureCounter = 0; for(i=0;i<game->handCount[player];i++){ if(game->hand[player][i] == copper){ treasureCounter++; } } if(treasureCounter != 2){ printf("%d: adventureMethod(): FAIL, random deck. tcount - %d.\n", counter, treasureCounter); } else{ printf("%d: adventurerMethod(): PASSED random.\n", counter); } counter++; } //Fourth check, no treasure in deck, only last cards are copper if(setHand(game, curse, r, 1)){ printf("%d: Error setting DECK.\n", counter); } if(setHand(game, estate, r, 0)){ printf("%d: Error setting HAND.\n", counter); } if(adventurerMethod(game, tempHand, player) != 0){ printf("%d: Error unknown. NO TREASURE.\n", counter); counter++; } else{ treasureCounter = 0; for(i=0;i<game->handCount[player];i++){ if(game->hand[player][i] == copper){ treasureCounter++; } } if(treasureCounter > 0){ printf("%d: adventureMethod(): FAIL, no treasure deck. tcount - %d.\n", counter, treasureCounter); } else{ printf("%d: adventurerMethod(): PASSED no treasure?.\n", counter); } counter++; } }
void kpok::initPoker(unsigned int numPlayers) { m_numPlayers = numPlayers; // Tell the game about the players also. PokerGameType gametype = (numPlayers == 1) ? SinglePlayer : MultiPlayer; // Read some defaults. kapp->config()->setGroup("General"); int minBet = kapp->config()->readNumEntry("MinBet", MIN_BET); int maxBet = kapp->config()->readNumEntry("MaxBet", MAX_BET); // Start a new poker game using the data found out above. m_game.newGame(gametype, m_numPlayers, m_players, minBet, maxBet); // Not (yet) configurable cashPerRound = CASH_PER_ROUND; drawDelay = kapp->config()->readNumEntry("DrawDelay", DRAWDELAY); m_blinkingBox = 0; currentMustBet = m_game.getMinBet(); // --- Graphics --- // Make all labels / boxes / cardwidgets for every player. playerBox = new PlayerBox *[numPlayers]; for (int unsigned i = 0; i < numPlayers; i++) { playerBox[i] = new PlayerBox(i == 0, this); playerBox[i]->setPlayer(&m_players[i]); if (i == 0) topLayout->insertWidget(0, playerBox[i]); else topLayout->addWidget(playerBox[i]); playerBox[i]->showName(); // If it has been deleted and created again it hasn't be shown // correctly - hiding and re-showing solves the problem. playerBox[i]->hide(); playerBox[i]->show(); } // Connects for player 1 // // FIXME: Make CardWidget::toggleHeld() work. playerBox[0]->activateToggleHeld(); connect(playerBox[0], SIGNAL(toggleHeld()), this, SLOT(toggleHeld())); // hide some things playerBox[0]->showHelds(false); wonLabel->hide(); emit showClickToHold(false); // Different meaning of the status for single and multi player games. if (m_game.getNumActivePlayers() > 1) { setHand(i18n("Nobody"), false); betBox->show(); betBox->setEnabled(false); potLabel->show(); } else { setHand(i18n("Nothing")); betBox->hide(); potLabel->hide(); playerBox[0]->singlePlayerGame(cashPerRound); } // Some final inits. drawStat = 0; waveActive = 0; fCount = 0; // Finally clear the pot and show the decks/cash - in one word: begin :-) m_game.clearPot(); drawAllDecks(); for (unsigned int i = 0; i < m_numPlayers; i++) { playerBox[i]->repaintCard(); } paintCash(); playerBox[0]->setHeldEnabled(false); }