Esempio n. 1
0
        public void Pop(int drawCardIndex)
        {
            if (false == isValid(drawCardIndex))
                return;

            DrawCard = _cardArray[drawCardIndex];
            switch (DrawCard.Type)
            {
                case Card.EType.Attack:
                    Log.Debug(string.Format("player id: {0}, draw card: {1}", Id, DrawCard.Type));
                    --NumAttack;
                    break;

                case Card.EType.Defense:
                    Log.Debug(string.Format("player id: {0}, draw card: {1}", Id, DrawCard.Type));
                    --NumDefense;
                    break;

                case Card.EType.Number:
                    NumberCard numCard = DrawCard as NumberCard;
                    Log.Debug(string.Format("player id: {0}, draw card: {1}", Id, numCard.No));
                    break;

                default:
                    break;
            }

            _cardArray[drawCardIndex] = null;
        }
Esempio n. 2
0
    public void SetCard(BoardGame.Card card)
    {
        if (null == card)
        {
            Log.Error("card is null");
            return;
        }

        switch (card.Type)
        {
        case BoardGame.Card.EType.Number:
            BoardGame.NumberCard numCard = card as BoardGame.NumberCard;
            setNumber(numCard.No);
            break;

        case BoardGame.Card.EType.Attack:
            setAttack();
            break;

        case BoardGame.Card.EType.Defense:
            setDefense();
            break;

        default:
            Log.Error("invalid card type");
            return;
        }

        Show();
    }
Esempio n. 3
0
        public void Shuffle()
        {
            NumAttack = shuffleAttack(NumAttack);
            NumDefense = shuffleDefense(NumDefense);

            byte numNumberCard = (byte) (CardCapacity - NumAttack - NumDefense);
            if (numNumberCard > CardCapacity)
            {
                Log.Error(string.Format("invalid num card; numNumberCard({0}, CardCapacity({1})", numNumberCard, CardCapacity));
                return;
            }

            int NumberCardMaxNo = NumberCard.MAX_NO + 1;    // consider range.exclusive
            for (int i = 0; i < numNumberCard; ++i)
            {
                byte randomNumber = (byte)Random.Range(NumberCard.MIN_NO, NumberCardMaxNo);
                _cardArray[i] = new NumberCard(randomNumber);
            }

            for (int i = numNumberCard; i < (numNumberCard + NumAttack); ++i)
            {
                _cardArray[i] = new Card(Card.EType.Attack);
            }

            for (int i = (numNumberCard + NumAttack); i < CardCapacity; ++i)
            {
                _cardArray[i] = new Card(Card.EType.Defense);
            }

            Log.Debug(string.Format("player id:{0}, num:{1}, att:{2}, def:{3}", Id, numNumberCard, NumAttack, NumDefense));
        }
Esempio n. 4
0
        private int getHighestNumCardIndex()
        {
            int index   = -1;
            int highest = NumberCard.MIN_NO;

            int numCard = CardArray.Length;

            for (int i = 0; i < numCard; ++i)
            {
                if (Card.EType.Number != CardArray[i].Type)
                {
                    continue;
                }

                NumberCard numberCard = CardArray[i] as NumberCard;

                int num = numberCard.No;
                if (num >= highest)
                {
                    highest = num;
                    index   = i;
                }
            }

            return(index);
        }
Esempio n. 5
0
        private bool compare(out Player superiority, out byte superNum,
                            out Player inferiority, out byte inferNum)
        {
            superiority = null;
            superNum = 0;

            inferiority = null;
            inferNum = 0;

            NumberCard userNumCard = _user.DrawCard as NumberCard;
            byte userNum = userNumCard.No;

            NumberCard aiNumCard = _ai.DrawCard as NumberCard;
            byte aiNum = aiNumCard.No;

            Log.Debug(string.Format("compare; user({0}), ai({1})", userNum, aiNum));

            if (userNum == aiNum)
                return false; // tie

            switch (Criterion)
            {
                case ENumberCriterion.Low:
                    {
                        if (userNum < aiNum)
                        {
                            superiority = _user;    superNum = userNum;
                            inferiority = _ai;      inferNum = aiNum;
                        }
                        else
                        {
                            superiority = _ai;      superNum = aiNum;
                            inferiority = _user;    inferNum = userNum;
                        }
                    }
                    return true;

                case ENumberCriterion.High:
                    {
                        if (userNum < aiNum)
                        {
                            superiority = _ai;      superNum = aiNum;
                            inferiority = _user;    inferNum = userNum;
                        }
                        else
                        {
                            superiority = _user;    superNum = userNum;
                            inferiority = _ai;      inferNum = aiNum;
                        }
                    }
                    return true;

                default:
                    {
                        Log.Error("invalid number criterion");
                    }
                    return false;
            }
        }
Esempio n. 6
0
        IEnumerator judgeUserNumAIDefense()
        {
            NumberCard userNumberCard = _user.DrawCard as NumberCard;
            Log.Debug(string.Format("judge; user({0}), ai(D)", userNumberCard.No));

            int removeCount = _ai.RemoveAllDefenseOfOpponent();
            if (removeCount > 0)
                yield return null;

            _user.Push();
            yield return null;

            if (EUserGameState.Unknown != isOver())
                yield break;

            IEnumerator iter= processBoard(userNumberCard.No, _user);
            while (iter.MoveNext())
                yield return null;
        }
Esempio n. 7
0
    private void set(BoardGame.Card card)
    {
        switch (card.Type)
        {
        case BoardGame.Card.EType.Number:
            BoardGame.NumberCard numCard = card as BoardGame.NumberCard;
            setNumber(numCard.No);
            break;

        case BoardGame.Card.EType.Attack:
            setAttack();
            break;

        case BoardGame.Card.EType.Defense:
            setDefense();
            break;

        default:
            break;
        }
    }