Skip to content

DennisLiu1993/BlackJack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BlackJack

Using MFC to create a BlackJack game platform

What Techniques Used in This Project

  1. double buffer drawing strategy in MFC to prevent controls or numbers from blinking (see OnPaint ())
  2. usage of CButtonST (Image Button with features of transparent background and no border)
  3. OpenCV perspective tranform to show slanted cards (see WarpPespective ())
  4. dynamically show number changes (see code when win or lose)
  5. dealing cards animation

Interface

image

Demo Gif

image

How to Build

  1. Download Visual Studio 2017 or newer versions
  2. Check on the option of "x86 and x64 version of C++ MFC"
  3. Install
  4. Open BlackJack.vcxproj
  5. Upgrade if it is required
  6. Open this project's property page
  7. Choose the SDK version you have in "General-Windows SDK Version"
  8. Choose the right toolset you have in "General-Platform Toolset" (for me, it is Visual Studio 2017 (v141))
  9. Go to "C/C++ - General", and type in "Additional Include Directories" for your own OpenCV include headers (e.g. C:\OpenCV3.1\opencv\build\include or C:\OpenCV4.0\opencv\build\include)
  10. Type in "Library Directories" for your own OpenCV's library path (the directory where your opencv_worldXX.lib locates)
  11. Go to "Linker-Input", and type in library name (e.g. C:\OpenCV3.1\build2017_worldx64\lib\opencv_world310d_vs2017_x64.lib)
  12. Make sure that your opencv_worldXX.dll and is in the same directory as .exe of this project (after building)

Extentions

With Perspective Tranform, we can make the animation of deal more fluent and sophistocated.

If we want to build a full action of flipping cards, we need to divide this action into several steps.

For instance, now I break flipping cards into 20 actions with 20 different perspective matrix:

In this way, showing all cards continually can simulate the action of flipping

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

code to output images like this:

Point2f vecLT2RT = PLAYER_CARD1_RT - PLAYER_CARD1_LT;
Point2f vecLB2RB = PLAYER_CARD1_RB - PLAYER_CARD1_LB;
for (int i = 1; i < 20; i++)
{
	Mat matShow = m_matShow.clone ();
	m_ptsPlayerOne[0] = PLAYER_CARD1_LT + vecLT2RT / 40 * i;//LT
	m_ptsPlayerOne[1] = PLAYER_CARD1_RT - vecLT2RT / 40 * i;//RT
	m_ptsPlayerOne[2] = PLAYER_CARD1_LB + vecLT2RT / 40 * i;//LB
	m_ptsPlayerOne[3] = PLAYER_CARD1_RB - vecLT2RT / 40 * i;//RB
	Mat matAction = getPerspectiveTransform (m_ptsTableTop, m_ptsPlayerOne);
	warpPerspective (m_matHoleCard, matShow, matAction, m_matTableTop.size (), 1, BORDER_TRANSPARENT);
	string s = format ("C:\\users\\user\\Downloads\\%d.jpg", i);
	imwrite (s, matShow (rect));
}

Releases

No releases published

Packages

No packages published