Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
aspx
Not quite what you are looking for? You may want to try: ×
SoundPlayer bug - Calling unmanaged APIs
Blackjack - a real world OOD example
highlights off
Home Articles Questions & Answers Learning Zones Features Help! The Lounge Design a blackjack game.
» Platforms, Frameworks & Libraries » Game Development » Games
Licence CPOL
See Also...
Announcements
1 of 4 3/1/2011 8:42 AM
Blackjack Game Simulator - CodeProject http://www.codeproject.com/KB/game/Blackjack_Game_Simulator.aspx
Common Component
IPlayer's methods are called by the Game component to notify the player about events.
Game Component
PlayerStatus class - wrapper class for player; data such as current player's hand and current
status are stored in this class to prevent cheating :)
Game class - blackjack game logic and control
PlayerDirectory class - dynamically loads the player's components
OnRoundEnd
OnGameEnd
OnPlayerAdded
OnPlayerRemoved
OnPlayerListCleared
OnDealerChange
Game runs in its own thread and has methods for synchronization with GUI animations, which are
played at the end of a round. At round end, the game thread calls WaitForAnimation and waits until
the GUI thread signals that the animation is finished by calling AnimationFinished. Methods
2 of 4 3/1/2011 8:42 AM
Blackjack Game Simulator - CodeProject http://www.codeproject.com/KB/game/Blackjack_Game_Simulator.aspx
StartGame, StopGame, PauseGame and ContinueGame are used to control the game.
The PlayerDirectory class has the tasks of loading players' components and instantiation of players.
In the class constructor, all assemblies from the .\Players folder are checked and loaded if containing a
player's class. The name of a player class must be MyPlayer and must be in the Player namespace.
Other assemblies can be added by calling the LoadPlayer method and specifying the path to assembly.
To create an instance of a player, just call CreateInstanceOfPlayer, specifying the assembly name
and constructor parameters as needed.
Collapse
playerDirectory.CreateInstanceOfPlayer("PlayerWithNameAndAge",
new object[]{ "Someone", 30 } );
Simple Player
Collapse
using Common;
namespace Player
{
public class MyPlayer : IPlayer
{
private Hand _myHand = new Hand();
Framework Project
The framework project provides an easy way of testing a player's logic with complete setup of
environment and project. All unneeded source code has been stripped.
Additional Information
Like I said, there's room for many improvements (i.e. cards should be presented by class not integer
number, animation code can be improved). Also, some rules from blackjack are not implemented, like
the split option for players.
Points of Interest
Well, my college has had some fun making smarter players and had a little competition. I hope you will
enjoy it, too.
History
24 August, 2007 -- Original version posted
License
3 of 4 3/1/2011 8:42 AM
Blackjack Game Simulator - CodeProject http://www.codeproject.com/KB/game/Blackjack_Game_Simulator.aspx
This article, along with any associated source code and files, is licensed under The Code Project Open
License (CPOL)
Mladen Jankovic
Software Developer
Coolsoft Software
Development
Serbia
Member
(Refresh)
-- There are no messages in this forum --
4 of 4 3/1/2011 8:42 AM