       .  8:   Visual C#  .  2.  1
  


                   ()  -     ,   ,               .    Visual C#   .   8    :       21 ,       ,    ,      ,     ,        .     .      VC#    ,      ,        .              VC#   .





 

       .  8:   Visual C#  .  2.  1








                                  ,       ,        Visual C#         Microsoft ().

  (, artificial intelligence, AI)     ,    ,   ,         .     , ,      ,    ,      -    .  ,         .           .      , ,     ,   ,      ,        .            .

  (, , ) Visual Studio (  VS)   -               ,             .  ,    VS      ,       ,       (    )            Visual C#, Visual Basic  Visual C++.      (   )    ,     ,              .

       ,      .           Visual C#        VC#.     ,        (          ZharkovPress.ru     )    ,         .           ,            VC#,      ;       ,           Visual C#     .    ,        ,    ,   (   ,     ,       ),      ,     .         ,           .     .           (        ,    )      ( : ,  )           VS.               (      )        .                       ZharkovPress.ru (    Help  Visual Studio,  ,      ),       , ,     (   )   , , , , ,      (  )     .                 VS  (  ),            ,        .

     . .  I.       .  1.            21 .  II.           .  2.               .  3.            .  4.       Minjie            .  III.        ,      ,     .  5.          .  6.        ,      ,     .  7.        ,         ,     .  8.            .  9. :   C#         -.  IV. ,          .  10.        . .  .

        ,    Microsoft,      Microsof.                   ,        .     ,        (              ZharkovPress.ru)  ,                ,                 ,            .

                         ,    (  )    Visual C#     ,   ,                           .      ,   ,      , , , ,    .

    (     )         .

,             email  : ZharkovPress.ru.

:       (. ).

 

I

.       




 1.            21 


1.1.  



                   21,     microsoft.com: Rob Miles. Pocket Jack: Writing a Card-Playing Application,        Visual Studio.

      ,          ,    .  ,             ,         ,   .

     ,         .       ( )   (    ),    ,    ""       .     ,         Black Jack, 21  pontoon   52- ,            21   36- .           52-     36  (  ).

  .   ,  ,  :      ,  .     (-  dealer  )     ,     ,     21   21 (21      ),    21.     21,     ,    .      21,       .     ,  ,   ,   ,  .        ,   ,     ,  ,  (    ).    .

1.2.    

 ,   ,    ,    , ,   ,   .   ,  : 52      , , (.gif),     0.gif,    bank.jpg     loading.gif. ,   (.gif)   Graphics Interchange Format (   ).        . 1.1,       . 1.2  1.5. ,      1, 2, 3,,52      13     (  :   club,   diamond,   heart,   spade).    0   .              .       1  ,      ,     .








. 1.1.        .








. 1.2.      .








. 1.3.      .

    13  1, 2, 3, ,13     club.       (Ace  A).








. 1.4.      .

    13  14, 15, 16, , 26     diamond  13  27, 28, 29, , 39     heart.        (Ace  A).

  13  40, 41, 42, , 52      spade.








. 1.5.      .

    :  (Ace  A) = 1  11;  1-, 2-  3-     11 ; ,   ,   11     10+11=21     PocketJack,    ,   21;  4-       1 ;     2  9    ;

   10 card with number 10,  (Jack  J),  (Queen  Q),  (King  K) =  10 .

1.3.     



        ,         ,      ,        Embedded Resource,         .

                 Image  Bitmap.           playfield,  .      ,    .   ,    :

static private Image[] cardImages = new Bitmap[53];

System.Reflection.Assembly execAssem =

System.Reflection.Assembly.GetExecutingAssembly();

for (int i=0 ; i< 53 ; i++ )

{

cardImages[i] =

new Bitmap(execAssem.GetManifestResourceStream (

@"PocketJack.cardImages."+i+@".gif"));

}

,        PocketJack,       cardImages,    cardImages      i    (.gif).

  ,      ,    :

public Image CardImage

{

get

{

int dispNo = CardNo;

if (!FaceUp)

{

dispNo = 0;

}

if (cardImages[dispNo] == null)

{

cardImages[dispNo] = new Bitmap(

execAssem.GetManifestResourceStream(

@"PocketJack.images." +dispNo + @".gif"));

}

return cardImages[dispNo];

}

}

,        PocketJack,       images,    cardImages      dispNo    (.gif).

1.4.   

        .       .      ,       .    ,  ,        .          ,   ,      ,    . 1.6.








. 1.6.     .

         ,      Form1    .     ,     ImageAttributes      :

static public System.Drawing.Imaging.ImageAttributes

cardAttributes;

static Card()

{

cardAttributes =

new System.Drawing.Imaging.ImageAttributes();

cardAttributes.SetColorKey(Color.Green, Color.Green);

execAssem =

System.Reflection.Assembly.GetExecutingAssembly();

}

    SetColorKey      ,     .    .NET Compact Framework          ,         .

          Form1   BackColor -  (DarkGreen)   Color.

   ,  DrawImage   :

private static Rectangle drawRect;

public void DrawHand(Graphics g, int startx, int starty,

int gapx, int gapy)

{

drawRect.X = startx;

drawRect.Y = starty;

foreach (Card card in this)

{

drawRect.Width = card.CardImage.Width;

drawRect.Height = card.CardImage.Height;

g.DrawImage(

card.CardImage,// Image

drawRect,// destination rectange

0,// srcX

0,// srcY

card.CardImage.Width, // srcWidth

card.CardImage.Height,// srcHeight

GraphicsUnit.Pixel,// srcUnit

Card.cardAttributes); // ImageAttributes

drawRect.X += gapx;

drawRect.Y += gapy;

}

}

           (      Random).

1.5.  Card   

  

   CardEngine.cs   Card      .           .    ,        ,       .  Card       ,    ,      .

   Card    ,    .   52         .    .       ,          :

static private Image[] cardImages = new Bitmap[53];

public Image CardImage

{

get

{

int dispNo = CardNo;

if (!FaceUp)

{

dispNo = 0;

}

if (cardImages[dispNo] == null)

{

cardImages[dispNo] = new Bitmap(

execAssem.GetManifestResourceStream(

@"PocketJack.images." +dispNo + @".gif"));

}

return cardImages[dispNo];

}

}

 cardImages    .        .     dispNo       .        (null),       .   ,     ,    .       ,          ; , ,      ,   ,  .         ,         ,  ,         .

1.6.  CardHand   

   

   CardEngine.cs      CardHand (     ),    .        :           .  CardHand,    ,   .     ArrayList,      CardHand       .     ,      ,     :

public void DrawHand(Graphics g, int startx, int starty,

int gapx, int gapy)

 ,  ,  ,      .         .

 CardHand    ,        blackjack ():

public int BlackJackScoreHand()

{

int score = 0;

int aces = 0;

foreach (Card card in this)

{

score += card.BlackJackScore;

if (card.BlackJackScore == 11)

{

aces++;

}

}

while ((score > 21) && (aces > 0))

{

score -= 10;

aces;

}

return score;

}

      .      (aces),    ,       ,  ,        21,     .

1.7.  CardShoe   

       

 ,       CardEngine.cs,  CardShoe.    ,       (      ...).       ,  shoe ()  deck (),   .      (shuffle)      .       ...       .  CardShoe         .         ,     ,    .

    ,    ,      ().       ,        50    ,  ,    ,     ,  21.   CardShoe   .      ,     ,      ,    ,       byte   "  " .    ,          .              ,      .

 ,             (   ),      CardShoe,           . ,     ,      ,            .

 ,       ,  blackjacks,      ,     :

public CardShoe(byte[] stackedDeck)

{

decks = stackedDeck;

testShoe = true;

}

          .   1       ,   .     13 , 14-      ,    .      (player)   (banker)       1  14    ,   ,   , .   11  25   ()      ,  ,     ()    .     (player),   (banker)   ,   ()    ,   .

1.8.   

  ,   (Clear)   (player's hand)       :

CardHand playerHand = new CardHand();

playerHand.Clear();

dealerHand.Clear();

// deal the face down hole card

dealerHoleCard = shoe.DealCard();

dealerHoleCard.FaceUp = false;

dealerHand.Add(dealerHoleCard);

// deal the first player card

playerHand.Add(shoe.DealCard());

// deal the second dealer card (face up)

dealerHand.Add(shoe.DealCard());

// deal the second player card

playerHand.Add(shoe.DealCard());

  ,  ,           .        .

     Hit Me  maneMenu1.    ,     ,       21,     :

void playerHits()

{

if (playerHand.BlackJackScoreHand() < 21)

{

playerHand.Add(shoe.DealCard());

if (playerHand.BlackJackScoreHand() > 21)

{

//We write in the original:

pot.DoPlaceBet();

pot.HouseWins();

showPot();

mode = GameMode.PlayerBust;

}

this.Invalidate();

}

}

,   BlackJackScoreHand       (playerHand).    Invalidate   Form1, ,       .    maneMenu1   ,       ( ).

1.9.   

 Windows       ,      -  . ,       - ,   .    ,          ,        .   ,    ,     :

static private SolidBrush messageBrush =

new SolidBrush(Color.Black);

public static void BigText(string message, int x, int y,

Color back, Color fore,

Font messageFont, Graphics g)

{

int i;

messageBrush.Color = back;

for (i = 1; i < 3; i++)

{

g.DrawString(message, messageFont, messageBrush,

x  i, y  i);

g.DrawString(message, messageFont, messageBrush,

x  i, y + i);

g.DrawString(message, messageFont, messageBrush,

x + i, y  i);

g.DrawString(message, messageFont, messageBrush,

x + i, y + i);

}

messageBrush.Color = fore;

g.DrawString(message, messageFont, messageBrush, x, y);

}

  BigText     ,       (message)   (messageFont)   .         .            .   ,         Utilities,      ,     :

Utilities.BigText("Dealer Bust",

20, 80, Color.Black, Color.Yellow, messageFont, g);

    "Dealer Bust!"    .

 messageFont  Font          .

           Paint (      Paint   Properties   Form1),               ,     .    ,             Paint.    ,      Form1_Paint     paintForm,     :



private void Form1_Paint(object sender, PaintEventArgs e)

{

paintForm(e.Graphics);

}

1.10. 









     ,       . ,     ,     (player)    ( ),     (   dealer)    (  ).

            :

      (the player is making his or her moves);

   (the player busted);

  (the player has won);

 (dealer)    (the dealer is making his or her moves.);

   (the dealer busted);

  (the dealer has won);

  (the score is tied, known as a push).

        ,     . ,       ,      .         (mode)   enum  :

public enum GameMode

{

LoadingDisplay,

PlacingBets,

PlayerActive,

PlayerWon,

PlayerBust,

PocketJack,

DealerActive,

DealerWon,

DealerBust,

Push

}

  GameMode   .     .    ,    .        ,       :

GameMode modeValue;

GameMode mode

{

get

{

return modeValue;

}

set

{

switch (value)

{

case GameMode.LoadingDisplay:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Point";

StayToolStripMenuItem.Enabled = false;

MenuToolStripMenuItem.Text = "21";

MenuToolStripMenuItem.Enabled = false;

break;



modeValue = value;

this.Invalidate();

}

}

    value,        set.    set ,  switch    . ,       PlayerActive,    Hit  Stay. ,       ,       .   ,           . , ,    ,   Invalidate   .

  (game state)   ,    Paint,     :

void paintForm(Graphics g)

{

switch (mode)

{



case GameMode.PlayerActive:

dealerHand.DrawHand(g, 10, 30, 80, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

break;



    Paint ,       .    ,    .

1.11.   

 (dealer)    ,        (face down).       :

// clear the hands

playerHand.Clear();

dealerHand.Clear();

// deal the face down hole card

dealerHoleCard = shoe.DealCard();

dealerHoleCard.FaceUp = false;

dealerHand.Add(dealerHoleCard);

// deal the first player card

playerHand.Add(shoe.DealCard());

// deal the second dealer card (face up)

dealerHand.Add(shoe.DealCard());

// deal the second player card

playerHand.Add(shoe.DealCard());



mode = GameMode.PlayerActive;

    "  hole"  ,     ,    .     FaceUp (  ) ,  False.    ,       "  hole"  .     ,  FaceUp (  )   True,        . ,    (mode)        ,       .

       ,        ,    .          ,      "  " ,     .

1.12.   

  ,  ,      .    ,      21,     :



void playerHits()

{

if (playerHand.BlackJackScoreHand() < 21)

{

playerHand.Add(shoe.DealCard());

if (playerHand.BlackJackScoreHand() > 21)

{

//We write in the original:

pot.DoPlaceBet();

pot.HouseWins();

showPot();

mode = GameMode.PlayerBust;

}

this.Invalidate();

}

}

    21,     (the player busts),    ,   . ,  ,         .

   ,   ,    (stay)   ,     :

void playerStays()

{

dealerHoleCard.FaceUp = true;

mode = GameMode.DealerActive;

this.Refresh();

System.Threading.Thread.Sleep(750);

while (dealerHand.BlackJackScoreHand() < 17)

{

dealerHand.Add(shoe.DealCard());

this.Refresh();

System.Threading.Thread.Sleep(750);

}

if (dealerHand.BlackJackScoreHand() > 21)

{

mode = GameMode.DealerBust;

pot.PlayerWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() >

dealerHand.BlackJackScoreHand())

{

mode = GameMode.PlayerWon;

pot.PlayerWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() <

dealerHand.BlackJackScoreHand())

{

mode = GameMode.DealerWon;

//   :

pot.DoPlaceBet();

pot.HouseWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() ==

dealerHand.BlackJackScoreHand())

{

mode = GameMode.Push;

pot.DoPushBet();

showPot();

return;

}

}

       DealerActive      .        ,      .     ,      ,     17.       .     750     ,      (      ).   Refresh ,        .

   ,  21,    DealerBust (  ),    . ,  ,       .      new game    ,           .

1.13. -  

        .   ,          ,  ,     .       ,    .    ,          ,     ,     :

void doEnter()

{

switch (mode)

{

case GameMode.LoadingDisplay:

break;

case GameMode.PlacingBets:

startPlay();

break;

case GameMode.PlayerActive:

playerHits();

break;

case GameMode.PocketJack:

case GameMode.PlayerWon:

case GameMode.PlayerBust:

case GameMode.DealerActive:

case GameMode.DealerWon:

case GameMode.DealerBust:

case GameMode.Push:

startHand();

break;

}

}

          MenuStrip.

     ,       .   PlayerActive,   Enter,     .          .   Stay ()   MenuStrip,      .

    ,      .         (      ),     , ,  ,           .    . ,     MenuStrip      - ; ,   Hit     .     ,    ,    .

1.14.   

       (Pot).   ,     (Bet),          .          ,      .     ,              .      Pot,        ( ).       ,    (  ),     .      ,   ,       .

    ,       .        MenuStrip.

              MenuStrip    .          ,          ,    .

1.15.   

     ,   .        .   :

 ,

   Loading,            - 

  .

      Form2 (    Form1   ),           Toolbox, ,   TextBox     .          MenuStrip,         (. 1.7),     Form1     2 (. 1.8). ,     MenuStrip      .   Form2     Close,        Form1.















. 1.7.    . . 1.8.  .

1.16.   

                (a loading screen)    loading.gif.        (mode = GameMode.LoadingDisplay;)    Paint        (,      )   ,   .           .      ,       Visible,     :

System.Reflection.Assembly asm =

System.Reflection.Assembly.GetExecutingAssembly();

loadingImage = new Bitmap(asm.GetManifestResourceStream(

"PocketJack.images.loading.gif"));

bankImage = new Bitmap(asm.GetManifestResourceStream(

"PocketJack.images.bank.jpg"));

mode = GameMode.LoadingDisplay;

this.Visible = true;

    

PocketJack.images.loading.gif

 PocketJack    (  ),

  images   ,      loading.gif.

  ,   loading.gif             ,     :

void paintForm(Graphics g)

{

switch (mode)

{

case GameMode.LoadingDisplay:

//We draw all images below the menu:

g.DrawImage(

bankImage, 0, StayToolStripMenuItem.Height);

g.DrawImage(

loadingImage, 0, StayToolStripMenuItem.Height + 60);

break;

case GameMode.PlacingBets:

g.DrawImage(bankImage, 0, StayToolStripMenuItem.Height);

Utilities.BigText("Bank : " +pot.PotValue.ToString(),

10, 40, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText("Bet : " +

pot.BetValue.ToString(), 10, 80, Color.Black,

Color.Yellow, messageFont, g);

break;



 . 1.9        loading.gif   POCKET JACK LOADING       bank.jpg.        ,        ,   ,        ,    .








. 1.9.   loading.gif

         ,      .

1.17.  

     ( 52 )   ,         Form2,          MenuStrip    Form1.

1.  ()           -.

2.       , , 500      , , , 5 .         ,        .

  ,     500,                500 .

        500,           500     .

,              ,    .

3.    ,     ,         ,     21,    21, ,   , ,   .        ,          .

4.             (. 1.10),    loading.gif,          bank.jpg    :

: 500 : 5















. 1.10.   () .  . 1.11.   +  .

     ,         MenuStrip,      +   - (. 1.11) .       .           .  ,        .      .

5.      Enter.

    (  Text  Form1)       (. 1.12): : 500 : 5

           ,            (. 1.12).      pj_bg_noise.wav        .

6.     .       , ,

  ,    Enter (     , .  )    ,

,   ,         (    ).















. 1.12.      . . 1.13.   .

  (  ),         ,       17   .     14 . ,        (      ).   ,     Enter   . , ,      ,            22 (. 1.13).       pj_busted.wav.         ,         :

: 495 : 5

7.            (  )    Enter.

  Enter.

        bank.jpg           (  Text  Form1),          ,   DrawString (. 1.14):

: 495 : 5

  . ,      Enter.          (. 1.15).

8.       .       , ,

  ,    Enter    ,

,   ,        Take a card to yourself (    ).

  (  ),         ,       17   .

     9 .     Enter    .    ,    14   (. 1.16).















. 1.14.     . . 1.15.    .















. 1.16.   14 . . 1.17.   17 .

9.    Enter   .    ,    17   (. 1.17).

10.  , ..    17   17,      ,     21,     .

      .      , ,

  ,    Enter    ,      ( 21),

,   ,        Take a card to yourself (    ),      .

,     Enter   .  , ,      ,            (. 1.18).

      pj_busted.wav.

        , ,  505  500     : : 500 : 5















. 1.18.     . . 1.19.     .

11.  , ,  -     Enter.

        bank.jpg           (  Text  Form1),          ,   DrawString (. 1.19):

: 490 : 5

12.            (  )    Enter.

  Enter.         .

  ,    (  ,   )     ,        .

      .

13.    Enter  (  ,   )     , ,  16 (. 1.20)          .

,   ,  20 ,         .

            .

14.    Enter    ,  ,   ,    21  ( , ),          (. 1.21).

            .

15.    Enter  (  ,   )     , ,  18 (. 1.22)          .















. 1.20.  . . 1.21.    .















. 1.22.  . . 1.23.    .

,   ,   17 ,         .

           .

        pj_claps.wav.

16.    Enter  (  ,   )     , ,  20 (. 1.23)          .

,   ,  22 ,          ( ).

           .

17.    Enter  (  ,   )     , ,  17 (. 1.24)          .















. 1.24.   . . 1.25.      PocketJack.

,   ,   17 .  ,      ,      , .. .         .        , , ,    .            .

18.    Enter    , ,   ,     21  ( , ),    .       .    , ,     21    PocketJack,    21   .          (. 1.25).

           .

     PocketJack    pj_pj.wav (   pj     PocketJack).

19. , 

13  1, 2, 3, ,13      (club),

13  14, 15, 16, , 26      (diamond),

13  27, 28, 29, , 39      (heart),

13  40, 41, 42, , 52       (spade).

      (Ace  A).

    :

 (Ace  A) = 1  11;

 1-, 2-  3-     11 ;

 ,   ,   11     10+11=21     PocketJack,     (  ),   21;

 4-       1 ;

    2  9    ;

   10,  (Jack  J),  (Queen  Q),  (King  K) =  10 .

20.       .

21.     ,    17  .

22.      ,         .

23.       ,         (      +   -      MenuStrip).

24.        .       ,     .

25.    ,    ,     .     (     ).

26.  :

    , , 1:1.

27.    ,         ,       Enter.

28.        ,    , , ,            .    ,     .

29.         .

                      (     ).

1.18.  

    : VS   New Project   Templates, Visual C#, Windows Classic Desktop, Windows Forms App (.NET Framework),   Name    PocketJack   OK.        . ,    Name     ,   PocketJack,              ,          ( Form1.cs)    PocketJack   .

 ,   Form1 (.     )   .  (   ) ,       , , 361; 408.       ,   Properties ( Form1)   BackColor      Control    Window.

      ,         , , images.      ,   Solution Explorer (. 1.26  1.28)      ,     Add, New Folder,         images    Enter.     images  0.gif (       ,      )   ,  :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,         (, ,         )    Add (     ).   Solution Explorer    .





























. 1.26.  images ( ). . 1.27.  images ( ).















. 1.28.  . . 1.29.  Embedded Resource.

    0.gif          ,  :  Solution Explorer     ,    Properties (  )   Build Action       Embedded Resource, . 1.29.

            :

  52 ,  

1.gif, 10.gif, 11.gif, 12.gif, , 52.gif,

 bank.jpg  ,   ,

   loading.gif,                

     pj_bg_noise.wav (        )   ,  :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,         (, ,         )    Add (     ).   Solution Explorer    .

       :

pj_busted.wav         ;

pj_claps.wav            ;

pj_pj.wav         ,  PocketJack       .

,           ,    ,    Embedded Resource     ,       (      ,      Shift             ,      Ctrl        ).

  , DirectX  .

1.19.  

  Form1.cs (,  : File, Open, File)           :

using System.Reflection; //Namespace for class Assembly.

using System.Media; //Namespace for class SoundPlayer.

using System.IO; //Namespace for class Stream.

  Form1       .

 1.1.   .

//Shoe of cards:

CardShoe shoe;

CardHand playerHand = new CardHand();

Card dealerHoleCard;

CardHand dealerHand = new CardHand();

//Bank of a game:

Pot pot;

//We declare an object for a help form:

Form2 helpForm;

Image loadingImage = null;

Image bankImage = null;

public enum GameMode

{

LoadingDisplay,

PlacingBets,

PlayerActive,

PlayerWon,

PlayerBust,

PocketJack,

DealerActive,

DealerWon,

DealerBust,

Push

}

GameMode modeValue;

GameMode mode

{

get

{

return modeValue;

}

set

{

switch (value)

{

case GameMode.LoadingDisplay:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Point";

StayToolStripMenuItem.Enabled = false;

MenuToolStripMenuItem.Text = "21";

MenuToolStripMenuItem.Enabled = false;

break;

case GameMode.PlacingBets:

BetMinusToolStripMenuItem1.Enabled = true;

BetPlusToolStripMenuItem.Enabled = true;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

break;

case GameMode.PlayerActive:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = true;

StayToolStripMenuItem.Text = "Take a card to yourself";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//Disturbing noise of the support groups

//surrounding the player:

//not single, but continuous Looping;

Assembly a = Assembly.GetExecutingAssembly();

Stream s =

a.GetManifestResourceStream(

"PocketJack.pj_bg_noise.wav");

SoundPlayer player = new SoundPlayer(s);

player.PlayLooping();

break;

case GameMode.PlayerWon:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//An applause in our address for a prize in cards:

Assembly a1 = Assembly.GetExecutingAssembly();

Stream s1 =

a1.GetManifestResourceStream(

"PocketJack.pj_claps.wav");

SoundPlayer player1 = new SoundPlayer(s1);

player1.Play();

break;

case GameMode.PlayerBust:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//Discontent of support group with our exceeding of

//cards:

Assembly a2 = Assembly.GetExecutingAssembly();

Stream s2 =

a2.GetManifestResourceStream(

"PocketJack.pj_busted.wav");

SoundPlayer player2 = new SoundPlayer(s2);

player2.Play();

break;

case GameMode.PocketJack:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//A victorious tune after Pocket Jack with 21 points:

Assembly a3 = Assembly.GetExecutingAssembly();

Stream s3 =

a3.GetManifestResourceStream(

"PocketJack.pj_pj.wav");

SoundPlayer player3 = new SoundPlayer(s3);

player3.Play();

break;

case GameMode.DealerActive:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = false;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

break;

case GameMode.DealerWon:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//Discontent of support group with our exceeding of

//cards:

Assembly a4 = Assembly.GetExecutingAssembly();

Stream s4 =

a4.GetManifestResourceStream(

"PocketJack.pj_busted.wav");

SoundPlayer player4 = new SoundPlayer(s4);

player4.Play();

break;

case GameMode.DealerBust:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

//An applause in our address for a prize in cards:

Assembly a5 = Assembly.GetExecutingAssembly();

Stream s5 =

a5.GetManifestResourceStream(

"PocketJack.pj_claps.wav");

SoundPlayer player5 = new SoundPlayer(s5);

player5.Play();

break;

case GameMode.Push:

BetMinusToolStripMenuItem1.Enabled = false;

BetPlusToolStripMenuItem.Enabled = false;

HitMeToolStripMenuItem.Enabled = false;

StayToolStripMenuItem.Text = "Distribution of cards";

StayToolStripMenuItem.Enabled = true;

MenuToolStripMenuItem.Text = "Menu";

MenuToolStripMenuItem.Enabled = true;

break;

}

modeValue = value;

this.Invalidate();

}

}

//We load the game objects:

public void init()

{

System.Reflection.Assembly asm =

System.Reflection.Assembly.GetExecutingAssembly();

loadingImage = new Bitmap(asm.GetManifestResourceStream(

"PocketJack.images.loading.gif"));

bankImage = new Bitmap(asm.GetManifestResourceStream(

"PocketJack.images.bank.jpg"));

mode = GameMode.LoadingDisplay;

this.Visible = true;

this.Refresh();

pot = new Pot();

//We create also initsializuy the help Form2 form:

helpForm = new Form2();

}

void startGame()

{

shoe = new CardShoe();

//We comment in the original,

//since this line  only for testing of a game:

//shoe =

//new CardShoe(new byte[] { 2, 14, 11, 25, 10, 7, 6, 5 });

pot.ResetPot();

mode = GameMode.PlacingBets;

}

void startHand()

{

mode = GameMode.PlacingBets;

}

void showPot()

{

this.Text =

"Bank: " +pot.PotValue.ToString() + " Bet: " +

pot.BetValue.ToString();

}

void startPlay()

{

//We commented out in the original:

//pot.DoPlaceBet();

//We write in the original:

if (mode == GameMode.PlayerBust && mode == GameMode.DealerWon)

pot.DoPlaceBet();

showPot();

// clear the hands

playerHand.Clear();

dealerHand.Clear();

// deal the face down hole card

dealerHoleCard = shoe.DealCard();

dealerHoleCard.FaceUp = false;

dealerHand.Add(dealerHoleCard);

// deal the first player card

playerHand.Add(shoe.DealCard());

// deal the second dealer card (face up)

dealerHand.Add(shoe.DealCard());

// deal the second player card

playerHand.Add(shoe.DealCard());

if ((dealerHand.BlackJackScoreHand() == 21) &&

(playerHand.BlackJackScoreHand() != 21))

{

//We write in the original:

pot.DoPlaceBet();

pot.HouseWins();

showPot();

//Discontent of support group with our exceeding of

//cards:

Assembly a2 = Assembly.GetExecutingAssembly();

Stream s2 =

a2.GetManifestResourceStream("PocketJack.pj_busted.wav");

SoundPlayer player2 = new SoundPlayer(s2);

player2.Play();

dealerHoleCard.FaceUp = true;

mode = GameMode.DealerWon;

return;

}

if ((playerHand.BlackJackScoreHand() == 21) &&

(dealerHand.BlackJackScoreHand() != 21))

{

pot.PlayerWins();

showPot();

dealerHoleCard.FaceUp = true;

mode = GameMode.PocketJack;

return;

}

if ((playerHand.BlackJackScoreHand() == 21) &&

(dealerHand.BlackJackScoreHand() == 21))

{

pot.DoPushBet();

showPot();

dealerHoleCard.FaceUp = true;

mode = GameMode.Push;

return;

}

mode = GameMode.PlayerActive;

}

Font messageFont = new Font(FontFamily.GenericSansSerif, 20,

FontStyle.Regular);

void paintForm(Graphics g)

{

switch (mode)

{

case GameMode.LoadingDisplay:

//We draw all images below the menu:

g.DrawImage(

bankImage, 0, StayToolStripMenuItem.Height);

g.DrawImage(

loadingImage, 0, StayToolStripMenuItem.Height + 60);

break;

case GameMode.PlacingBets:

g.DrawImage(bankImage, 0, StayToolStripMenuItem.Height);

Utilities.BigText("Bank : " +pot.PotValue.ToString(),

10, 40, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText("Bet : " +

pot.BetValue.ToString(), 10, 80, Color.Black,

Color.Yellow, messageFont, g);

break;

case GameMode.PlayerActive:

dealerHand.DrawHand(g, 10, 30, 80, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

break;

case GameMode.PlayerWon:

case GameMode.PocketJack:

dealerHand.DrawHand(g, 10, 30, 20, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(dealerHand.BlackJackScoreHand().

ToString(), 140, 45, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(" !",

20, 80, Color.Black, Color.Yellow, messageFont, g);

break;

case GameMode.PlayerBust:

dealerHand.DrawHand(g, 10, 30, 80, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(" .",

20, 80, Color.Black, Color.Red, messageFont, g);

break;

case GameMode.DealerActive:

dealerHand.DrawHand(g, 10, 30, 20, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(dealerHand.BlackJackScoreHand().

ToString(), 140, 45, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

break;

case GameMode.DealerWon:

dealerHand.DrawHand(g, 10, 30, 20, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(dealerHand.BlackJackScoreHand().

ToString(), 140, 45, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(" .",

20, 80, Color.Black, Color.Red, messageFont, g);

break;

case GameMode.DealerBust:

dealerHand.DrawHand(g, 10, 30, 20, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(dealerHand.BlackJackScoreHand().

ToString(), 140, 45, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText("Dealer Bust",

20, 80, Color.Black, Color.Yellow, messageFont, g);

break;

case GameMode.Push:

dealerHand.DrawHand(g, 10, 30, 20, 25);

playerHand.DrawHand(g, 10, 135, 20, 25);

Utilities.BigText(dealerHand.BlackJackScoreHand().

ToString(), 140, 45, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(playerHand.BlackJackScoreHand().

ToString(), 140, 150, Color.Black,

Color.Yellow, messageFont, g);

Utilities.BigText(" .",

20, 80, Color.Black, Color.Yellow, messageFont, g);

break;

}

}

void playerHits()

{

if (playerHand.BlackJackScoreHand() < 21)

{

playerHand.Add(shoe.DealCard());

if (playerHand.BlackJackScoreHand() > 21)

{

//We write in the original:

pot.DoPlaceBet();

pot.HouseWins();

showPot();

mode = GameMode.PlayerBust;

}

this.Invalidate();

}

}

void playerStays()

{

dealerHoleCard.FaceUp = true;

mode = GameMode.DealerActive;

this.Refresh();

System.Threading.Thread.Sleep(750);

while (dealerHand.BlackJackScoreHand() < 17)

{

dealerHand.Add(shoe.DealCard());

this.Refresh();

System.Threading.Thread.Sleep(750);

}

if (dealerHand.BlackJackScoreHand() > 21)

{

mode = GameMode.DealerBust;

pot.PlayerWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() >

dealerHand.BlackJackScoreHand())

{

mode = GameMode.PlayerWon;

pot.PlayerWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() <

dealerHand.BlackJackScoreHand())

{

mode = GameMode.DealerWon;

//We write in the original:

pot.DoPlaceBet();

pot.HouseWins();

showPot();

return;

}

if (playerHand.BlackJackScoreHand() ==

dealerHand.BlackJackScoreHand())

{

mode = GameMode.Push;

pot.DoPushBet();

showPot();

return;

}

}

void doLeftMenuKey()

{

switch (mode)

{

case GameMode.LoadingDisplay:

break;

case GameMode.PlacingBets:

startPlay();

break;

case GameMode.PlayerActive:

playerStays();

break;

case GameMode.PocketJack:

case GameMode.PlayerWon:

case GameMode.PlayerBust:

case GameMode.DealerActive:

case GameMode.DealerWon:

case GameMode.DealerBust:

case GameMode.Push:

startHand();

break;

}

}

void doEnter()

{

switch (mode)

{

case GameMode.LoadingDisplay:

break;

case GameMode.PlacingBets:

startPlay();

break;

case GameMode.PlayerActive:

playerHits();

break;

case GameMode.PocketJack:

case GameMode.PlayerWon:

case GameMode.PlayerBust:

case GameMode.DealerActive:

case GameMode.DealerWon:

case GameMode.DealerBust:

case GameMode.Push:

startHand();

break;

}

}

void doUp()

{

switch (mode)

{

case GameMode.PlacingBets:

pot.DoIncreaseBet();

showPot();

this.Invalidate();

break;

}

}



void doDown()

{

switch (mode)

{

case GameMode.PlacingBets:

pot.DoDecreaseBet();

showPot();

this.Invalidate();

break;

}

}

void showHelp()

{

helpForm.ShowDialog();

}

  Properties ( Form1)   Events      Load.    Form1_Load       .

 1.2.     .



private void Form1_Load(object sender, EventArgs e)

{

//We load the game objects:

init();

startGame();

}

  Properties ( Form1)   Events      Paint.    Form1_Paint       . ,     , ,    PictureBox     -     .

 1.3.    .

private void Form1_Paint(object sender, PaintEventArgs e)

{

paintForm(e.Graphics);

}

       -    .   ,    Toolbox     MenuStrip     (    ).   Form1     Type Here,     (  ,     Properties   Text): Stay, Menu, Exit, HitMe, BetPlus, BetMinus, Sound, Help, . 1.30.  ,     ,   Properties     Checked    True.








. 1.30.    MenuStrip.

        Stay (  ).         .

 1.4.    .

private void StayToolStripMenuItem_Click(object sender, EventArgs e)

{

doLeftMenuKey();

}

     Exit.          .

 1.5.    .



private void ExitToolStripMenuItem_Click(object sender, EventArgs e)

{

Application.Exit();

}

     Hit Me.          .

 1.6.     .



private void HitMeToolStripMenuItem_Click(object sender, EventArgs e)

{

playerHits();

}

     BetPlus.          .

 1.7.    .

private void BetPlusToolStripMenuItem_Click(object sender, EventArgs e)

{

doUp();

}

      - (Bet -).          .

 1.8.    .



private void BetMinusToolStripMenuItem1_Click(object sender, EventArgs e)

{

doDown();

}

              (Sound)   .   ,   .

     Help.          .

 1.9.     .

private void HelpToolStripMenuItem_Click(object sender, EventArgs e)

{

showHelp();

}

     ,   , ,  (Up)   (Down),  (Left)   (Right)   ,    Enter (             ).   Properties (  Form1)   Events      KeyDown.                (    )   .

 1.10.     .

private void Form1_KeyDown(object sender, KeyEventArgs e)

{

if ((e.KeyCode == System.Windows.Forms.Keys.Up))

{

doUp();

e.Handled = true;

}

if ((e.KeyCode == System.Windows.Forms.Keys.Down))

{

doDown();

e.Handled = true;

}

if ((e.KeyCode == System.Windows.Forms.Keys.Enter))

{

//  :

doEnter();

}

}

       Form1 (  Form1    ).      (Engine Game)     Form1.cs (  ),     CardEngine.cs.

       (    )   .

  Solution Explorer            Add, New Item.   Add New Item   Code File,   Name       *.cs    Add.   (   Solution Explorer)   ,     ,     .

 1.11.   CardEngine.cs.

using System;

using System.Collections;

using System.Drawing;

namespace PocketJack

{

/// <summary>

/// Provides the behaviours required to manage and draw cards

/// </summary>

public class Card

{

/// <summary>

/// The number of the card, in the range 1 to 52

/// </summary>

public byte CardNo;

/// <summary>

/// Indicates if the card is to be drawn face up.

/// True by default.

/// </summary>

public bool FaceUp = true;

/// <summary>

/// The images of the cards. Stored for all the cards.

/// The image with number 0 is the

/// back pattern of the card

/// </summary>

static private Image[] cardImages = new Bitmap[53];

/// <summary>

/// The attribute to be used when drawing the card

/// to implement transpancy

/// </summary>

static public System.Drawing.Imaging.ImageAttributes

cardAttributes;

/// <summary>

/// Used when loading card images prior to drawing

/// </summary>

static private System.Reflection.Assembly execAssem;

/// <summary>

/// Sets up the color and attribute values.

/// </summary>

static Card()

{

cardAttributes =

new System.Drawing.Imaging.ImageAttributes();

cardAttributes.SetColorKey(Color.Green, Color.Green);

execAssem =

System.Reflection.Assembly.GetExecutingAssembly();

}

/// <summary>

/// Scores for each of the cards in a suit

/// </summary>

static private byte[] scores =

new byte[] { 11,//ace

2,3,4,5,6,7,8,9,10, //spot cards

10,10,10}; //jack, queen, king

/// <summary>

/// Picture information for each card in a suit

/// </summary>

static private bool[] isPicture =

new bool[] { false,//ace

false,false,false,false,false,false,

false,false,false, //spot cards

true,true,true}; //jack, queen, king

/// <summary>

/// Names of the suits, in the order that of the suits

/// in the number sequence

/// </summary>

static private string[] suitNames =

new string[] { "club", "diamond", "heart", "spade" };

/// <summary>

/// Names of individual cards, in the order of the cards

/// in a suit

/// </summary>

static private string[] valueNames =

new string[] {"Ace", "Deuce","Three","Four","Five","Six",

"Seven","Eight","Nine","Ten", "Jack","Queen","King" };

/// <summary>

/// Returns the value in points of a given card,

/// according to BlackJack rules

/// </summary>

public int BlackJackScore

{

get

{

return scores[(CardNo  1) % 13];

}

}

/// <summary>

/// Returns true if the card is a picture

/// (i.e. jack, queen or king)

/// </summary>

public bool IsPicture

{

get

{

return isPicture[(CardNo  1) % 13];

}

}

/// <summary>

/// Returns text of the suit of this card

/// </summary>

public string Suit

{

get

{

return suitNames[(CardNo  1) / 13];

}

}

/// <summary>

/// Returns the text of the value of this card

/// </summary>

public string ValueName

{

get

{

return valueNames[(CardNo  1) % 13];

}

}

/// <summary>

/// Returns true if this is a red card

/// </summary>

public bool Red

{

get

{

int suit = (CardNo  1) / 13;

return ((suit == 1) || (suit == 2));

}

}

/// <summary>

/// Returns true if this is a black card

/// </summary>

public bool Black

{

get

{

return !Red;

}

}

/// <summary>

/// Returns an image which can be used to draw this card

/// </summary>

public Image CardImage

{

get

{

int dispNo = CardNo;

if (!FaceUp)

{

dispNo = 0;

}

if (cardImages[dispNo] == null)

{

cardImages[dispNo] = new Bitmap(

execAssem.GetManifestResourceStream(

@"PocketJack.images." +dispNo + @".gif"));

}

return cardImages[dispNo];

}

}

/// <summary>

/// Constructs a card with a partiuclar number

/// </summary>

/// <param name="cardNo">number of the card

/// in the range 1 to 52</param>

/// <param name="faceUp">true if the card

/// is to be drawn face up</param>

public Card(byte cardNo, bool faceUp)

{

CardNo = cardNo;

FaceUp = faceUp;

}

/// <summary>

/// Constructs a face up card with that number

/// </summary>

/// <param name="cardNo"></param>

public Card(byte cardNo)

: this(cardNo, true)

{

}

/// <summary>

/// String description of the card

/// </summary>

/// <returns>the name and suit of the card</returns>

public override string ToString()

{

return ValueName + " of " +Suit;

}

}

/// <summary>

/// Provides a container for a number of cards.

/// May be used to draw the cards and compute their score.

/// </summary>

public class CardHand : ArrayList

{

/// <summary>

/// Used as a destination of teh draw action

/// </summary>

private static Rectangle drawRect;

/// <summary>

/// Draws the hand on the graphics.

/// </summary>

/// <param name="g">graphics to draw with</param>

/// <param name="startx">left edge of first card</param>

/// <param name="starty">top of first card</param>

/// <param name="gapx">x gap between each card</param>

/// <param name="gapy">y gap between each card</param>

public void DrawHand(Graphics g, int startx, int starty,

int gapx, int gapy)

{

drawRect.X = startx;

drawRect.Y = starty;

foreach (Card card in this)

{

drawRect.Width = card.CardImage.Width;

drawRect.Height = card.CardImage.Height;

g.DrawImage(

card.CardImage,// Image

drawRect,// destination rectange

0,// srcX

0,// srcY

card.CardImage.Width, // srcWidth

card.CardImage.Height,// srcHeight

GraphicsUnit.Pixel,// srcUnit

Card.cardAttributes); // ImageAttributes

drawRect.X += gapx;

drawRect.Y += gapy;

}

}

/// <summary>

/// Computes the score of the hand

/// </summary>

/// <returns>the value of the score</returns>

public int BlackJackScoreHand()

{

int score = 0;

int aces = 0;

foreach (Card card in this)

{

score += card.BlackJackScore;

if (card.BlackJackScore == 11)

{

aces++;

}

}

while ((score > 21) && (aces > 0))

{

score -= 10;

aces;

}

return score;

}

}

/// <summary>

/// Contains a number of card decks

/// which can be dealt one at a time.

/// </summary>

public class CardShoe

{

private int noOfDecks = 1;

private byte[] decks;

private int nextCard;

private bool testShoe = false;

/// <summary>

/// True if the deck is "stacked",

/// i.e. was created from a byte array

/// </summary>

public bool TestShoe

{

get

{

return testShoe;

}

}

private void makeShoe()

{

decks = new byte[noOfDecks * 52];

int cardPos = 0;

for (int i = 0; i < noOfDecks; i++)

{

for (byte j = 1; j < 53; j++)

{

decks[cardPos] = j;

cardPos++;

}

}

nextCard = 0;

}

private void shuffleShoe()

{

if (!testShoe)

{

System.Random rand = new Random();

byte swap;

int p1, p2;

for (int i = 0; i < decks.Length; i++)

{

p1 = rand.Next(decks.Length);

p2 = rand.Next(decks.Length);

swap = decks[p1];

decks[p1] = decks[p2];

decks[p2] = swap;

}

}

nextCard = 0;

}

/// <summary>

/// Gets the next card number from the deck

/// </summary>

/// <returns>The number of the next card</returns>

public byte NextCardNo()

{

if (nextCard == decks.Length)

{

shuffleShoe();

}

return decks[nextCard++];

}

/// <summary>

/// Gets the next card from the deck.

/// </summary>

/// <returns>A new instance of the card</returns>

public Card DealCard()

{

return new Card(NextCardNo());

}

/// <summary>

/// Constructs a shoe containing a number of decks

/// </summary>

/// <param name="noOfDecks"></param>

public CardShoe(int noOfDecks)

{

this.noOfDecks = noOfDecks;

makeShoe();

shuffleShoe();

testShoe = false;

}

/// <summary>

/// Constructs a shoe containing a single deck

/// </summary>

public CardShoe()

: this(1)

{

}



/// <summary>

/// Creates a stacked deck for test purposes.

/// </summary>

/// <param name="stackedDeck">array of bytes</param>

public CardShoe(byte[] stackedDeck)

{

decks = stackedDeck;

testShoe = true;

}

}

}

  Solution Explorer            Add, New Item.   Add New Item   Code File,   Name       *.cs    Add.   (   Solution Explorer)   ,     ,     .

 1.12.   Pot.cs .

using System;

namespace PocketJack

{

/// <summary>

/// Summary description for Betting.

/// </summary>

public class Pot

{

private int betValueChangeValue;

private int betValue;

private int potValue;

private const int INITIAL_POT_VALUE = 500;

private const int INITIAL_BET_CHANGE_VALUE = 5;

public int BetValue

{

get

{

return betValue;

}

}

public int PotValue

{

get

{

return potValue;

}

}

public void ResetPot()

{

betValueChangeValue = INITIAL_BET_CHANGE_VALUE;

betValue = INITIAL_BET_CHANGE_VALUE;

potValue = INITIAL_POT_VALUE;

}

public void CheckPot()

{

if (betValue > potValue)

{

if (System.Windows.Forms.MessageBox.Show(

"Insufficient funds for the bet." +

"Do you want to reload the pot?",

"Bank",

System.Windows.Forms.MessageBoxButtons.YesNo,

System.Windows.Forms.MessageBoxIcon.Question,

System.Windows.Forms.

MessageBoxDefaultButton.Button1) ==

System.Windows.Forms.DialogResult.Yes)

{

ResetPot();

}

else

{

betValue = potValue;

}

}

}

public void DoIncreaseBet()

{

betValue = betValue + betValueChangeValue;

CheckPot();

}

public void DoDecreaseBet()

{

if (betValue >= betValueChangeValue)

{

betValue = betValue  betValueChangeValue;

}

}

public void PlayerWins()

{

// win back 2 * our stake

potValue = potValue + betValue;

//potValue = potValue + betValue; //We commented out.

}

public void HouseWins()

{

CheckPot();

}

public void DoPushBet()

{

// put the betValue back in the potValue

potValue = potValue + betValue;

}

public void DoPlaceBet()

{

potValue = potValue  betValue;

}

public Pot()

{

ResetPot();

}

}

}

     Solution Explorer   ,    .     ,    ,   .

    XML- (XML comment),  XML  Extensible Markup Language    , :

/// <summary>

/// Description of a variable:

/// </summary>

     (start tag):

/// <summary>

   (end tag):

/// </summary>

    :

///  :

/// Description of a variable:

        //     /**/,            XML-  ,          (         ),         ,      ,        . XML-    ,    .

  XML-,        ,  (  )     .

1.20.      

        (   )  Utilities,

  Solution Explorer            Add, New Item.   Add New Item   Code File,   Name       *.cs    Add.   (   Solution Explorer)   ,     ,     .

 1.13.  Utilities.cs.

using System.Drawing;

namespace PocketJack

{

public class Utilities

{

static private SolidBrush messageBrush =

new SolidBrush(Color.Black);

public static void BigText(string message, int x, int y,

Color back, Color fore, Font messageFont, Graphics g)

{

int i;

messageBrush.Color = back;

for (i = 1; i < 3; i++)

{

g.DrawString(message, messageFont, messageBrush,

x  i, y  i);

g.DrawString(message, messageFont, messageBrush,

x  i, y + i);

g.DrawString(message, messageFont, messageBrush,

x + i, y  i);

g.DrawString(message, messageFont, messageBrush,

x + i, y + i);

}

messageBrush.Color = fore;

g.DrawString(message, messageFont, messageBrush, x, y);

}

public Utilities()

{

// TODO: Add constructor logic here

}

}

}

  Utilities.cs              ,        ,     ,        .

   ,      Utilities.cs      (     PocketJack), :

    Utilities.cs     (   PocketJack)  :

namespace PocketJack

   ,

     ,       Utilities.cs,     ( )   PocketJack:

using PocketJack;

1.21.      

     () ,     , ,  ,   Project  Add Windows Form,   Add New Item         Add.   Visual Studio    Form2 (. 1.31)     Solution Explorer   Form2.cs.















. 1.31.   . . 1.32   Multiline  True.

,  ,           TextBox.         ,   Properties (  )   Multiline   True (. 1.32).

        ,      .       -    .          Close,     .

        Form2.  (,  : File, Open, File)  Form2.cs   -  Form2   :

public Form2()

{

InitializeComponent();



          TextBox  .

 1.14.       .

StringBuilder sbl;

sbl = new StringBuilder();

sbl.Append("   :\r\n\r\n\r\n");

sbl.Append("Rules of the game in point:\r\n\r\n\r\n");

sbl.Append("1)    (player)   " +

sbl.Append("1) You are a player and play" +

"     (dealer).\r\n\r\n");

"in private with a dealer.\r\n\r\n");

sbl.Append("2)     ,     " +

sbl.Append("2) Your purpose consists in having in a hand" +

"  ,     21,    21, " +

"a card with points as it is possible closer to 21, " +

"but without exceeding 21," +

" ,   .\r\n\r\n");

"and more, than at dealer.\r\n\r\n");



sbl.Append("3)      , " +

sbl.Append("3) Originally are available for you two cards," +

"      ,     " +

"you see the sum of points of these two cards, " +

"and you can take" +

" ,   Enter " +

"the additional cards, pressing the Enter key" +

"       " +

"or choosing the command "HitMe" in the Menu" +

"   mainMenu1.\r\n\r\n");

"for the control mainMenu1.\r\n\r\n control");

sbl.Append("4)     " +

sbl.Append("4) If total quantity of points" +

"   21, " +

"of your cards exceeds 21," +

"       .\r\n\r\n");

"you took excess cards and lose yours bet.\r\n\r\n");

sbl.Append("5)       , " +

sbl.Append("5) If a dealer scored the same quantity of points," +

"  ,  , " +

"as well as you, win you," +

"     .\r\n\r\n");

"and the account increases in yours advantage.\r\n\r\n");

sbl.Append("6)     :\r\n");

sbl.Append("6) Values of points of each card following:\r\n");

sbl.Append("Ace  A = 1 or 11; " +

" 1-, 2-  3-     11 ; " +

"as the 1st, 2nd or 3rd card  Ace gives 11 points;" +

",  ,      11  " +

"for example, with Jack, Gueen and King, Ace gives 11 points" +

"   10+11=21     PocketJack, " +

"and in the sum 10+11=21 these two cards are called " +

"PocketJack," +

"   ,   21; " +

"who covers the rival's cards, even gathered 21;" +

" 4-       1 ;\r\n");

"as the 4th and subsequent card  Ace gives 1 point; \r\n");

sbl.Append("    2  9 " +

sbl.Append("Digits on cards from 2 to 9" +

"   ;\r\n");

"mean the points of this card; \r\n");

sbl.Append("   10, " +

sbl.Append ("a card with number 10," +

"Jack  J, " +

"Queen  Q, " +

"King  K = on 10 points." +

"\r\n\r\n");

sbl.Append("7)         " +

sbl.Append("7) If the first two cards at player or dealer" +

" 21 ,    " +

"gathered 21 points, they also" +

"  ,   21.\r\n\r\n");

"cover the rival's cards, even gathered 21.\r\n\r\n");

sbl.Append("8)    " +

sbl.Append("8) Dealer hands over cards" +

"   .\r\n\r\n");

"from the only shoe of cards.\r\n\r\n");

sbl.Append("9)     , " +

sbl.Append("9) Dealer will hand over itself cards," +

"   17  .\r\n\r\n");

"will not reach 17 or it is more.\r\n\r\n");

sbl.Append("10)      " +

sbl.Append("10) The first card of a dealer can be given" +

"     .\r\n\r\n");

"the face down and to be nevidimoy.\r\n\r\n");

sbl.Append("11)       , " +

sbl.Append("11) You should or to leave a bet by default," +

"        " +

"or to set your new bet before distribution of cards" +

"(     " +

" (in the latter case use the commands" +

"<BetPlus ->  <BetMinus -> " +

"     mainMenu1).\r\n\r\n");

"in the Menu for the mainMenu1 control).\r\n\r\n");

sbl.Append("12)    " +

sbl.Append("12) Your value of bank" +

"    . " +

"all the time show on the screen." +

"      , " +

"If value of bank becomes below your bet," +

"    .\r\n\r\n");

"to you will suggest to begin the new game.\r\n\r\n");

sbl.Append("13)    ,   " +

sbl.Append ("13) When you gathered cards, you can" +

" ,     . " +

"suspend a game, having chosen in Menu the command Stop." +

"   .\r\n\r\n");

"Dealer will show the card.\r\n\r\n");

sbl.Append("14)  :\r\n");

sbl.Append ("14) Scheme of payment:\r\n");

sbl.Append("    , " +

sbl.Append ("the loser pays the winner by agreement," +

", 1:1;\r\n");

"for example, 1:1; \r\n");

sbl.Append("       .\r\n");

sbl.Append ("The game in a point wishes you all the best.\r\n");

textBox1.Text = sbl.ToString();

,       ,  .

  ,       Form1,    Form1    Form2 (. 1.33).    TextBox  ,     ,   ,    .  . 1.33     ,    4, 5  6      .








. 1.33.   Form2.

,          Form2  ShowDialog    (. 1.34),  ,         Form1 (    ),     Form2.








. 1.34.    Form2  ShowDialog   .

    Form2  Show     :

helpForm.Show();

,  ()  Form1,        Form1 (      ),      Form2 (       ).

1.22.  

       :

Build, Build Selection; Debug, Start Without Debugging.

 , Visual C#   Form1      .

,             (    ),     .      (    )         (  )    .

     Enter      .

 ,       ( )   (      Random),    ,    ""       .

      ,         Black Jack, 21   (pontoon)   52 ,            21   36 .

        52      36  (  )   52    ,    36 .

         .

 

I

I.           




 2.               



2.1.  



          ,         .

,     .     ,    (,    )    1,     2 (   )      2 (   ).      .       2-  ,          .        1,            2    2.        , ,         ,       (lives)     ,             .

    Singleplayer ( 1  ),   ,  1        ,            ,       (    )  1   .  ,  1   ( )     ,      .      .

    Multiplayer ( 1   2),  1   ,    ,    2    W  S   ,            ,       (    )  2   .

    GetInputStates  :

if (gamePadUp ||

keyboard.IsKeyDown(Keys.Up))

rightPaddlePosition -= moveFactorPerSecond;

if (gamePadDown ||

keyboard.IsKeyDown(Keys.Down))

 ,   1         Up  Down.

  GetInputStates  :



if (gamePad2Up ||

keyboard.IsKeyDown(Keys.W))

leftPaddlePosition -= moveFactorPerSecond;

if (gamePad2Down ||

keyboard.IsKeyDown(Keys.S) ||

keyboard.IsKeyDown(Keys.O))

leftPaddlePosition += moveFactorPerSecond;

 ,   2       W, S  O.

      ,          ,       .

 ,       .   ,       .




2.2.  


1.  ,       Singleplayer, Multiplayer  Exit (. 2.1).          Enter.

2.   ,      (Blue)   1,     (Red)      2 (    Singleplayer)   2 (    Multiplayer).

          Lives         (. 2.2).

      4-  ,       .            .        1,         2 (     2).








. 2.1.    Singleplayer  Multiplayer.








. 2.2.     1,     2,      .

3. ,          Singleplayer ( 1  )    Enter.  1      Up  Down   ,            ,       (    )  1   .      .

4. ,          Multiplayer ( 1   2)    Enter.  1   ,    ,    2    W  S   ,            ,       (    )  2   .

5.  ,       .

6.   ,        ( . 2.3    2    Red).    Red Won.  ,  (   2) .

4.      ,    ,        .

5.     ,     Close.

       .

            (       ).








. 2.3.   .

2.3.   Visual Studio 



 VS   New Project ( File, New, Project),   New Project   Project types    Visual C#, XNA Game Studio   Templates   Windows Game,   Name   Pong2   OK. VS      Game1.cs     .

  Solution Explorer       Content,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,  )     Shift  Ctrl      PongGame.png, PongMenu.png  SpaceBackground.dds,    Add.      Solution Explorer,    . 2.4 ( PongSound.xap     ,      XACT).    Solution Explorer   SpaceBackground.dds,     Properties      (. 2.5).

     ,   Open File (    File, Open, File),    Open File   "Look in:"  (,  )     (  , PongBallHit.wav  PongBallLost.wav),    Shift  Ctrl     ,             (Copy)       .















. 2.4.  Solution Explorer. . 2.5.  Properties.

     Open File   "Look in:"    Visual Studio     Content,                (Paste)       .       Content    Open File,      Solution Explorer     Content      .

 ,      PongBallHit.wav  ,       .   PongBallLost.wav  ,    ,        ,     .

      (Build, Build Solution)   (Debug, Start Without Debugging)     ,    .      ,       XACT     (.xap),     .    Visual Studio.




2.4.    XACT


       XACT     Audio Project  (.xap).

1.   XACT,   Start (), All Programs ( ),| Microsoft XNA Game Studio Tools, Microsoft Cross-Platform Audio Creation Tool (XACT).     Microsoft Cross-Platform Audio Creation Tool (XACT) v.2.0 (Windows).

2.   File  New Project.   New Project Path.      ":"    Visual Studio  Content,   " :"   , , PongSound     (Save), . 2.6. ,        " :"    All Files,           .















. 2.6.   VS   Content  . . 2.7.  .

  Microsoft Cross-Platform Audio Creation Tool (XACT) v.2.0 (Windows)   New Project     .

3.   Wave Banks   New Wave Bank.   XACT      Wave Bank.

  Sound Banks   New Sound Bank.   XACT      Sound Bank.

    Wave Bank  Sound Bank    XACT ,   .       ,      XACT     Wave Bank  Sound Bank.

4.        Wave Bank       Insert Wave File(s).

    (Open) ,    ":"   Content (     ,   ),       (. 2.7)    .   ,       Wave Bank (   ).

        Wave Bank,      Insert Wave File(s),       Lost.wav    .      Wave Bank.

    " :" ,      XNA,  : Sound Files (*.wav, *.aif, *.aiff).

5.   Wave Bank         ,          Sound Bank, ,       Cue Name.         Sound Bank. ٸ  ,        .








. 2.8.  Microsoft Cross-Platform Audio Creation Tool (XACT) v.2.0 (Windows).




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=68908707)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


