コード例 #1
0
        // when i = 0:you, i=1:left, i=2:right
        // The buttons appear for you when you have special resources. If this is
        // zero then you don't need buttons and none appear.
        // The buttons for the left and right on the other hand will appear when any
        // COMBINED(special and base) resource is > 0.
        // This is so you can choose which resource to add from yourself and which
        // resource to buy from your neighbor.

        private void createButtons()
        {
            int skip    = 0;
            int counter = 0;

            int[] currentTotals = new int[] { 0, 0, 0, 0, 0, 0, 0 };

            for (int i = 0; i < 3; i++)
            {
                // This is you
                if (i == 0)
                {
                    //currentTotals = rm.SpecialResourceArray(rc.getPlayerName());
                    currentTotals = manager.SpecialResourceArray(you);
                }

                // This is Left
                if (i == 1)
                {
                    currentTotals = manager.tradableArray(you, 1);
                }

                // This is Right
                if (i == 2)
                {
                    currentTotals = manager.tradableArray(you, 2);
                }

                for (int j = 0; j < 7; j++)
                {
                    counter++;

                    Button b = new Button();
                    b.Content = "+";
                    b.Name    = "B" + (string)counter.ToString();//You: 1-7, Left:8-14, Right:15-21
                    b.Width   = 25;
                    b.Height  = 27;
                    b.Click  += new RoutedEventHandler(buyButton_Click);
                    Grid.SetColumn(b, j);
                    Grid.SetRow(b, (i + 1 + skip));

                    if (currentTotals[j] > 0)
                    {
                        // Console.WriteLine("Player #: " + i + " In index: " + j + " value is: " + currentTotals[j]);
                        b.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        b.Visibility = Visibility.Hidden;
                    }
                    mainGrid.Children.Add(b);
                }
                skip += 1;
            }
        }