Esempio n. 1
0
        public void FaceCardQueenCanBeCreated()
        {
            //Act
            int            value        = 10;
            ECardSuitTypes cardSuitType = ECardSuitTypes.Clubs;
            ECardType      cardType     = ECardType.Queen;
            Card           testCard;

            //Arrange
            testCard = new FaceCard(cardSuitType, cardType);

            //Assert
            if (testCard.Value != value)
            {
                string errorMessage = $"Card is created with the wrong value. Expected card value is {value}. Actual card value is {testCard.Value}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardSuit != cardSuitType)
            {
                string errorMessage = $"Card is created with the wrong card suit type. Expected card suit type is {cardSuitType}. Actual card suit type is {testCard.CardSuit}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardType != cardType)
            {
                string errorMessage = $"Card is created with the wrong card type. Expected card type is {cardType}. Actual card suit type is {testCard.CardType}";
                Assert.Fail(errorMessage);
            }
        }
Esempio n. 2
0
        public void NumericalCardCanBeCreated()
        {
            //Act
            int            value        = 7;
            ECardSuitTypes cardSuitType = ECardSuitTypes.Spades;
            ECardType      cardType     = ECardType.Numerical;
            Card           testCard;

            //Arrange
            testCard = new Card(value, cardSuitType, cardType);

            //Assert
            if (testCard.Value != value)
            {
                string errorMessage = $"Card is created with the wrong value. Expected card value is {value}. Actual card value is {testCard.Value}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardSuit != cardSuitType)
            {
                string errorMessage = $"Card is created with the wrong card suit type. Expected card suit type is {cardSuitType}. Actual card suit type is {testCard.CardSuit}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardType != cardType)
            {
                string errorMessage = $"Card is created with the wrong card type. Expected card type is {cardType}. Actual card suit type is {testCard.CardType}";
                Assert.Fail(errorMessage);
            }
        }
Esempio n. 3
0
 public bool CanChow(ECardType card)
 {
     if (this.IsTiao(card) || this.IsTong(card) || this.IsWan(card))
     {
         if (card == ECardType.OneTiao || card == ECardType.OneTong || card == ECardType.OneWan)
         {
             return(this.m_CardArray[(int)card + 1] > 0 && this.m_CardArray[(int)card + 2] > 0);
         }
         if (card == ECardType.TwoTiao || card == ECardType.TwoTong || card == ECardType.TwoWan)
         {
             return(this.m_CardArray[(int)card + 1] > 0 &&
                    (this.m_CardArray[(int)card - 1] > 0 || this.m_CardArray[(int)card + 2] > 0));
         }
         if (card == ECardType.NineTiao || card == ECardType.NineTong || card == ECardType.NineWan)
         {
             return(this.m_CardArray[(int)card - 1] > 0 && this.m_CardArray[(int)card - 2] > 0);
         }
         if (card == ECardType.EightTiao || card == ECardType.EightTong || card == ECardType.EightWan)
         {
             return(this.m_CardArray[(int)card - 1] > 0 &&
                    (this.m_CardArray[(int)card - 2] > 0 || this.m_CardArray[(int)card + 1] > 0));
         }
         return(this.m_CardArray[(int)card - 1] > 0 && this.m_CardArray[(int)card + 1] > 0 ||
                this.m_CardArray[(int)card - 1] > 0 && this.m_CardArray[(int)card - 2] > 0 ||
                this.m_CardArray[(int)card + 1] > 0 && this.m_CardArray[(int)card + 2] > 0);
     }
     return(false);
 }
Esempio n. 4
0
        public void FaceCardWithModifiedValueCanBeCreated()
        {
            //Act
            int            value        = 5;
            ECardSuitTypes cardSuitType = ECardSuitTypes.Diamonds;
            ECardType      cardType     = ECardType.King;
            Card           testCard;

            //Arrange
            testCard = new Card(value, cardSuitType, cardType);

            //Assert
            if (testCard.Value != value)
            {
                string errorMessage = $"Card is created with the wrong value. Expected card value is {value}. Actual card value is {testCard.Value}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardSuit != cardSuitType)
            {
                string errorMessage = $"Card is created with the wrong card suit type. Expected card suit type is {cardSuitType}. Actual card suit type is {testCard.CardSuit}";
                Assert.Fail(errorMessage);
            }

            if (testCard.CardType != cardType)
            {
                string errorMessage = $"Card is created with the wrong card type. Expected card type is {cardType}. Actual card suit type is {testCard.CardType}";
                Assert.Fail(errorMessage);
            }
        }
Esempio n. 5
0
    private void IsAllMelds(int[] cards, int[,] result, int index, ECardType pair, ref List <WinSeq> results)
    {
        if (index >= 4)
        {
            WinSeq seq = new WinSeq
            {
                Pair = new[] { (int)pair, (int)pair },
                Seq  = result
            };
            results.Add(seq);
            return;
        }

        for (int i = 0; i < cards.Length; ++i)
        {
            if (cards[i] > 0 && cards[i] <= 4)
            {
                if (cards[i] == 3)
                {
                    int[] copy = new int[cards.Length];
                    cards.CopyTo(copy, 0);
                    copy[i]           = copy[i] - 3;
                    int[,] resultCopy = new int[4, 3];
                    Array.Copy(result, resultCopy, result.Length);

                    resultCopy[index, 0] = i;
                    resultCopy[index, 1] = i;
                    resultCopy[index, 2] = i;
                    this.IsAllMelds(copy, resultCopy, index + 1, pair, ref results);
                }
                if (this.IsTiao((ECardType)i) || this.IsTong((ECardType)i) || this.IsWan((ECardType)i))
                {
                    if (i < cards.Length - 2 && cards[i + 1] > 0 && cards[i + 2] > 0)
                    {
                        if (this.IsMeld((ECardType)i, (ECardType)(i + 1), (ECardType)(i + 2)))
                        {
                            int[] copy = new int[cards.Length];
                            cards.CopyTo(copy, 0);

                            copy[i]     = copy[i] - 1;
                            copy[i + 1] = copy[i + 1] - 1;
                            copy[i + 2] = copy[i + 2] - 1;

                            int[,] resultCopy = new int[4, 3];
                            Array.Copy(result, resultCopy, result.Length);

                            resultCopy[index, 0] = i;
                            resultCopy[index, 1] = i + 1;
                            resultCopy[index, 2] = i + 2;
                            this.IsAllMelds(copy, resultCopy, index + 1, pair, ref results);
                        }
                    }
                }
                return;
            }
        }
    }
Esempio n. 6
0
 /// <summary>
 /// basic ctor, creates a new card
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="type"></param>
 /// <param name="str"></param>
 /// <param name="def"></param>
 /// <param name="race"></param>
 /// <param name="eleType"></param>
 /// <param name="eleLv"></param>
 /// <param name="cost"></param>
 public Card(int id, string name, ECardType type, short str, short def, ECardRace race, ECardElementType eleType, int eleLv, short cost)
 {
     ID       = id;
     Name     = name;
     Type     = type;
     Strength = StrengthCurrent = str;
     Defence  = DefenceCurrent = def;
     Race     = race;
     Element  = new CardElement(eleType, eleLv);
     Cost     = cost;
 }
Esempio n. 7
0
        public FaceCard(ECardSuitTypes cardSuitType, ECardType cardType) : base(10, cardSuitType, cardType)
        {
            if (cardType != ECardType.Jack && cardType != ECardType.Queen && cardType != ECardType.King)
            {
                throw new ArgumentException($@"Card type for face card must be either: 1) {ECardType.Jack} 2) {ECardType.Queen} 3) {ECardType.King}", nameof(cardType));
            }

            CardDeckConfiguration config = new CardDeckConfigurationProvider().GetRules();

            _value = config.FaceCardValue;
        }
Esempio n. 8
0
    static public CardData Create(ECardType type, int val)
    {
        CardData card = null;

        if (IsValidCardVal(val))
        {
            card = new CardData(type, val);
        }

        return(card);
    }
Esempio n. 9
0
    public void DiscardCard(GamePlayer player, ECardType card)
    {
        //Check if anyone win
        bool anyoneWin = false;

        for (int i = 1; i < 4; ++i)
        {
            ESeat seat = (ESeat)(((int)player.Seat + i) % 4);
            if (this.m_PlayerDict[seat].CanWin(card))
            {
                anyoneWin = true;
                Debug.LogError("Player Id " + this.m_PlayerDict[seat].PlayerId + " Win !");
            }
        }
        if (anyoneWin)
        {
            return;
        }

        //Check if anyone kong/pong
        bool anyonePong = false;

        for (int i = 1; i < 4; ++i)
        {
            ESeat seat = (ESeat)(((int)player.Seat + i) % 4);
            if (this.m_PlayerDict[seat].CanKong(card) || this.m_PlayerDict[seat].CanPong(card))
            {
                anyonePong = true;
            }
        }
        if (anyonePong)
        {
            return;
        }

        //Check if anyone chow
        bool anyoneChow = false;

        for (int i = 1; i < 4; ++i)
        {
            ESeat seat = (ESeat)(((int)player.Seat + i) % 4);
            if (this.m_PlayerDict[seat].CanChow(card))
            {
                anyoneChow = true;
            }
        }
        if (anyoneChow)
        {
            return;
        }
        //todo: something
    }
Esempio n. 10
0
    public void DiscardCard(ECardType card)
    {
        int currentCount = this.m_CardArray[(int)card];

        if (currentCount <= 0)
        {
            Debug.LogError("Min is 0 !");
        }
        else
        {
            this.m_CardArray[(int)card] = currentCount - 1;
            this.CheckTing();
        }
    }
Esempio n. 11
0
        private string GetCardType(ECardType Type)
        {
            string strType = Type.ToString();

            for (int i = 1; i < strType.Length; i++)
            {
                if (strType[i] >= 'A' && strType[i] <= 'Z')
                {
                    string prefix = strType.Substring(0, i);
                    string sufix  = strType.Substring(i);
                    return(prefix + ": " + sufix);
                }
            }
            return(strType);
        }
Esempio n. 12
0
 public CardTemplate(ECardType type, EPieceType pieceType, string name, int manaCost, int attack,
                     int health, IEnumerable <EAbility> abilities = null,
                     string flavourText = "")
     : base(null)
 {
     Type      = type;
     PieceType = pieceType;
     Id        = Guid.NewGuid();
     Name      = name;
     ManaCost  = manaCost;
     Power     = attack;
     Health    = health;
     if (abilities != null)
     {
         Abilities = abilities.ToList();
     }
     FlavourText = flavourText;
 }
Esempio n. 13
0
 private bool IsMeld(ECardType card1, ECardType card2, ECardType card3)
 {
     if (card1 == card2 && card2 == card3)
     {
         return(true);
     }
     if (this.IsTiao(card1) && this.IsTiao(card2) && this.IsTiao(card3) ||
         this.IsTong(card1) && this.IsTong(card2) && this.IsTong(card3) ||
         this.IsWan(card1) && this.IsWan(card2) && this.IsWan(card3))
     {
         ECardType[] cards = { card1, card2, card3 };
         Array.Sort(cards);
         if (card2 - card1 == 1 && card3 - card2 == 1)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 14
0
 public void DrawCard(ECardType card)
 {
     if (this.CanWin(card))
     {
         Debug.LogError("Player Id : " + this.PlayerId + " Win !");
     }
     else
     {
         int currentCount = this.m_CardArray[(int)card];
         if (currentCount >= 4)
         {
             Debug.LogError("Max is 4 !");
         }
         else
         {
             this.m_CardArray[(int)card] = currentCount + 1;
         }
     }
 }
Esempio n. 15
0
    CardData(ECardType type, int val)
    {
        _type = type;
        _val  = val;

        int offset = 0;

        if (type == ECardType.HEART)
        {
            offset = 13;
        }
        else if (type == ECardType.CLUB)
        {
            offset = 26;
        }
        else if (type == ECardType.DIAMOND)
        {
            offset = 39;
        }

        _id = offset + val;
    }
Esempio n. 16
0
 public Card(int time, int playerNumber, ECardType cardType)
 {
     Time         = time;
     PlayerNumber = playerNumber;
     CardType     = cardType;
 }
Esempio n. 17
0
 public bool CanWin(ECardType card)
 {
     return(this.IsTing && this.m_TingDict.ContainsKey(card));
 }
Esempio n. 18
0
 public bool CanPong(ECardType card)
 {
     return(this.m_CardArray[(int)card] >= 2);
 }
Esempio n. 19
0
 public ValueChangedEventargs()
 {
     cardType = ECardType.None;
     IsValid  = false;
 }
Esempio n. 20
0
		private string GetCardType(ECardType Type) {
			string strType = Type.ToString();
			for (int i = 1; i < strType.Length; i++) {
				if (strType[i] >= 'A' && strType[i] <= 'Z') {
					string prefix = strType.Substring(0, i);
					string sufix = strType.Substring(i);
					return prefix + ": " + sufix;
				}
			}
			return strType;
		}
Esempio n. 21
0
 public Card(int value, ECardSuitTypes cardSuitType, ECardType cardType)
 {
     _value        = value;
     _cardSuitType = cardSuitType;
     _cardType     = cardType;
 }
Esempio n. 22
0
 public bool CanKong(ECardType card)
 {
     return(this.m_CardArray[(int)card] == 3);
 }
Esempio n. 23
0
 private bool IsTong(ECardType card)
 {
     return(card >= ECardType.OneTong && card <= ECardType.NineTong);
 }
Esempio n. 24
0
 private bool IsTiao(ECardType card)
 {
     return(card >= ECardType.OneTiao && card <= ECardType.NineTiao);
 }
Esempio n. 25
0
		/// <summary>
		/// basic ctor, creates a new card
		/// </summary>
		/// <param name="id"></param>
		/// <param name="name"></param>
		/// <param name="type"></param>
		/// <param name="str"></param>
		/// <param name="def"></param>
		/// <param name="race"></param>
		/// <param name="eleType"></param>
		/// <param name="eleLv"></param>
		/// <param name="cost"></param>
		public Card( int id, string name, ECardType type, short str, short def, ECardRace race, ECardElementType eleType, int eleLv, short cost ) {
			ID = id;
			Name = name;
			Type = type;
			Strength = StrengthCurrent = str;
			Defence = DefenceCurrent = def;
			Race = race;
			Element = new CardElement( eleType, eleLv );
			Cost = cost;
		}
Esempio n. 26
0
 public PlayedCard(int value, ECardSuitTypes cardSuitType, ECardType cardType) : base(value, cardSuitType, cardType)
 {
 }
Esempio n. 27
0
    public bool IsFieldFull(ECardType type)
    {
        if (type == ECardType.MONSTER_CARD)
        {
            for (int i = 0; i < monsterCards.Length; i++)
            {
                if (monsterCards[i] == null)
                {
                    return false;
                }
            }
        }
        else if(type != ECardType.UNKNOWN)
        {
            for (int i = 0; i < effectCards.Length; i++)
            {
                if (effectCards[i] == null)
                {
                    return false;
                }
            }
        }

        return true;
    }
Esempio n. 28
0
 private bool IsWan(ECardType card)
 {
     return(card >= ECardType.OneWan && card <= ECardType.NineWan);
 }