Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 3: Программирование на Visual C# искусственного интеллекта (продолжение 2). Валерий Алексеевич Жарков
Чтение книги онлайн.

Читать онлайн книгу Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 3: Программирование на Visual C# искусственного интеллекта (продолжение 2) - Валерий Алексеевич Жарков страница 20

СКАЧАТЬ <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;

      }

      }

      /// СКАЧАТЬ