コード例 #1
0
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            switch (location)
            {
            case DeckLocation.InPlay:
                if (_PhaseChangingEventHandler != null)
                {
                    player.PhaseChanging -= _PhaseChangingEventHandler;
                }

                _PhaseChangingEventHandler = new Player.PhaseChangingEventHandler(player_PhaseChanging);
                player.PhaseChanging      += _PhaseChangingEventHandler;

                if (_CleaningUpEventHandler != null)
                {
                    player.CleaningUp -= _CleaningUpEventHandler;
                }

                _CleaningUpEventHandler = new Player.CleaningUpEventHandler(player_CleaningUp);
                player.CleaningUp      += _CleaningUpEventHandler;

                _CanPutOnDeck = false;
                break;
            }
        }
コード例 #2
0
 internal void AddedTo(DeckLocation location, Player player)
 {
     foreach (Card card in this)
     {
         card.AddedTo(location, player);
     }
 }
コード例 #3
0
    public void MoveLastAddedCard(DeckLocation location)
    {
        Card card = cards[GetSize() - 1];

        cards.RemoveAt(GetSize() - 1);
        AddCard(card, location);
    }
コード例 #4
0
    public void AddCard(Card card, DeckLocation location)
    {
        switch (location)
        {
        case DeckLocation.BOTTOM:
            cards.Add(card);
            break;

        case DeckLocation.TOP:
            cards.Insert(0, card);
            break;

        case DeckLocation.RANDOM:
            cards.Insert(Random.Range(0, GetSize() - 1), card);
            break;

        case DeckLocation.SHUFFLE:
            cards.Add(card);
            Shuffle();
            break;

        default:
            cards.Add(card);
            break;
        }
    }
コード例 #5
0
 public CardReceivedEventArgs(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
 {
     this.FromPlayer = fromPlayer;
     this.Card       = card;
     this.Location   = location;
     this.Position   = position;
 }
コード例 #6
0
    public static int GetACard()
    {
        if (CurrentCardNumber > 51)
        {
            return(-1);
        }

        //
        // 5/16/2017 there is only ONE deck of cards
        //
        int cardPTR = instance.cardDeckPointer[CurrentCardNumber];

        CurrentCardNumber += 1;
        if (CurrentCardNumber > 51)
        {
            //
            // change carddeck image to out of cards
            //
            SpriteRenderer render = DeckLocation.GetComponent <Renderer>() as SpriteRenderer;
            render.sprite = instance.cardBacks[0];
        }
        //if (CurrentCardNumber > 51)
        //{
        //    return -1;
        //    //
        //    // Re-create/shuffle
        //    //Shuffle();
        //    //cardPTR = instance.cardDeckPointer[CurrentCardNumber];
        //}

        return(cardPTR);
    }
コード例 #7
0
 internal void RemovedFrom(DeckLocation location, Player player)
 {
     foreach (Card card in this)
     {
         card.RemovedFrom(location, player);
     }
 }
コード例 #8
0
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            switch (location)
            {
            case DeckLocation.Hand:
                if (_AttackHandler != null)
                {
                    player.Attacked -= _AttackHandler;
                }

                _AttackHandler   = new Player.AttackedEventHandler(player_Attacked);
                player.Attacked += _AttackHandler;
                break;

            case DeckLocation.SetAside:
                if (_TurnStartedEventHandler != null)
                {
                    player.TurnStarted -= _TurnStartedEventHandler;
                }
                _TurnStartedEventPlayer              = player;
                _TurnStartedEventHandler             = new Player.TurnStartedEventHandler(player_TurnStarted);
                _TurnStartedEventPlayer.TurnStarted += _TurnStartedEventHandler;
                break;
            }
        }
コード例 #9
0
 public CardGainEventArgs(Game game, Card card, DeckLocation location, DeckPosition position, Boolean bought)
 {
     this.Game     = game;
     this.Card     = card;
     this.Location = location;
     this.Position = position;
     this.Bought   = bought;
 }
コード例 #10
0
 public virtual void RemovedFrom(DeckLocation location, Player player)
 {
     if (_TokenEventHandler != null)
     {
         player.TokenActedOn -= _TokenEventHandler;
     }
     _TokenEventHandler = null;
 }
コード例 #11
0
 public override void RemovedFrom(DeckLocation location, Player player)
 {
     base.RemovedFrom(location, player);
     if (_CardBoughtHandler != null)
     {
         player.CardBought -= _CardBoughtHandler;
     }
     _CardBoughtHandler = null;
 }
コード例 #12
0
 public override void RemovedFrom(DeckLocation location, Player player)
 {
     base.RemovedFrom(location, player);
     if (_ShuffledEventHandler != null)
     {
         player.Shuffled -= _ShuffledEventHandler;
     }
     _ShuffledEventHandler = null;
 }
コード例 #13
0
 public override void RemovedFrom(DeckLocation location, Player player)
 {
     base.RemovedFrom(location, player);
     if (_CostComputeEventHandler != null)
     {
         player._Game.CostCompute -= _CostComputeEventHandler;
     }
     _CostComputeEventHandler = null;
 }
コード例 #14
0
ファイル: Base.cs プロジェクト: micahpaul/dominion_net_multi
 public override void RemovedFrom(DeckLocation location, Player player)
 {
     base.RemovedFrom(location, player);
     if (_AttackHandler != null)
     {
         player.Attacked -= _AttackHandler;
     }
     _AttackHandler = null;
 }
コード例 #15
0
 public virtual void AddedTo(DeckLocation location, Player player)
 {
     if (location == DeckLocation.Hand)
     {
         if (player._Game.Table.Supplies.ContainsKey(this))
         {
             if (player._Game.Table.Supplies[this].Tokens.Any(token => token.ActDefined))
             {
                 _TokenEventHandler   = new Token.TokenActionEventHandler(token_TokenAction);
                 player.TokenActedOn += _TokenEventHandler;
             }
         }
     }
 }
コード例 #16
0
ファイル: Base.cs プロジェクト: micahpaul/dominion_net_multi
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            if (location == DeckLocation.Hand)
            {
                if (_AttackHandler != null)
                {
                    player.Attacked -= _AttackHandler;
                }

                _AttackHandler   = new Player.AttackedEventHandler(player_Attacked);
                player.Attacked += _AttackHandler;
            }
        }
コード例 #17
0
 public override void RemovedFrom(DeckLocation location, Player player)
 {
     base.RemovedFrom(location, player);
     if (_PhaseChangingEventHandler != null)
     {
         player.PhaseChanging -= _PhaseChangingEventHandler;
     }
     _PhaseChangingEventHandler = null;
     if (_CleaningUpEventHandler != null)
     {
         player.CleaningUp -= _CleaningUpEventHandler;
     }
     _CleaningUpEventHandler = null;
     _CanPutOnDeck           = false;
 }
コード例 #18
0
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            if (location == DeckLocation.InPlay)
            {
                if (_CardBoughtHandler != null)
                {
                    player.CardBought -= _CardBoughtHandler;
                }

                _CardBoughtHandler = new Player.CardBoughtEventHandler(player_CardBought);
                player.CardBought += _CardBoughtHandler;
            }
        }
コード例 #19
0
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            if (location == DeckLocation.InPlay)
            {
                if (_CostComputeEventHandler != null)
                {
                    player._Game.CostCompute -= _CostComputeEventHandler;
                }

                _CostComputeEventHandler  = new Game.CostComputeEventHandler(player_PrincessInPlayArea);
                player._Game.CostCompute += _CostComputeEventHandler;
                player._Game.SendMessage(player, this, 2);
            }
        }
コード例 #20
0
    public Card GetCard(DeckLocation location)
    {
        switch (location)
        {
        case DeckLocation.BOTTOM:
            return(cards[cards.Count - 1]);

        case DeckLocation.RANDOM:
            return(cards[Random.Range(0, cards.Count - 1)]);

        case DeckLocation.TOP:
            return(cards[0]);

        default:
            return(null);
        }
    }
コード例 #21
0
        public override void AddedTo(DeckLocation location, Player player)
        {
            base.AddedTo(location, player);

            switch (location)
            {
            case DeckLocation.Deck:
                if (_ShuffledEventHandler != null)
                {
                    player.Shuffled -= _ShuffledEventHandler;
                }

                _ShuffledEventHandler = new Player.ShuffledEventHandler(player_Shuffled);
                player.Shuffled      += _ShuffledEventHandler;
                break;
            }
        }
コード例 #22
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, Type type, int count)
		{
			return RetrieveCardsFrom(location, DeckPosition.Automatic, c => c.CardType == type, count);
		}
コード例 #23
0
ファイル: GameController.cs プロジェクト: rycoll/1KBWC
 public void AddToDeck(Card card, DeckLocation loc)
 {
     GM.Cards.Deck.AddCard(card, loc);
     UI.SetDeckText(GM.Cards.Deck.GetSize());
 }
コード例 #24
0
		public CardCollection Draw(int number, DeckLocation destination)
		{
			CardCollection cardsDrawn = DrawFrom(DeckPosition.Top, number, destination);
			return cardsDrawn;
		}
コード例 #25
0
ファイル: Deck.cs プロジェクト: micahpaul/dominion_net_multi
 public Deck(DeckLocation deckLocation, Visibility visibility, VisibilityTo visibilityTo) : this(deckLocation, visibility, visibilityTo, null, false)
 {
 }
コード例 #26
0
		/// <summary>
		/// Tries to gain the number of cards specified from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="count">How many cards to gain</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, DeckLocation location, DeckPosition position, int count)
		{
			Boolean success = true;
			for (int i = 0; i < count; i++)
				success &= this.Gain(supply, supply.TopCard == null ? null : supply.TopCard.CardType, location, position, false);
			return success;
		}
コード例 #27
0
		/// <summary>
		/// Tries to gain the specified card from the trash specified into the location and position of the deck specified
		/// </summary>
		/// <param name="trash">The trash pile to look through</param>
		/// <param name="card">The card to gain from the trash</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Trash trash, Card card, DeckLocation location, DeckPosition position)
		{
			if (trash.Contains(card))
			{
				CardGainEventArgs cgea = CardGainCheckAllowed(card, location, position, false);
				if (!cgea.Cancelled)
					return this.Gain(trash.Retrieve(this, card), cgea.Location, cgea.Position, cgea.Bought);
				else
				{
					CardGainFinish(card, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);
					return true;
				}
			}
			return false;
		}
コード例 #28
0
		private CardCollection MoveToTrashStart(DeckLocation location, CardCollection cards)
		{
			CardCollection cardsMoved = null;
			switch (location)
			{
				case DeckLocation.Hand:
					cardsMoved = _Hand.Retrieve(this, c => cards.Contains(c));
					break;

				case DeckLocation.Revealed:
					cardsMoved = _Revealed.Retrieve(this, c => cards.Contains(c));
					break;

				case DeckLocation.Discard:
					cardsMoved = _DiscardPile.Retrieve(this, c => cards.Contains(c));
					break;

				case DeckLocation.InPlay:
					cardsMoved = _InPlay.Retrieve(this, c => cards.Contains(c));
					break;

				case DeckLocation.SetAside:
					cardsMoved = _SetAside.Retrieve(this, c => cards.Contains(c));
					break;

				case DeckLocation.Private:
					cardsMoved = _Private.Retrieve(this, c => cards.Contains(c));
					break;

				default:
					throw new Exception("Cannot move card to trash from this location");
			}
			_Game.Table.Trash.AddRange(cardsMoved);
			return cardsMoved;
		}
コード例 #29
0
		/// <summary>
		/// Tries to gain the specified cardType from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="cardType">The card type we're trying to gain</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="isBought">Indicating whether or not the card was bought</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, Type cardType, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			if (supply.CanGain(cardType))
			{
				Card supplyCard = supply[cardType].First();
				CardGainEventArgs cgea = CardGainCheckAllowed(supplyCard, location, position, isBought);
				if (!cgea.Cancelled)
					return this.Gain(supply.Take(cardType), cgea.Location, cgea.Position, cgea.Bought);
				else
				{
					CardGainFinish(supplyCard, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);
					return false;
				}
			}
			return false;
		}
コード例 #30
0
    public void executeNext()
    {
        Instruction next = this.next();

        try {
            switch (next)
            {
            // FUNCTIONS

            case Instruction.RANDOM_NUMBER: {
                int upperBound = ReadIntLiteral(skipToNext);
                push(LiteralFactory.CreateIntLiteral(UnityEngine.Random.Range(1, upperBound)));
                break;
            }

            case Instruction.ADD: {
                int a = ReadIntLiteral(skipToNext);
                int b = ReadIntLiteral(skipToNext);
                push(LiteralFactory.CreateIntLiteral(a + b));
                break;
            }

            case Instruction.IF: {
                int         controlID  = ReadIntLiteral(skipToNext);
                Condition   condition  = ReadConditionLiteral(skipToNext);
                List <byte> blockBytes = new List <byte>();

                while (HasBytes())
                {
                    byte b = pop();
                    if (b == (byte)Instruction.ENDIF)
                    {
                        int id = ReadIntLiteral(skipToNext);
                        if (id == controlID)
                        {
                            break;
                        }
                        else
                        {
                            blockBytes.Insert(0, (byte)Instruction.ENDIF);
                            blockBytes.InsertRange(0, LiteralFactory.CreateIntLiteral(id));
                        }
                    }
                    else
                    {
                        blockBytes.Insert(0, b);
                    }
                }
                if (condition.Evaluate())
                {
                    push(blockBytes);
                }
                break;
            }

            case Instruction.UNLESS: {
                int         controlID  = ReadIntLiteral(skipToNext);
                Condition   condition  = ReadConditionLiteral(skipToNext);
                List <byte> blockBytes = new List <byte>();

                while (HasBytes())
                {
                    byte b = pop();
                    if (b == (byte)Instruction.ENDIF)
                    {
                        int id = ReadIntLiteral(skipToNext);
                        if (id == controlID)
                        {
                            break;
                        }
                        else
                        {
                            blockBytes.Insert(0, (byte)Instruction.ENDIF);
                            blockBytes.InsertRange(0, LiteralFactory.CreateIntLiteral(id));
                        }
                    }
                    else
                    {
                        blockBytes.Insert(0, b);
                    }
                }
                if (!condition.Evaluate())
                {
                    push(blockBytes);
                }
                break;
            }

            case Instruction.LIST_LENGTH: {
                List <byte[]> list = ReadList(skipToNext);
                push(LiteralFactory.CreateIntLiteral(list.Count));
                break;
            }

            case Instruction.CARD_HAS_TAG: {
                Card   card    = GM.ReadCardFromStack();
                string tagName = ReadStringLiteral(skipToNext);
                push(LiteralFactory.CreateConditionLiteral(
                         LiteralFactory.CreateBoolLiteral(card.HasTag(tagName)),
                         LiteralFactory.CreateBoolLiteral(true),
                         ConditionType.BOOL,
                         ConditionOperator.EQUAL
                         ));
                break;
            }

            case Instruction.PLAYER_IS_WINNING: {
                GamePlayer player  = GM.ReadPlayerFromStack();
                bool       winning = true;
                foreach (GamePlayer otherPlayer in GM.Players.GetPlayers())
                {
                    if (otherPlayer.Points > player.Points)
                    {
                        winning = false;
                        break;
                    }
                }
                push(LiteralFactory.CreateConditionLiteral(
                         LiteralFactory.CreateBoolLiteral(winning),
                         LiteralFactory.CreateBoolLiteral(true),
                         ConditionType.BOOL,
                         ConditionOperator.EQUAL
                         ));
                break;
            }

            case Instruction.PLAYER_IS_LOSING: {
                GamePlayer player = GM.ReadPlayerFromStack();
                bool       losing = true;
                foreach (GamePlayer otherPlayer in GM.Players.GetPlayers())
                {
                    if (otherPlayer.Points < player.Points)
                    {
                        losing = false;
                        break;
                    }
                }
                push(LiteralFactory.CreateBoolLiteral(losing));
                break;
            }

            case Instruction.MULTIPLY: {
                int a = ReadIntLiteral(skipToNext);
                int b = ReadIntLiteral(skipToNext);
                push(LiteralFactory.CreateIntLiteral(a * b));
                break;
            }

            case Instruction.LOOP: {
                int id  = ReadIntLiteral(skipToNext);
                int num = ReadIntLiteral(skipToNext);
                List <List <byte> > instructionArrays = new List <List <byte> >();
                while (HasBytes())
                {
                    if (peek() == (byte)Instruction.ENDLOOP)
                    {
                        pop();
                        int endloopID = ReadIntLiteral(skipToNext);
                        if (endloopID == id)
                        {
                            break;
                        }
                        else
                        {
                            List <byte> endloopBytes = new List <byte>(LiteralFactory.CreateIntLiteral(endloopID));
                            endloopBytes.Add((byte)Instruction.ENDLOOP);
                            instructionArrays.Insert(0, endloopBytes);
                        }
                    }
                    else
                    {
                        List <byte> arr = popInstruction(skipToNext);
                        instructionArrays.Insert(0, arr);
                    }
                }
                for (int n = 0; n < num; n++)
                {
                    for (int m = 0; m < instructionArrays.Count; m++)
                    {
                        push(instructionArrays[m]);
                    }
                }
                break;
            }

            case Instruction.FOR_LOOP: {
                int                 ID                = ReadIntLiteral(skipToNext);
                List <byte[]>       items             = ReadList(skipToNext);
                List <List <byte> > instructionArrays = new List <List <byte> >();
                while (HasBytes())
                {
                    if (peek() == (byte)Instruction.ENDLOOP)
                    {
                        pop();
                        int endloopID = ReadIntLiteral(skipToNext);
                        if (endloopID == ID)
                        {
                            break;
                        }
                        else
                        {
                            List <byte> endloopBytes = new List <byte>(LiteralFactory.CreateIntLiteral(endloopID));
                            endloopBytes.Add((byte)Instruction.ENDLOOP);
                            instructionArrays.Insert(0, endloopBytes);
                        }
                    }
                    List <byte> arr = popInstruction(skipToNext);
                    instructionArrays.Insert(0, arr);
                }

                List <byte> idBytes = LiteralFactory.CreateIntLiteral(ID);
                for (int i = 0; i < items.Count; i++)
                {
                    List <byte> currentItem = new List <byte>(items[i]);
                    currentItem.Reverse();
                    List <byte> addToRegister = InstructionFactory.Make_AddToRegister(idBytes, currentItem);
                    for (int m = 0; m < instructionArrays.Count; m++)
                    {
                        push(instructionArrays[m]);
                    }
                    push(addToRegister);
                }
                break;
            }

            case Instruction.ADD_TO_REGISTER: {
                int         ID    = ReadIntLiteral(skipToNext);
                int         size  = ReadIntLiteral(skipToNext);
                List <byte> bytes = pop(size);
                register[ID] = bytes;
                break;
            }

            case Instruction.PLACEHOLDER: {
                int         ID    = ReadIntLiteral(skipToNext);
                List <byte> fetch = new List <byte>(register[ID]);
                fetch.Reverse();
                push(fetch);
                break;
            }

            // QUERIES

            case Instruction.GET_ACTIVE_PLAYER: {
                push(LiteralFactory.CreatePlayerLiteral(GM.Players.GetActivePlayer()));
                break;
            }

            case Instruction.GET_ALL_OPPONENTS: {
                push(LiteralFactory.CreateListLiteral(
                         new List <GamePlayer>(GM.Players.GetOpponents())
                         ));
                break;
            }

            case Instruction.GET_ALL_PLAYERS: {
                push(LiteralFactory.CreateListLiteral(
                         new List <GamePlayer>(GM.Players.GetPlayers())
                         ));
                break;
            }

            case Instruction.GET_CARDS_IN_DECK: {
                push(LiteralFactory.CreateListLiteral(
                         new List <Card>(GM.Cards.Deck.GetCards())
                         ));
                break;
            }

            case Instruction.GET_CARDS_IN_DISCARD: {
                push(LiteralFactory.CreateListLiteral(
                         new List <Card>(GM.Cards.Discard.GetCards())
                         ));
                break;
            }

            case Instruction.GET_CARDS_IN_HAND: {
                GamePlayer player = GM.ReadPlayerFromStack();
                push(LiteralFactory.CreateListLiteral(
                         new List <Card>(player.Hand.GetCards())
                         ));
                break;
            }

            case Instruction.GET_PLAYER_POINTS: {
                GamePlayer player = GM.ReadPlayerFromStack();
                int        points = player.Points;
                push(LiteralFactory.CreateIntLiteral(points));
                break;
            }

            case Instruction.READ_COUNTER: {
                string key   = ReadStringLiteral(skipToNext);
                int    count = GM.Variables.GetCounter(key);
                push(LiteralFactory.CreateIntLiteral(count));
                break;
            }

            case Instruction.BOOL_COMPARISON: {
                bool operandA     = ReadBoolLiteral(skipToNext);
                byte operatorEnum = ReadEnumLiteral();
                bool operandB     = ReadBoolLiteral(skipToNext);
                push(LiteralFactory.CreateConditionLiteral(
                         new CompareBool(operandA, operandB, (ConditionOperator)operatorEnum)
                         ));
                break;
            }

            case Instruction.NUM_COMPARISON: {
                int  operandA     = ReadIntLiteral(skipToNext);
                int  operandB     = ReadIntLiteral(skipToNext);
                byte operatorEnum = ReadEnumLiteral();
                push(LiteralFactory.CreateConditionLiteral(
                         new CompareNum(operandA, operandB, (ConditionOperator)operatorEnum)
                         ));
                break;
            }

            case Instruction.TARGET_PLAYER: {
                GM.UI.PresentChoiceOfPlayers(new List <GamePlayer>(GM.Players.GetPlayers()), this);
                break;
            }

            case Instruction.TARGET_OPPONENT: {
                GM.UI.PresentChoiceOfPlayers(new List <GamePlayer>(GM.Players.GetOpponents()), this);
                break;
            }

            case Instruction.TARGET_CARD_IN_DECK: {
                GM.UI.PresentChoiceOfCards(new List <Card>(GM.Cards.Deck.GetCards()), this);
                break;
            }

            case Instruction.TARGET_CARD_IN_DISCARD: {
                GM.UI.PresentChoiceOfCards(new List <Card>(GM.Cards.Discard.GetCards()), this);
                break;
            }

            case Instruction.TARGET_CARD_IN_HAND: {
                GamePlayer player = GM.ReadPlayerFromStack();
                GM.UI.PresentChoiceOfCards(new List <Card>(player.Hand.GetCards()), this);
                break;
            }

            case Instruction.RANDOM_PLAYER: {
                GamePlayer[] players      = GM.Players.GetPlayers();
                GamePlayer   randomPlayer = players[UnityEngine.Random.Range(0, players.Length)];
                push(LiteralFactory.CreatePlayerLiteral(randomPlayer));
                break;
            }

            case Instruction.RANDOM_OPPONENT: {
                GamePlayer[] opponents      = GM.Players.GetOpponents();
                GamePlayer   randomOpponent = opponents[UnityEngine.Random.Range(0, opponents.Length)];
                push(LiteralFactory.CreatePlayerLiteral(randomOpponent));
                break;
            }

            case Instruction.RANDOM_CARD_IN_DECK: {
                Card[] deckCards  = GM.Cards.Deck.GetCards();
                Card   randomCard = deckCards[UnityEngine.Random.Range(0, deckCards.Length)];
                push(LiteralFactory.CreateCardLiteral(randomCard));
                break;
            }

            case Instruction.RANDOM_CARD_IN_DISCARD: {
                Card[] discardCards = GM.Cards.Discard.GetCards();
                Card   randomCard   = discardCards[UnityEngine.Random.Range(0, discardCards.Length)];
                push(LiteralFactory.CreateCardLiteral(randomCard));
                break;
            }

            case Instruction.RANDOM_CARD_IN_HAND: {
                GamePlayer player     = GM.ReadPlayerFromStack();
                Card[]     handCards  = player.Hand.GetCards();
                Card       randomCard = handCards[UnityEngine.Random.Range(0, handCards.Length)];
                push(LiteralFactory.CreateCardLiteral(randomCard));
                break;
            }

            // EFFECTS

            case Instruction.INCREMENT_PLAYER_POINTS: {
                GamePlayer player    = GM.ReadPlayerFromStack();
                int        pointsNum = ReadIntLiteral(skipToNext);
                GM.SetPlayerPoints(player, player.Points + pointsNum);
                break;
            }

            case Instruction.PLAYER_DRAW_CARD: {
                GamePlayer player   = GM.ReadPlayerFromStack();
                int        numCards = ReadIntLiteral(skipToNext);
                for (int n = 0; n < numCards; n++)
                {
                    GM.PlayerDrawCard(player);
                }
                break;
            }

            case Instruction.SET_COUNTER: {
                string key   = ReadStringLiteral(skipToNext);
                int    count = ReadIntLiteral(skipToNext);
                GM.Variables.SetCounter(key, count);
                break;
            }

            case Instruction.SET_PLAYER_DRAW: {
                GamePlayer player = GM.ReadPlayerFromStack();
                int        num    = ReadIntLiteral(skipToNext);
                player.SetDrawPerTurn(num);
                break;
            }

            case Instruction.SET_PLAYER_MAX_HAND: {
                GamePlayer player = GM.ReadPlayerFromStack();
                int        num    = ReadIntLiteral(skipToNext);
                player.Hand.SetMax(num);
                break;
            }

            case Instruction.SET_PLAYER_POINTS: {
                GamePlayer player    = GM.ReadPlayerFromStack();
                int        pointsNum = ReadIntLiteral(skipToNext);
                GM.SetPlayerPoints(player, pointsNum);
                break;
            }

            case Instruction.MOVE_TO_DECK: {
                Card         card    = GM.ReadCardFromStack();
                DeckLocation posEnum = (DeckLocation)ReadEnumLiteral();
                card.Zone.MoveCard(GM.Cards.Deck, card.GetID());
                GM.Cards.Deck.MoveLastAddedCard(posEnum);
                break;
            }

            case Instruction.MOVE_TO_DISCARD: {
                Card card = GM.ReadCardFromStack();
                card.Zone.MoveCard(GM.Cards.Discard, card.GetID());
                break;
            }
            }
        } catch (UnexpectedByteException e) {
            Debug.LogError(e);
        } catch (StackFullException e) {
            Debug.LogError(e);
        } catch (StackEmptyException e) {
            Debug.LogError(e);
        }
    }
コード例 #31
0
ファイル: Base.cs プロジェクト: micahpaul/dominion_net_multi
 public override void AddedTo(DeckLocation location, Player player)
 {
     base.AddedTo(location, player);
     this._CanCleanUp = true;
 }
コード例 #32
0
ファイル: Deck.cs プロジェクト: micahpaul/dominion_net_multi
 public Deck(DeckLocation deckLocation)
     : base()
 {
     _DeckLocation = deckLocation;
 }
コード例 #33
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, Predicate<Card> match)
		{
			return RetrieveCardsFrom(location, DeckPosition.Automatic, match, -1);
		}
コード例 #34
0
		private void CardGainInto(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (this.DiscardPile.Contains(card))
				this.RetrieveCardFrom(DeckLocation.Discard, card);
			card.Gaining(this, ref location, ref position);
			this.AddCardInto(location, card, position);
			card.Gained(this);

			if (CardGainedInto != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainedInto(this, cgea);
			}
		}
コード例 #35
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, DeckPosition position, Predicate<Card> match, int count)
		{
			CardCollection cards;
			switch (location)
			{
				case DeckLocation.Hand:
					cards = _Hand.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Revealed:
					cards = _Revealed.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Discard:
					cards = _DiscardPile.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Deck:
					cards = _DrawPile.Retrieve(this, position, match, count);
					if (cards.Count < count && _DrawPile.Count == 0 && _DiscardPile.Count > 0)
						this.ShuffleForDrawing();
					cards.AddRange(_DrawPile.Retrieve(this, position, match, count < 0 ? count : count - cards.Count));
					break;

				case DeckLocation.InPlay:
					cards = _InPlay.Retrieve(this, position, match, count);
					break;

				case DeckLocation.SetAside:
					cards = _SetAside.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Private:
					cards = _Private.Retrieve(this, position, match, count);
					break;

				case DeckLocation.InPlayAndSetAside:
					cards = _InPlay.Retrieve(this, position, match, count);
					cards.AddRange(_SetAside.Retrieve(this, position, match, count < 0 ? count : count - cards.Count));
					break;

				default:
					cards = new CardCollection();
					break;
			}
			cards.RemovedFrom(location, this);
			return cards;
		}
コード例 #36
0
		public void Receive(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
		{
			if (CurrentTurn != null)
				CurrentTurn.Received(card);
			this.AddCardInto(location, card, position);
			card.ReceivedBy(this);

			if (CardReceived != null)
			{
				CardReceivedEventArgs crea = new CardReceivedEventArgs(fromPlayer, card, location, position);
				CardReceived(this, crea);
			}
		}
コード例 #37
0
		private CardGainEventArgs CardGainCheckAllowed(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			Boolean cancelled = false;
			CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);

			if (CardGaining != null)
			{
				do
				{
					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.Cancelled = cancelled;
					CardGaining(this, cgea);

					Boolean isAnyRequired = false;
					List<String> options = new List<String>();
					IEnumerable<Type> cardTypes = cgea.Actions.Keys;
					foreach (Type key in cardTypes)
					{
						options.Add(cgea.Actions[key].Text);
						isAnyRequired |= cgea.Actions[key].IsRequired;
					}

					if (options.Count > 0)
					{
						options.Sort();
						Choice choice = new Choice(String.Format("You are gaining {0}", card), null, new CardCollection() { card }, options, this, cgea, false, isAnyRequired ? 1 : 0, 1);
						ChoiceResult result = this.MakeChoice(choice);

						if (result.Options.Count > 0)
							cgea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(this, ref cgea);
					}

					cancelled = cgea.Cancelled;
					location = cgea.Location;
					position = cgea.Position;
				} while (CardGaining != null && cgea.HandledBy.Count > 0);
			}
			return cgea;
		}
コード例 #38
0
		internal void Trash(DeckLocation location, CardCollection cards)
		{
			if (cards.Count == 0)
				return;

			TrashEventArgs tea = null;

			if (Trashing != null)
			{
				do
				{
					tea = new TrashEventArgs(this, cards);
					Trashing(this, tea);

					Boolean isAnyRequired = false;
					List<String> options = new List<String>();
					IEnumerable<Type> cardTypes = tea.Actions.Keys;
					foreach (Type key in cardTypes)
					{
						options.Add(tea.Actions[key].Text);
						isAnyRequired |= tea.Actions[key].IsRequired;
					}

					if (options.Count > 0)
					{
						options.Sort();
						Choice choice = new Choice(String.Format("You are trashing {0} cards", cards.Count), null, cards, options, this, tea, false, isAnyRequired ? 1 : 0, 1);
						ChoiceResult result = this.MakeChoice(choice);

						if (result.Options.Count > 0)
							tea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(this, ref tea);
					}
				} while (Trashing != null && tea.HandledBy.Count > 0);
			}

			this.MoveToTrashStart(location, cards);
			if (CurrentTurn != null)
				CurrentTurn.Trashed(cards);

			if (Trashed != null)
			{
				List<Object> handledBy = new List<Object>();
				Boolean actionPerformed = false;
				do
				{
					actionPerformed = false;

					tea = new TrashEventArgs(this, cards);
					tea.HandledBy.AddRange(handledBy);
					Trashed(this, tea);
					handledBy = tea.HandledBy;

					IEnumerator<Player> enumerator = this._Game.GetPlayersStartingWithEnumerator(this);
					while (enumerator.MoveNext())
					{
						Boolean isAnyRequired = false;
						List<String> options = new List<String>();
						IEnumerable<Type> cardTypes = tea.Actions.Keys;
						foreach (Type key in cardTypes)
						{
							if (enumerator.Current == tea.Actions[key].Player)
							{
								options.Add(tea.Actions[key].Text);
								isAnyRequired |= tea.Actions[key].IsRequired;
							}
						}
						if (options.Count > 0)
						{
							options.Sort();
							Choice choice = new Choice(String.Format("{0} trashed {1}", this == enumerator.Current ? "You" : this.ToString(), Utilities.StringUtility.Plural("card", cards.Count)), null, cards, options, this, tea, false, isAnyRequired ? 1 : 0, 1);
							ChoiceResult result = enumerator.Current.MakeChoice(choice);

							if (result.Options.Count > 0)
							{
								tea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(enumerator.Current, ref tea);
								actionPerformed = true;
							}
						}
					}
				} while (Trashed != null && actionPerformed);
			}

			cards.TrashedBy(this);
			Lose(cards);

			if (TrashedFinished != null)
			{
				tea = new TrashEventArgs(this, cards);
				TrashedFinished(this, tea);
			}

			cards.RemovedFrom(location, this);
		}
コード例 #39
0
		/// <summary>
		/// Tries to gain from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, DeckLocation location, DeckPosition position)
		{
			return Gain(supply, supply.TopCard == null ? null : supply.TopCard.CardType, location, position, false);
		}
コード例 #40
0
		public DeckPosition ResolveDeckPosition(DeckLocation location, DeckPosition position)
		{
			switch (location)
			{
				case DeckLocation.Hand:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Revealed:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Discard:
					return position == DeckPosition.Automatic ? DeckPosition.Top : position;

				case DeckLocation.Deck:
					return position == DeckPosition.Automatic ? DeckPosition.Top : position;

				case DeckLocation.InPlay:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.SetAside:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.PlayerMat:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Private:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.InPlayAndSetAside:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;
			}
			return position;
		}
コード例 #41
0
		/// <summary>
		/// Tries to gain the specified cardType from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="cardType">The card type we're trying to gain</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, Type cardType, DeckLocation location, DeckPosition position)
		{
			return Gain(supply, cardType, location, position, false);
		}
コード例 #42
0
ファイル: Deck.cs プロジェクト: micahpaul/dominion_net_multi
 public Deck(DeckLocation deckLocation, Visibility visibility, VisibilityTo visibilityTo, IComparer <Card> comparer, Boolean collate)
     : base(visibility, visibilityTo, comparer, collate)
 {
     _DeckLocation = deckLocation;
 }
コード例 #43
0
		/// <summary>
		/// Tries to gain the specified card into the location and position of the deck specified
		/// </summary>
		/// <param name="card">The card to gain from the supply</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="isBought">Indicating whether or not the card was bought</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		private Boolean Gain(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			if (card == null)
				return false;

			Boolean cancelled = false;
			Boolean lostTrackOf = false;
			if (CurrentTurn != null)
				CurrentTurn.Gained(card);

			CardGainInto(card, location, position, isBought, false, false);

			if (CardGained != null)
			{
				// This is a little bit wacky, but we're going to set up an event listener INSIDE this method that listens to both
				// the Discard Pile and the Draw Pile for changes.  We need to do this in order to capture any "Lost Track" updates
				// that might happen from one card covering up another card (e.g. this card being gained) and causing the game state
				// to "Lose Track" of the card being gained in this method.
				_LostTrackStack[card] = false;
				Pile.PileChangedEventHandler pceh = new Pile.PileChangedEventHandler(DiscardPile_PileChanged_CaptureLostTrack);
				this.DiscardPile.PileChanged += pceh;

				List<Object> handledBy = new List<Object>();
				CardGainEventArgs cgea = null;
				Boolean actionPerformed = false;
				do
				{
					actionPerformed = false;

					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.HandledBy.AddRange(handledBy);
					cgea.Cancelled = cancelled;
					cgea.IsLostTrackOf = lostTrackOf;
					CardGained(this, cgea);
					handledBy = cgea.HandledBy;
					cancelled |= cgea.Cancelled;
					lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
					location = cgea.Location;
					position = cgea.Position;

					IEnumerator<Player> enumerator = this._Game.GetPlayersStartingWithEnumerator(this);
					while (enumerator.MoveNext())
					{
						Boolean isAnyRequired = false;
						List<String> options = new List<String>();
						IEnumerable<Type> cardTypes = cgea.Actions.Keys;
						foreach (Type key in cardTypes)
						{
							if (enumerator.Current == cgea.Actions[key].Player)
							{
								options.Add(cgea.Actions[key].Text);
								isAnyRequired |= cgea.Actions[key].IsRequired;
							}
						}
						if (options.Count > 0)
						{
							Choice choice = new Choice(String.Format("{0} gained {1}", this == enumerator.Current ? "You" : this.ToString(), card), null, new CardCollection() { card }, options, this, cgea, false, isAnyRequired ? 1 : 0, 1);
							ChoiceResult result = enumerator.Current.MakeChoice(choice);

							if (result.Options.Count > 0)
							{
								options.Sort();
								cgea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(enumerator.Current, ref cgea);
								actionPerformed = true;
							}

							if (enumerator.Current == this && (cgea.Location != location || cgea.Position != position))
								CardGainInto(card, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);

							cancelled |= cgea.Cancelled;
							lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
							location = cgea.Location;
							position = cgea.Position;
						}
					}
				} while (CardGained != null && actionPerformed);

				if (pceh != null)
					this.DiscardPile.PileChanged -= pceh;
				_LostTrackStack.Remove(card);
			}

			CardGainFinish(card, location, position, isBought, cancelled, lostTrackOf);

			return true;
		}
コード例 #44
0
		public void Discard(DeckLocation fromLocation)
		{
			Discard(fromLocation, -1);
		}
コード例 #45
0
		private void CardGainFinish(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (CardGainFinished != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainFinished(this, cgea);
			}
		}
コード例 #46
0
		public void Discard(DeckLocation fromLocation, Card card)
		{
			Discard(fromLocation, c => c == card);
		}
コード例 #47
0
		internal void Trash(DeckLocation location, Card card)
		{
			this.Trash(location, new CardCollection() { card });
		}
コード例 #48
0
		public void Discard(DeckLocation fromLocation, IEnumerable<Card> cards, CardsDiscardAction discardAction)
		{
			Discard(fromLocation, c => cards.Contains(c), discardAction);
		}
コード例 #49
0
		public IPile ResolveDeck(DeckLocation location)
		{
			switch (location)
			{
				case DeckLocation.Hand:
					return this.Hand;

				case DeckLocation.Revealed:
					return this.Revealed;

				case DeckLocation.Discard:
					return this.DiscardPile;

				case DeckLocation.Deck:
					return this.DrawPile;

				case DeckLocation.InPlay:
					return this.InPlay;

				case DeckLocation.SetAside:
					return this.SetAside;

				case DeckLocation.Private:
					return this.Private;

				case DeckLocation.InPlayAndSetAside:
					return this.InPlayAndSetAside;
			}
			return null;
		}
コード例 #50
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, Category cardType)
		{
			return RetrieveCardsFrom(location, cardType, -1);
		}
コード例 #51
0
		public Card Draw(DeckLocation destination) { return Draw(1, destination).FirstOrDefault(); }
コード例 #52
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, Category cardType, int count)
		{
			return RetrieveCardsFrom(location, DeckPosition.Automatic, c => (c.Category & cardType) == cardType, count);
		}
コード例 #53
0
		public void AddCardsToHand(DeckLocation location)
		{
			this.AddCardsToHand(this.RetrieveCardsFrom(location));
		}
コード例 #54
0
ファイル: GameController.cs プロジェクト: rycoll/1KBWC
 public void AddToDiscard(Card card, DeckLocation loc)
 {
     GM.Cards.Discard.AddCard(card, loc);
     UI.AddToDiscardDisplay(card);
     UI.SetDiscardText(GM.Cards.Discard.GetSize());
 }
コード例 #55
0
		public void Discard(DeckLocation fromLocation, int count)
		{
			Discard(fromLocation, c => true, count, null);
		}
コード例 #56
0
 internal virtual void Gaining(Player player, ref DeckLocation location, ref DeckPosition position)
 {
     Receiving(player, ref location, ref position);
 }
コード例 #57
0
		public void Discard(DeckLocation fromLocation, IEnumerable<Card> cards)
		{
			Discard(fromLocation, cards, null);
		}
コード例 #58
0
 internal virtual void Receiving(Player player, ref DeckLocation location, ref DeckPosition position)
 {
 }
コード例 #59
0
		public void Discard(DeckLocation fromLocation, Type cardType, int count)
		{
			Discard(fromLocation, c => c.CardType == cardType, count, null);
		}
コード例 #60
0
		internal CardCollection RetrieveCardsFrom(DeckLocation location, CardCollection cards)
		{
			//return new CardCollection(RetrieveCardsFrom(location, DeckPosition.Automatic, c => cards.Any(card => card.CardType == c.CardType), cards.Count).OrderBy(c => cards.IndexOf(c)));
			return new CardCollection(RetrieveCardsFrom(location, DeckPosition.Automatic, c => cards.Contains(c), -1).OrderBy(c => cards.IndexOf(c)));
		}