当前位置: 首页>>代码示例>>C++>>正文


C++ Hand::isBlackjack方法代码示例

本文整理汇总了C++中Hand::isBlackjack方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::isBlackjack方法的具体用法?C++ Hand::isBlackjack怎么用?C++ Hand::isBlackjack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hand的用法示例。


在下文中一共展示了Hand::isBlackjack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;

	}
//.........这里部分代码省略.........
开发者ID:jsimpson9,项目名称:win32proto,代码行数:101,代码来源:Table.cpp


注:本文中的Hand::isBlackjack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。