     .  3:  Visual C#   (2)
  


                ()  -     ,   ,        ,   , , ,   Xbox.        ,     ,    ,    .





     

 3:  Visual C#   (2)



  



  ,2022



ISBN978-5-0059-1084-4 (. 3)

ISBN978-5-0056-6546-1

     Ridero








                        ,     ,       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: valery-zharkov@mtu-net.ru  : www.ZharkovPress.ru.



:       (. ).



 I.      



 1.         21




1.1.  


            ⠫  ⠫21,    microsoft.com: Rob Miles. Pocket Jack: Writing aCard-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.    蠖  (AceA).








. 1.4.     .



   13 14, 15, 16, , 26   diamond 13 27, 28, 29, , 39  蠖 heart. Ƞ   蠖  (AceA).

  13 40, 41, 42, , 52   蠖 spade.








. 1.5.     .



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



  10card 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 inthis)
		{
		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 inthis)
		{
		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)      114 , ,   , .   1125  ()    ,  ,     ()    .    (player),  (banker)  ,   ()   ,   .




1.8.  


  ,   (Clear)   (players hand)      :



CardHand playerHand = new CardHand();

		playerHand.Clear();
		dealerHand.Clear();
		// deal the face down holecard
		dealerHoleCard = shoe.DealCard();
		dealerHoleCard. FaceUp = false;
		dealerHand.Add (dealerHoleCard);
		// deal the first playercard
		playerHand.Add(shoe.DealCard());
		// deal the second dealer card (faceup)
		dealerHand.Add(shoe.DealCard());
		// deal the second playercard

playerHand.Add(shoe.DealCard());
  ,  ,        .       .

    Hit Me  maneMenu1.    ,     ,       21,    :

		void playerHits()
		{
		if (playerHand. BlackJackScoreHand ()<21)
		{
		playerHand.Add(shoe.DealCard());
		if (playerHand. BlackJackScoreHand ()>21)
		{
		//We write inthe 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, inty,
		Color back, Color fore,
		Font messageFont, Graphicsg)
		{
		inti;
		messageBrush.Color = back;
		for (i= 1; i<3;i++)
		{
		g. DrawString (message, messageFont, messageBrush,
		x i, yi);
		g. DrawString (message, messageFont, messageBrush,
		x i, y +i);
		g. DrawString (message, messageFont, messageBrush,
		x + i, yi);
		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, PaintEventArgse)

{

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 apush).

       ,    . ,       ,      .         (mode)   enum  :

		public enum GameMode
		{
		LoadingDisplay,
		PlacingBets,
		PlayerActive,
		PlayerWon,
		PlayerBust,
		PocketJack,
		DealerActive,
		DealerWon,
		DealerBust,
		Push

}



  GameMode   .     .    ,    .       ,       :

		GameMode modeValue;
		GameModemode
		{
		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 (Graphicsg)
		{
		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 holecard
		dealerHoleCard = shoe.DealCard();
		dealerHoleCard. FaceUp = false;
		dealerHand.Add (dealerHoleCard);
		// deal the first playercard
		playerHand.Add(shoe.DealCard());
		// deal the second dealer card (faceup)
		dealerHand.Add(shoe.DealCard());
		// deal the second playercard
		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 inthe 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.   


            (aloading 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 (Graphicsg)
		{
		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 acard toyourself (    ).

  ( ),        ,     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 acard toyourself (    ),   .

,    Enter   . , ,    ,          (. 1.18).

     pj_busted.wav.

       , , 505500   : : 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).

   蠖  (AceA).

    :

 (Ace A) = 111;

 1-, 2-  3- ࠖ   11;

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

 4-  ࠖ   1;

  29   ;

  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 oftype  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 oftype  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 ofcards:
		CardShoe shoe;
		CardHand playerHand = new CardHand();
		Card dealerHoleCard;
		CardHand dealerHand = new CardHand();
		//Bank ofagame:
		Potpot;
		//We declare an object for ahelp form:
		Form2 helpForm;
		Image loadingImage = null;
		Image bankImage = null;
		public enum GameMode
		{
		LoadingDisplay,
		PlacingBets,
		PlayerActive,
		PlayerWon,
		PlayerBust,
		PocketJack,
		DealerActive,
		DealerWon,
		DealerBust,
		Push
		}
		GameMode modeValue;
		GameModemode
		{
		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 acard toyourself;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//Disturbing noise ofthe 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 ofcards;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//An applause inour address for aprize incards:
		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 ofcards;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//Discontent ofsupport group with our exceedingof
		//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 ofcards;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//Avictorious tune after Pocket Jack with 21points:
		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 ofcards;
		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 ofcards;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//Discontent ofsupport group with our exceedingof
		//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 ofcards;
		StayToolStripMenuItem. Enabled = true;
		MenuToolStripMenuItem. Text = Menu;
		MenuToolStripMenuItem. Enabled = true;
		//An applause inour address for aprize incards:
		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 ofcards;
		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 inthe original,
		//since this line only for testing ofagame:
		//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 inthe original:
		//pot.DoPlaceBet();
		//We write inthe original:
		if (mode == GameMode.PlayerBust && mode == GameMode.DealerWon)
		pot.DoPlaceBet();
		showPot();
		// clear the hands
		playerHand.Clear();
		dealerHand.Clear();
		// deal the face down holecard
		dealerHoleCard = shoe.DealCard();
		dealerHoleCard. FaceUp = false;
		dealerHand.Add (dealerHoleCard);
		// deal the first playercard
		playerHand.Add(shoe.DealCard());
		// deal the second dealer card (faceup)
		dealerHand.Add(shoe.DealCard());
		// deal the second playercard
		playerHand.Add(shoe.DealCard());
		if ((dealerHand. BlackJackScoreHand () == 21)&&
		(playerHand. BlackJackScoreHand ()!=21))
		{
		//We write inthe original:
		pot.DoPlaceBet();
		pot. HouseWins();
		showPot();
		//Discontent ofsupport group with our exceedingof
		//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 (Graphicsg)
		{
		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 inthe 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 inthe 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, EventArgse)
		{
		//We load the game objects:
		init();
		startGame();

}



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



 1.3.    .



private void Form1_Paint (object sender, PaintEventArgse)

{

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, EventArgse)

{

doLeftMenuKey();

}

    Exit.         .



 1.5.    .



private void ExitToolStripMenuItem_Click (object sender, EventArgse)

{

Application. Exit();

}



    Hit Me.         .



 1.6.     .



private void HitMeToolStripMenuItem_Click (object sender, EventArgse)

{

playerHits();

}



    BetPlus.         .



 1.7.    .



private void BetPlusToolStripMenuItem_Click (object sender, EventArgse)

{

doUp();

}



     - (Bet -).         .



 1.8.    .



private void BetMinusToolStripMenuItem1_Click (object sender, EventArgse)

{

doDown();

}



           (Sound)   .   ,   .

    Help.         .



 1.9.     .



private void HelpToolStripMenuItem_Click (object sender, EventArgse)

{

showHelp();

}



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



 1.10.     .



private void Form1_KeyDown (object sender, KeyEventArgse)

{

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 tomanage and draw cards
		/// </summary>
		public classCard
		{
		/// <summary>
		/// The number ofthe card, inthe range 1to52
		/// </summary>
		public byte CardNo;
		/// <summary>
		/// Indicates if the card is tobe drawn faceup.
		/// True bydefault.
		/// </summary>
		public bool FaceUp = true;
		/// <summary>
		/// The images ofthe cards. Stored for all the cards.
		/// The image with number 0isthe
		/// back pattern ofthecard
		/// </summary>
		static private Image [] cardImages = new Bitmap [53];
		/// <summary>
		/// The attribute tobe used when drawing thecard
		/// toimplement transpancy
		/// </summary>
		static public System.Drawing.Imaging.ImageAttributes
		cardAttributes;
		/// <summary>
		/// Used when loading card images prior todrawing
		/// </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 ofthe cards inasuit
		/// </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 inasuit
		/// </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 ofthe suits, inthe order that ofthe suits
		/// inthe number sequence
		/// </summary>
		static private string [] suitNames=
		new string [] {club, diamond, heart, spade};
		/// <summary>
		/// Names ofindividual cards, inthe order ofthe cards
		/// inasuit
		/// </summary>
		static private string [] valueNames=
		new string [] {Ace, Deuce, Three, Four, Five, Six,
		Seven, Eight, Nine, Ten, Jack, Queen, King};
		/// <summary>
		/// Returns the value inpoints ofagiven card,
		/// according toBlackJack rules
		/// </summary>
		public int BlackJackScore
		{
		get
		{
		return scores [(CardNo 1) %13];
		}
		}
		/// <summary>
		/// Returns true if the card is apicture
		/// (i.e. jack, queen or king)
		/// </summary>
		public bool IsPicture
		{
		get
		{
		return isPicture [(CardNo 1) %13];
		}
		}
		/// <summary>
		/// Returns text ofthe suit ofthiscard
		/// </summary>
		public stringSuit
		{
		get
		{
		return suitNames [(CardNo 1) /13];
		}
		}
		/// <summary>
		/// Returns the text ofthe value ofthiscard
		/// </summary>
		public string ValueName
		{
		get
		{
		return valueNames [(CardNo 1) %13];
		}
		}
		/// <summary>
		/// Returns true if this is aredcard
		/// </summary>
		public boolRed
		{
		get
		{
		int suit = (CardNo 1) /13;
		return ((suit == 1) || (suit ==2));
		}
		}
		/// <summary>
		/// Returns true if this is ablackcard
		/// </summary>
		public bool Black
		{
		get
		{
		return!Red;
		}
		}
		/// <summary>
		/// Returns an image which can be used todraw thiscard
		/// </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 acard with apartiuclar number
		/// </summary>
		/// <param name=cardNo> number ofthecard
		/// inthe range 1to52</param>
		/// <param name=faceUp> true if thecard
		/// is tobe drawn face up </param>
		public Card (byte cardNo, bool faceUp)
		{
		CardNo = cardNo;
		FaceUp = faceUp;
		}
		/// <summary>
		/// Constructs aface up card with that number
		/// </summary>
		/// <param name=cardNo> </param>
		public Card (byte cardNo)
		: this (cardNo, true)
		{
		}
		/// <summary>
		/// String description ofthecard
		/// </summary>
		/// <returns> the name and suit ofthe card </returns>
		public override string ToString()
		{
		return ValueName + " of" +Suit;
		}
		}
		/// <summary>
		/// Provides acontainer for anumber ofcards.
		/// May be used todraw the cards and compute their score.
		/// </summary>
		public class CardHand: ArrayList
		{
		/// <summary>
		/// Used as adestination ofteh draw action
		/// </summary>
		private static Rectangle drawRect;
		/// <summary>
		/// Draws the hand on the graphics.
		/// </summary>
		/// <param name=g> graphics todraw with </param>
		/// <param name=startx> left edge offirst card </param>
		/// <param name=starty> top offirst card </param>
		/// <param name=gapx> xgap between each card </param>
		/// <param name=gapy> ygap 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 inthis)
		{
		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 ofthehand
		/// </summary>
		/// <returns> the value ofthe score </returns>
		public int BlackJackScoreHand()
		{
		int score =0;
		int aces =0;
		foreach (Card card inthis)
		{
		score += card. BlackJackScore;
		if (card. BlackJackScore ==11)
		{
		aces++;
		}
		}
		while ((score> 21) && (aces>0))
		{
		score -=10;
		aces;
		}
		return score;
		}
		}
		/// <summary>
		/// Contains anumber ofcard decks
		/// which can be dealt one at atime.
		/// </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 abyte 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 thedeck
		/// </summary>
		/// <returns> The number ofthe next card </returns>
		public byte NextCardNo()
		{
		if (nextCard == decks. Length)
		{
		shuffleShoe();
		}
		return decks [nextCard++];
		}
		/// <summary>
		/// Gets the next card from the deck.
		/// </summary>
		/// <returns> Anew instance ofthe card </returns>
		public Card DealCard()
		{
		return new Card (NextCardNo());
		}
		/// <summary>
		/// Constructs ashoe containing anumber ofdecks
		/// </summary>
		/// <param name=noOfDecks> </param>
		public CardShoe (int noOfDecks)
		{
		this.noOfDecks = noOfDecks;
		makeShoe();
		shuffleShoe();
		testShoe = false;
		}
		/// <summary>
		/// Constructs ashoe containing asingledeck
		/// </summary>
		public CardShoe()
		: this(1)
		{
		}

		/// <summary>
		/// Creates astacked deck for test purposes.
		/// </summary>
		/// <param name=stackedDeck> array ofbytes </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 classPot
		{
		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 toreload 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 commentedout.
		}
		public void HouseWins()
		{
		CheckPot();
		}
		public void DoPushBet()
		{
		// put the betValue back inthe potValue
		potValue = potValue + betValue;
		}
		public void DoPlaceBet()
		{
		potValue = potValue betValue;
		}
		public Pot()
		{
		ResetPot();

}

}

}



    Solution Explorer   ,   .    ,    ,  .

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

/// <summary>

/// Description ofavariable:

/// </summary>

    (start tag):

/// <summary>

  (end tag):

/// </summary>

    :

///  :

/// Description ofavariable:



       //     /**/,         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, inty,
		Color back, Color fore, Font messageFont, Graphicsg)
		{
		inti;
		messageBrush.Color = back;
		for (i= 1; i<3;i++)
		{
		g. DrawString (message, messageFont, messageBrush,
		x i, yi);
		g. DrawString (message, messageFont, messageBrush,
		x i, y +i);
		g. DrawString (message, messageFont, messageBrush,
		x + i, yi);
		g. DrawString (message, messageFont, messageBrush,
		x + i, y +i);
		}
		messageBrush.Color = fore;
		g. DrawString (message, messageFont, messageBrush, x,y);
		}
		public Utilities()
		{
		// TODO: Add constructor logichere

}

}

}



  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.      .



StringBuildersbl;

sbl = new StringBuilder();

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

sbl. Append (Rules ofthe game inpoint: \r\n\r\n\r\n);

sbl. Append (1)    (player)  "+

sbl. Append (1) You are aplayer and play+

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

inprivate with adealer.\r\n\r\n);

sbl. Append (2)    ,    "+

sbl. Append (2) Your purpose consists inhaving inahand+

 ,    21,  21, "+

acard with points as it is possible closer to21, "+

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 ofpoints ofthese two cards, "+

and you can take+

 ,   Enter "+

the additional cards, pressing the Enter key+

      "+

or choosing the command HitMe inthe Menu+

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

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

sbl. Append (4)     "+

sbl. Append (4) If total quantity ofpoints+

   21, "+

ofyour 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 adealer scored the same quantity ofpoints,+

 ,  , "+

as well as you, win you,+

   .\r\n\r\n);

and the account increases inyours advantage.\r\n\r\n);

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

sbl. Append (6) Values ofpoints ofeach card following:\r\n);

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

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

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

, ,     11 "+

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

 10+11=21    PocketJack, "+

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

PocketJack,+

   ,   21; "+

who covers the rivals cards, even gathered 21;"+

 4-  ࠖ   1;\r\n);

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

sbl. Append (  29"+

sbl. Append (Digits on cards from 2to9+

   ;\r\n);

mean the points ofthis card; \r\n);

sbl. Append (  10, "+

sbl. Append (acard with number 10,+

Jack J, "+

Queen Q, "+

King K = on 10points.+

\r\n\r\n);

sbl. Append (7)        "+

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

 21,    "+

gathered 21points, they also+

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

cover the rivals 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 ofcards.\r\n\r\n);

sbl. Append (9)     , "+

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

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

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

sbl. Append (10)      "+

sbl. Append (10) The first card ofadealer can be given+

    .\r\n\r\n);

the face down and tobe nevidimoy.\r\n\r\n);

sbl. Append (11)      , "+

sbl. Append (11) You should or toleave abet bydefault,+

       "+

or toset your new bet before distribution ofcards+

(    "+

(inthe latter case use the commands+

<BetPlus -> <BetMinus -> "+

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

inthe Menu for the mainMenu1 control).\r\n\r\n);

sbl. Append (12)    "+

sbl. Append (12) Your value ofbank+

   . "+

all the time show on the screen.+

      , "+

If value ofbank becomes below your bet,+

    .\r\n\r\n);

toyou will suggest tobegin the new game.\r\n\r\n);

sbl. Append (13)    ,   "+

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

 ,    . "+

suspend agame, having chosen inMenu 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 ofpayment:\r\n);

sbl. Append (   , "+

sbl. Append (the loser pays the winner byagreement,+

, 1:1;\r\n);

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

sbl. Append (     .\r\n);

sbl. Append (The game inapoint wishes you all the best.\r\n);

textBox1.Text = sbl.ToString();



,      ,  .

  ,      Form1,    Form1    Form2 (. 1.33).    TextBox  ,     ,   ,    . . 1.33    ,   4, 56    .








. 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.

        .



 II.        



 2.            




2.1.  


        ,      .

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

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

   Multiplayer ( 1 2),  1 ,   ,   2   WS   ,          ,       (   )  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   WS   ,          ,       (   )  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 oftype  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).

6.   View  ,      View Windows Property ( ,   ).

7.     XACT (File, Save Project), .2.8.

8.    XACT,   Close ( File, Exit).

9.  (   )   Visual Studio  Content ( File, Open, File).  ,                Win Xbox , ,      XACT       (.xap).   (.xap)        Audio Project ( ).

,     (.xap)    Content  Open File,    Content    Solution Explorer.

10.   ,    .   Solution Explorer      Content,    Add, Existing Item,  Add Existing Item  Files oftype  All Files,  Look in:"   Content   Visual Studio,       (.xap),   Add (    ).   Solution Explorer  Audio      (.xap).

,   Visual Studio  Content  Open File (   File, Open, File)    ,  . 2.9.  Content   Solution Explorer    ,    .



. 2.9.  Open File.








     XACT     (File, Save Project),   (  )   XACT.    XACT     : File, Open Project,         (.xap)    (     ).      XACT   Wave Bank     ,      Sound Bank     .          .      , ,        .




  .


   .

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

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


