Ejemplo n.º 1
0
    void TryMakeBuyAction(int handIndex, int tableIndex)
    {
        State = new PlayerTurnState();
        var action = new BuyCreatureAction("", handIndex, tableIndex);

        Game.ApplyAction(action);
    }
Ejemplo n.º 2
0
        public void CantBuyNotExistCard()
        {
            var state  = Common.GameState;
            var user   = state.Users[0];
            var action = new BuyCreatureAction(user.Name, -1, 0);

            Assert.False(action.CanApply(state));
            action = new BuyCreatureAction(user.Name, user.HandSet.Count, 0);
            Assert.False(action.CanApply(state));
        }
Ejemplo n.º 3
0
        public void CantBuyToWrongPosition()
        {
            var state  = Common.GameState;
            var user   = state.Users[0];
            var card   = user.HandSet.Find(c => c.Price <= user.Power);
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), -1);

            Assert.False(action.CanApply(state));
            action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), GameRules.MaxTableSet);
            Assert.False(action.CanApply(state));
        }
Ejemplo n.º 4
0
        public void UserCanBuyCreature()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(c => c.Price <= user.Power);

            Assert.NotNull(card);
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.True(action.CanApply(state));
        }
Ejemplo n.º 5
0
        public void CantBuyWithoutPower()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(c => c.Price <= user.Power);

            user.Power = 0;
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.False(action.CanApply(state));
        }
Ejemplo n.º 6
0
        public void CreatureIsRemovedFromHand()
        {
            var state  = Common.GameState;
            var user   = state.Users[0];
            var card   = user.HandSet.Find(c => c.Price <= user.Power);
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.True(action.CanApply(state));
            action.Apply(state);
            Assert.False(user.HandSet.Contains(card));
        }
Ejemplo n.º 7
0
        public void CreatureIsPlacedOnTable()
        {
            var state  = Common.GameState;
            var user   = state.Users[0];
            var card   = user.HandSet.Find(c => c.Price <= user.Power);
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.True(action.CanApply(state));
            action.Apply(state);
            Assert.True((user.TableSet.Count > 0) && (user.TableSet[0] == card));
        }
Ejemplo n.º 8
0
        public void PowerIsSpent()
        {
            var state      = Common.GameState;
            var user       = state.Users[0];
            var card       = user.HandSet.Find(c => (c.Price > 0) && (c.Price <= user.Power));
            var startPower = user.Power;
            var action     = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.True(action.CanApply(state));
            action.Apply(state);
            Assert.True(user.Power == (startPower - card.Price));
        }
Ejemplo n.º 9
0
        GameState CreatePlayerAttackReadyState()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(
                c => (c.Type == CardType.Creature) && (user.Power >= c.Price)
                );
            var buyAction = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            buyAction.Apply(state);
            card.Actions = card.MaxActions;
            return(state);
        }
Ejemplo n.º 10
0
        public void IsNotActiveOnFirstTurn()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(
                c => (c.Type == CardType.Creature) && (user.Power >= c.Price) && (c.MaxActions > 0)
                );

            Assert.NotNull(card);
            var buyAction = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            buyAction.Apply(state);
            Assert.True(user.TableSet[0].Actions == 0);
        }
Ejemplo n.º 11
0
        public void ActiveRestoredOnNextTurn()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(
                c => (c.Type == CardType.Creature) && (user.Power >= c.Price) && (c.MaxActions > 0)
                );
            var buyAction = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            buyAction.Apply(state);
            new TurnAction("1").Apply(state);
            new TurnAction("2").Apply(state);
            Assert.True(user.TableSet[0].Actions > 0);
            Assert.True(user.TableSet[0].Actions == user.TableSet[0].MaxActions);
        }
Ejemplo n.º 12
0
        GameState CreateCreatureAttackReadyState()
        {
            var state = CreatePlayerAttackReadyState();

            new TurnAction("1").Apply(state);
            var user = state.Users[1];
            var card = user.HandSet.Find(
                c => (c.Type == CardType.Creature) && (user.Power >= c.Price)
                );
            var buyAction = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            buyAction.Apply(state);
            new TurnAction("2").Apply(state);
            return(state);
        }
Ejemplo n.º 13
0
        public void CreaturesWithoutHealthIsRemoved()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(
                c => (c.Type == CardType.Creature) && (user.Power >= c.Price)
                );
            var buyAction = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            buyAction.Apply(state);
            Assert.True(user.TableSet.Contains(card));
            card.Health = 0;
            new EmptyAction().Apply(state);
            Assert.False(user.TableSet.Contains(card));
        }
Ejemplo n.º 14
0
        public void CantBuyToBusyPosition()
        {
            var state = Common.GameState;
            var user  = state.Users[0];
            var card  = user.HandSet.Find(c => c.Price <= user.Power);

            Assert.NotNull(card);
            var action = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);

            Assert.True(action.CanApply(state));
            action.Apply(state);
            user.Power = user.MaxPower;
            card       = user.HandSet.Find(c => c.Price <= user.Power);
            action     = new BuyCreatureAction(user.Name, user.HandSet.IndexOf(card), 0);
            Assert.False(action.CanApply(state));
        }
Ejemplo n.º 15
0
    void OnBuyCreatureAction(BuyCreatureAction action)
    {
        var userView    = GetUserView(action);
        var hand        = userView.Hand;
        var table       = userView.Table;
        var cardToSpawn = hand.Cards[action.HandIndex];
        var oldPos      = cardToSpawn.Root.position;

        cardToSpawn.Root.SetParent(GameObject.FindObjectOfType <Canvas>().transform, true);
        hand.Remove(cardToSpawn, false);
        var cardToReplace = table.Cards[action.TableIndex];
        var newPos        = cardToReplace.Root.transform.position;

        table.Remove(cardToReplace, true);
        table.Insert(cardToSpawn, action.TableIndex);
        var seq = DOTween.Sequence();

        seq.AppendInterval(0.01f);
        seq.AppendCallback(() => cardToSpawn.Root.SetParent(cardToSpawn.transform, true));
        seq.Append(cardToSpawn.Root.DOLocalMove(Vector3.zero, 0.33f, true));
        cardToSpawn.SetEffect(seq, PerformCommonCallback);
    }