예제 #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            scene.Update(gameTime, playerIndexInControl);

            switch (State)
            {
            case ShopStateType.Buy:
                if (isFirst)
                {
                    isFirst = false;
                    break;
                }

                if (InputHandler.KeyReleased(Keys.Down) ||
                    InputHandler.KeyReleased(Keys.S))
                {
                    selected++;
                    if (selected >= merchant.Backpack.Items.Count)
                    {
                        selected = 0;
                    }
                }

                if (InputHandler.KeyReleased(Keys.Up) ||
                    InputHandler.KeyReleased(Keys.W))
                {
                    selected--;
                    if (selected < 0)
                    {
                        selected = merchant.Backpack.Items.Count - 1;
                    }
                }


                if (InputHandler.KeyReleased(Keys.Space) ||
                    InputHandler.KeyReleased(Keys.Enter) ||
                    (InputHandler.CheckMouseReleased(MouseButton.Left) && mouseOver))
                {
                    if (selected >= 0 &&
                        GamePlayScreen.Player.Gold >=
                        merchant.Backpack.PeekItem(
                            merchant.Backpack.Items[selected].Item.Name).Price)
                    {
                        GamePlayScreen.Player.Backpack.AddItem(
                            merchant.Backpack.GetItem(
                                merchant.Backpack.Items[selected].Item.Name));
                        GamePlayScreen.Player.Gold -=
                            merchant.Backpack.PeekItem(
                                merchant.Backpack.Items[selected].Item.Name).Price;
                    }
                }
                break;

            case ShopStateType.Sell:
                if (isFirst)
                {
                    isFirst = false;
                    break;
                }
                if (InputHandler.KeyReleased(Keys.Down) ||
                    InputHandler.KeyReleased(Keys.S))
                {
                    selected++;

                    if (selected >= GamePlayScreen.Player.Backpack.Items.Count)
                    {
                        selected = 0;
                    }
                }

                if (InputHandler.KeyReleased(Keys.Up) ||
                    InputHandler.KeyReleased(Keys.W))
                {
                    selected--;
                    if (selected < 0)
                    {
                        selected = GamePlayScreen.Player.Backpack.Items.Count - 1;
                    }
                }


                if ((InputHandler.KeyReleased(Keys.Space) ||
                     InputHandler.KeyReleased(Keys.Enter) ||
                     (InputHandler.CheckMouseReleased(MouseButton.Left) && mouseOver)))
                {
                    if (selected >= 0)
                    {
                        GameItem item = GamePlayScreen.Player.Backpack.GetItem(
                            GamePlayScreen.Player.Backpack.Items[selected].Item.Name);
                        GamePlayScreen.Player.Gold += item.Item.Price * 3 / 4;
                    }
                }
                break;

            case ShopStateType.Talk:
                if (InputHandler.KeyReleased(Keys.Space) ||
                    InputHandler.KeyReleased(Keys.Enter))
                {
                    if (scene.SelectedIndex == 0)
                    {
                        isFirst = true;
                        State   = ShopStateType.Buy;
                        //selected = -1;
                        return;
                    }

                    if (scene.SelectedIndex == 1)
                    {
                        isFirst = true;
                        State   = ShopStateType.Sell;
                        //selected = -1;
                        return;
                    }

                    if (scene.SelectedIndex == 2 && State == ShopStateType.Talk)
                    {
                        StateManager.PopState();
                    }
                }
                break;
            }

            if (InputHandler.CheckMouseReleased(MouseButton.Right) || InputHandler.KeyReleased(Keys.Escape))
            {
                switch (State)
                {
                case ShopStateType.Buy:
                case ShopStateType.Sell:
                    State = ShopStateType.Talk;
                    break;
                }
            }
        }
예제 #2
0
 public ShopState(Game game, GameStateManager manager)
     : base(game, manager)
 {
     State = ShopStateType.Talk;
 }