Exemplo n.º 1
0
        // UI and game state
        private void AdvanceUI()
        {
            ComboBox corpList;

            // plan next move
            switch (game.State)
            {
            case AcquireGameStates.ExitGame:
                // show UI
                if (!game.CurrentPlayer.IsComputer)
                {
                    ExitGameGrid.Visibility = System.Windows.Visibility.Visible;
                }
                break;

            case AcquireGameStates.Done:
                // show the UI
                ExitGameGrid.Visibility     = System.Windows.Visibility.Collapsed;
                FinalDisplayGrid.Visibility = System.Windows.Visibility.Visible;

                // display the final results
                DisplayFinalResults(game.Players, game.Corporations);
                break;

            case AcquireGameStates.PlaceTile:
                // show UI
                ExitGameGrid.Visibility = System.Windows.Visibility.Collapsed;
                break;

            case AcquireGameStates.BuyShares:
                // populate the pull downs for the shares to purchase

                // hide UI
                SellGrid.Visibility       = System.Windows.Visibility.Collapsed;
                ChooseCorpGrid.Visibility = System.Windows.Visibility.Collapsed;

                if (!game.CurrentPlayer.IsComputer)
                {
                    ComboBox           buylist;
                    List <CorpNames>[] corps;

                    // show the UI
                    BuyGrid.Visibility = System.Windows.Visibility.Visible;

                    // populate the information
                    corps = game.SharesToBuy;
                    for (int i = 0; i < corps.Length; i++)
                    {
                        buylist = GetItem <ComboBox>(Lbuycorp[i]);
                        buylist.Items.Clear();
                        buylist.Items.Add(CorpNames.NA);
                        buylist.SelectedIndex = 0;
                        foreach (CorpNames corp in corps[i])
                        {
                            buylist.Items.Add(corp);
                        }
                    }
                }
                break;

            case AcquireGameStates.ChooseCorp:
                // populate the pull down with avaliable corporations
                if (!game.CurrentPlayer.IsComputer)
                {
                    // show UI
                    ChooseCorpGrid.Visibility = System.Windows.Visibility.Visible;

                    // display information
                    corpList = GetItem <ComboBox>(Lnewcorp);
                    corpList.Items.Clear();
                    foreach (CorpNames corp in game.AvailableCorporations)
                    {
                        corpList.Items.Add(corp);
                    }
                    corpList.SelectedIndex = 0;
                }
                break;

            case AcquireGameStates.ChooseParentCorp:
                // populate the pull down with avaliable corporations for the merger
                if (!game.CurrentPlayer.IsComputer)
                {
                    // show UI
                    ChooseCorpGrid.Visibility = System.Windows.Visibility.Visible;

                    // display information
                    corpList = GetItem <ComboBox>(Lnewcorp);
                    corpList.Items.Clear();
                    foreach (CorpNames corp in game.ParentCorporations)
                    {
                        corpList.Items.Add(corp);
                    }
                    corpList.SelectedIndex = 0;
                }
                break;

            case AcquireGameStates.NextTurn:
                // turn off UI
                BuyGrid.Visibility = System.Windows.Visibility.Collapsed;

                // end turn
                game.EndTurn();

                if (game.State == AcquireGameStates.ExitGame && !game.CurrentPlayer.IsComputer)
                {
                    ExitGameGrid.Visibility = System.Windows.Visibility.Visible;
                }
                break;

            case AcquireGameStates.SellShares:
                // NOTE! This section is reintrant... it is called multiple times to get answers from everyone

                // hide UI
                TradeGrid.Visibility = System.Windows.Visibility.Collapsed;

                if (!game.SharesToSell.Player.IsComputer)
                {
                    // show UI
                    SellGrid.Visibility = System.Windows.Visibility.Visible;

                    // display user information
                    GetItem <Label>(Lsellname).Content  = game.SharesToSell.Player.Name;
                    GetItem <Label>(Lsellcorp).Content  = game.SharesToSell.Corporation;
                    GetItem <Label>(Lsellprice).Content = "$" + game.SharesToSell.Price;
                    GetItem <ComboBox>(Lselllist).Items.Clear();
                    for (int shares = 0; shares <= game.SharesToSell.Player.Shares(game.SharesToSell.Corporation); shares++)
                    {
                        GetItem <ComboBox>(Lselllist).Items.Add(shares);
                    }
                    GetItem <ComboBox>(Lselllist).SelectedIndex = 0;
                }

                Refresh(game.SharesToSell.Player);
                break;

            case AcquireGameStates.TradeShares:
                // NOTE! This section is reintrant... it is called multiple times to get answers from everyone

                // hide UI
                ChooseCorpGrid.Visibility = System.Windows.Visibility.Collapsed;

                if (!game.SharesToTrade.Player.IsComputer)
                {
                    // show UI
                    TradeGrid.Visibility = System.Windows.Visibility.Visible;

                    // display the user information
                    GetItem <Label>(Ltradename).Content      = game.SharesToTrade.Player.Name;
                    GetItem <Label>(Ltradecorp).Content      = game.SharesToTrade.MergedCorp + "/" + game.SharesToTrade.ParentCorp;
                    GetItem <Label>(Ltraderes).Content       = "";
                    GetItem <Label>(Ltradebonuskind).Content = game.SharesToTrade.BonusKind;
                    GetItem <Label>(Ltradebonus).Content     = "$" + game.SharesToTrade.Bonus;
                    GetItem <ComboBox>(Ltradelist).Items.Clear();
                    for (int shares = 0; shares <= game.SharesToTrade.Player.Shares(game.SharesToTrade.MergedCorp) && (shares / 2) <= game[game.SharesToTrade.ParentCorp].Shares; shares += 2)
                    {
                        GetItem <ComboBox>(Ltradelist).Items.Add(shares);
                    }
                    GetItem <ComboBox>(Ltradelist).SelectedIndex = 0;
                }

                Refresh(game.SharesToTrade.Player);
                break;
            }

            if (game.State != AcquireGameStates.SellShares && game.State != AcquireGameStates.TradeShares)
            {
                // update the board
                Refresh(game.CurrentPlayer);
            }
        }