///
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;
}
///
/// Gets the next card number from the deck
///
/// The number of the next card
public byte NextCardNo()
{
if (nextCard == decks.Length)
{
shuffleShoe();
}
return decks[nextCard++];
}
///
/// Gets the next card from the deck.
///
/// A new instance of the card
public Card DealCard()
{
return new Card(NextCardNo());
}
///
/// Constructs a shoe containing a number of decks
///
///
public CardShoe(int noOfDecks)
{
this.noOfDecks = noOfDecks;
makeShoe();
shuffleShoe();
testShoe = false;
}
///
/// Constructs a shoe containing a single deck
///
public CardShoe()
: this(1)
{
}
///
/// Creates a stacked deck for test purposes.
///
/// array of bytes
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 description for Betting.
///
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;