Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Check mouse
            MouseState currentMouseState = Mouse.GetState();

            if (currentMouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
            {
                Debug.WriteLine("Mouse click");
                //Map
                if (currentMouseState.Position.Y < 620)
                {
                    foreach (Lot lot in Map.OfType <Lot>())
                    {
                        if (lot.CollisionCheck().Contains(currentMouseState.Position))
                        {
                            Debug.WriteLine(lot.Value);
                            Debug.WriteLine(lot.Position.X.ToString() + " " + lot.Position.Y.ToString());
                            lot.Selected = true;
                            navbar.UpdateSelected(lot);
                        }
                        else
                        {
                            lot.Selected = false;
                            if (navbar.GetSelected() == lot)
                            {
                                navbar.UpdateSelected(null);
                            }
                        }
                    }
                }
                //UI begins at Y = 620
                if (navbar.buySellButton.CollisionCheck().Contains(currentMouseState.Position) && navbar.GetSelected() != null)
                {
                    Debug.WriteLine("buy sell clicked");
                    if (navbar.buySellButton.State == BuySellButtonState.Buy)
                    {
                        Lot selectedLot = navbar.GetSelected();
                        if (selectedLot.Value <= Money)
                        {
                            NotificationDisplayer.DisplayNotification("Bought!", 2);
                            Money                 -= selectedLot.Value;
                            selectedLot.Owner      = Player.Human;
                            selectedLot.Investment = selectedLot.Value;
                        }
                        else
                        {
                            NotificationDisplayer.DisplayNotification("Not enough money", 2);
                        }
                    }

                    if (navbar.buySellButton.State == BuySellButtonState.Sell)
                    {
                        NotificationDisplayer.DisplayNotification("Sold!", 2);
                        Lot selectedLot = navbar.GetSelected();
                        Money += selectedLot.Value;
                        selectedLot.Investment  = 0;
                        selectedLot.TotalIncome = 0;
                        selectedLot.Owner       = Player.AI;
                    }
                }


                if (navbar.BuildHouseButton.CollisionCheck().Contains(currentMouseState.Position) && navbar.GetSelected() != null)
                {
                    Debug.WriteLine("build house clicked");
                    Lot selectedLot = navbar.GetSelected();
                    int price       = economy.BuildHousePrice;
                    if (Money >= price && selectedLot.State != LotState.House)
                    {
                        NotificationDisplayer.DisplayNotification("House constructed!", 2);
                        Money -= price;
                        selectedLot.Investment += price;
                        selectedLot.Value      += price;
                        selectedLot.State       = LotState.House;
                    }
                    else if (Money < price)
                    {
                        NotificationDisplayer.DisplayNotification("Not enough money", 2);
                    }
                }

                if (navbar.BuildShopButton.CollisionCheck().Contains(currentMouseState.Position) && navbar.GetSelected() != null)
                {
                    Debug.WriteLine("build shop clicked");
                    Lot selectedLot = navbar.GetSelected();
                    int price       = economy.BuildShopPrice;
                    if (Money >= price && selectedLot.State != LotState.Shop)
                    {
                        NotificationDisplayer.DisplayNotification("Shop constructed!", 2);
                        Money -= price;
                        selectedLot.Investment += price;
                        selectedLot.Value      += price;
                        selectedLot.State       = LotState.Shop;
                    }
                    else if (Money < price)
                    {
                        NotificationDisplayer.DisplayNotification("Not enough money", 2);
                    }
                }

                if (navbar.BuildOfficeButton.CollisionCheck().Contains(currentMouseState.Position) && navbar.GetSelected() != null)
                {
                    Debug.WriteLine("build office clicked");
                    Lot selectedLot = navbar.GetSelected();
                    int price       = economy.BuildOfficePrice;
                    if (Money >= price && selectedLot.State != LotState.Office)
                    {
                        NotificationDisplayer.DisplayNotification("Office constructed!", 2);
                        Money -= price;
                        selectedLot.Investment += price;
                        selectedLot.Value      += price;
                        selectedLot.State       = LotState.Office;
                    }
                    else if (Money < price)
                    {
                        NotificationDisplayer.DisplayNotification("Not enough money", 2);
                    }
                }
            }
            previousMouseState = currentMouseState;
            navbar.Update();

            NotificationDisplayer.Update(gameTime);

            //Update time and prices
            float timePassed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            TimerRemaining -= timePassed;
            if (TimerRemaining <= 0)
            {
                Debug.WriteLine("next month!!");
                if (Month < 12)
                {
                    Month++;
                }
                else
                {
                    Month = 1;
                    Year++;
                }
                Debug.WriteLine(Month + "/" + Year);
                economy.UpdateLotPrices();
                TimerRemaining = TimerDelay;
            }



            //Exit game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }