本文整理汇总了C++中Hand::dealCard方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::dealCard方法的具体用法?C++ Hand::dealCard怎么用?C++ Hand::dealCard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand::dealCard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HitButtonProc
LRESULT CALLBACK HitButtonProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_LBUTTONDOWN) {
PlaySound(L"sound-flipcard.wav", NULL, SND_FILENAME | SND_ASYNC);
GameEngine* gameEngine = GameEngine::getInstance();
Table* table = gameEngine->getTable();
Hand* playerHand = table->getPlayerHand();
playerHand->dealCard(false);
// Check for bust.
if (playerHand->isBusted()) {
table->setState(TABLE_STATE_FINISHED);
updateTextarea(hStaticTableMiddleMessage, "Busted. Dealer Wins.");
}
RedrawWindow(gameEngine->getHWnd(), NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW);
}
return CallWindowProc(oldHitButtonProc, hwnd, msg, wp, lp);
}
示例2: StandButtonProc
LRESULT CALLBACK StandButtonProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_LBUTTONDOWN) {
GameEngine* gameEngine = GameEngine::getInstance();
User* user = gameEngine->getUser();
Table* table = gameEngine->getTable();
table->setState(TABLE_STATE_STANDING);
Hand* dealerHand = table->getDealerHand();
Hand* playerHand = table->getPlayerHand();
//
// Flip over the first card.
//
dealerHand->GetCards()->at(0)->setFacedown(false);
PlaySound(L"sound-flipcard.wav", NULL, SND_FILENAME | SND_ASYNC);
RedrawWindow(gameEngine->getHWnd(), NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW);
Sleep(500);
//
// See if we need additional cards.
//
while (true) {
std::vector<int>* vals = dealerHand->GetValues();
bool done = false;
for (int i = 0; i < vals->size(); i++) {
// Dealer must stop taking cards
// if he has a value of 17 or higher.
if (vals->at(i) >= 17) {
done = true;
break;
}
}
if (done) {
break;
}
PlaySound(L"sound-flipcard.wav", NULL, SND_FILENAME | SND_ASYNC);
dealerHand->dealCard(false);
RedrawWindow(gameEngine->getHWnd(), NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW);
Sleep(500);
}
//
// Determine winner. Update balance amounts.
//
// table->setState(TABLE_STATE_READY);
std::vector<int>* dealerValues = dealerHand->GetValues();
std::vector<int>* playerValues = playerHand->GetValues();
int dealerFinal = 0;
int playerFinal = 0;
for (int i = 0; i < dealerValues->size(); i++) {
if (dealerValues->at(i) > dealerFinal &&
dealerValues->at(i) < 22) {
dealerFinal = dealerValues->at(i);
}
}
for (int i = 0; i < playerValues->size(); i++) {
if (playerValues->at(i) > playerFinal &&
playerValues->at(i) < 22) {
playerFinal = playerValues->at(i);
}
}
table->setState(TABLE_STATE_FINISHED);
// If values are same, this is a push.
if (dealerFinal == playerFinal) {
updateTextarea(hStaticTableMiddleMessage, "Push");
// Return player's bet money.
int bet = playerHand->getBetAmount();
user->setBalance(user->getBalance() + bet);
} else if (dealerFinal < playerFinal) {
// Player wins, return bet and winning.
updateTextarea(hStaticTableMiddleMessage, "Player Wins!");
int bet = playerHand->getBetAmount();
//.........这里部分代码省略.........
示例3: DealButtonProc
LRESULT CALLBACK DealButtonProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_LBUTTONDOWN) {
TCHAR buff[64];
GetWindowText(hTextboxBetAmount, buff, 20);
int bet = _ttoi(buff);
/*
for (int i = 0; buff[i] != NULL; i++) {
if (! std::isdigit(buff[i]) ) {
MessageBox(
GameEngine::getInstance()->getHWnd(),
L"Invalid bet amount.",
L"Error",
NULL);
return 0;
}
}
*/
// int bet = atoi(buff);
Table* table = GameEngine::getInstance()->getTable();
User* user = GameEngine::getInstance()->getUser();
// Can player bet this much?
if (bet > user->getBalance()) {
MessageBox(
GameEngine::getInstance()->getHWnd(),
L"Insufficient funds available to place this bet.",
L"Error",
NULL);
return 0;
}
if (bet == 0) {
MessageBox(
GameEngine::getInstance()->getHWnd(),
L"Must bet more than $0.",
L"Error",
NULL);
return 0;
}
Hand* dealerHand = new Hand();
Hand* playerHand = new Hand();
playerHand->setBetAmount(bet);
user->setBalance(user->getBalance() - bet);
dealerHand->dealCard(true);
dealerHand->dealCard(false);
playerHand->dealCard(false);
playerHand->dealCard(false);
table->setDealerHand(dealerHand);
table->setPlayerHand(playerHand);
GameEngine::getInstance()->setState(GameEngine::STATE_PLAYING);
PlaySound(L"sound-chips.wav", NULL, SND_FILENAME | SND_ASYNC);
//
// Check if we have blackjack, if so player
// wins right away. Otherwise move to substate
// "playing"
//
if (playerHand->isBlackjack()) {
table->setState(TABLE_STATE_FINISHED);
updateTextarea(hStaticTableMiddleMessage, "Blackjack! Player Wins.");
// Play YAY sound
PlaySound(L"sound-yay.wav", NULL, SND_FILENAME | SND_ASYNC);
// Update user balance.
user->setBalance(user->getBalance() + (bet*2));
} else {
table->setState(TABLE_STATE_PLAYING);
}
//
// Force redraw of window, which should now render the new
// card data.
//
// https://msdn.microsoft.com/en-us/library/dd162911%28VS.85%29.aspx
// http://stackoverflow.com/questions/2325894/difference-between-invalidaterect-and-redrawwindow
//
RedrawWindow(GameEngine::getInstance()->getHWnd(), NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW);
return 0;
}
//.........这里部分代码省略.........