Пример #1
0
        public void Update(Input.InputState inputState)
        {
            selectedLevel = null;

            float fCol = (inputState.MousePos.X - levelBasePos.X) / levelSpacing.X;
            int Col = (int)fCol;
            if (Col < 0 || Col >= chapters.Count)
            {
                hovering = null;
                hoveringStar = false;
                return;
            }

            List<LevelState> levels = chapters[Col];
            float fRow = (inputState.MousePos.Y + levelSpacing.Y/3 - levelBasePos.Y) / levelSpacing.Y;
            int Row = (int)fRow;
            if (Row < 0 || Row >= levels.Count)
            {
                hovering = null;
                hoveringStar = false;
                return;
            }

            hovering = levels[Row];
            hoveringStar = (fCol - Col) > 0.1f;

            if (inputState.WasMouseLeftJustPressed())
            {
                selectedLevel = hovering;
            }
        }
Пример #2
0
        public void Update(Input.InputState inputState, Rectangle screenSize)
        {
            // for now, let's refresh the state every frame
            NewGameState();

            LayOutArea(viewingPlayer.Hand, new Rectangle(100, screenSize.Height - 100, screenSize.Width - 200, 100), handCardSize, 0);
            int battlefieldHeight = (screenSize.Height - 130) / 2;
            LayOutBattlefield(new Rectangle(10, battlefieldHeight, screenSize.Width-20, battlefieldHeight), viewingPlayer.Battlefield, false);

            Player opponent = GetOpponent();
            if(opponent != null)
            {
                LayOutBattlefield(new Rectangle(10, 0, screenSize.Width-20, battlefieldHeight), opponent.Battlefield, true);
            }

            Vector2 mousePos = inputState.MousePos;
            if (hoveredCard != null)
            {
                if (!hoveredCard.Contains(mousePos))
                    hoveredCard = null;
            }
            bool hoveredCardMissing = (hoveredCard != null);

            foreach (UICard c in gameStateRepresentation.Values)
            {
                if (c == hoveredCard)
                    hoveredCardMissing = false;
                else if (hoveredCard == null && c.Contains(mousePos))
                    hoveredCard = c;

                c.Update(hoveredCard == c);
            }

            if (hoveredCardMissing)
                hoveredCard = null;

            if (hoveredCard != null && inputState.WasMouseLeftJustPressed())
            {
                if (hoveredCard.card is HandCardReference)
                {
                    viewingPlayer.Play((HandCardReference)hoveredCard.card);
                }
                else if (hoveredCard.card is BattlefieldCardReference)
                {
                    bool activatedAnAbility = false;
                    foreach(AbilityInstance a in hoveredCard.card.Abilities)
                    {
                        if(a.ability is ActivatedAbility)
                        {
                            ((ActivatedAbility)a.ability).Activate((BattlefieldCardReference)hoveredCard.card);
                            activatedAnAbility = true;
                            break;
                        }
                    }

                    if(!activatedAnAbility && hoveredCard.card.IsCreature && viewingPlayer.game.currentPhase == Phase.Attack)
                    {
                        BattlefieldCardReference battlefieldCard = (BattlefieldCardReference)hoveredCard.card;
                        if (viewingPlayer.IsAttacking(battlefieldCard))
                        {
                            viewingPlayer.WithdrawAttacker(battlefieldCard);
                        }
                        else
                        {
                            viewingPlayer.DeclareAttacker(battlefieldCard, GetOpponent());
                        }
                    }
//                    BattlefieldCardReference cardRef = ((BattlefieldCardReference)hoveredCard.card);
//                    cardRef.isTapped = !cardRef.isTapped;
                }
            }

            foreach(UIButton button in buttons)
            {
                button.Update(inputState);
            }
        }