예제 #1
0
        private void MakeGrid() //makes the grid for Ship Placement
        {
            //PlayArea.Children.Clear(); //clears the grid, just in case
            for (int x = 0; x < 10; x++)                                      //looping 10 times x
            {
                for (int y = 0; y < 10; y++)                                  //looping 10 times y
                {
                    Cell cell = new Cell();                                   //Creating cell object for binding
                    game.Player1.Field[x, y] = cell;                          //placing cell object in Player1's field
                    Button Cell = new Button();                               //creates button
                    Cell.Tapped         += SelectBoi;                         //adds on tap method SelectBoi
                    Cell.DataContext     = cell;                              // sets the cell as the datacontext of the button
                    Cell.Height          = 50;                                // i leik squares
                    Cell.Width           = 50;                                // i leik squares
                    Cell.BorderBrush     = new SolidColorBrush(Colors.Black); //give some definition
                    Cell.BorderThickness = new Thickness(2);                  // more of dat definition
                    Binding b = new Binding                                   //set binding
                    {
                        Path      = new PropertyPath("State"),                //get that state-based binding for color
                        Mode      = BindingMode.OneWay,                       // don't want two way communication. Communtication bad
                        Converter = con                                       //use my converter binding boi
                    };
                    Cell.SetBinding(Button.BackgroundProperty, b);            //Bind the binding to the bound button of bindingness. bind

                    PlayArea.Children.Add(Cell);                              //make sure the button is in the grid
                    Grid.SetColumn(Cell, y);                                  // gitcho place boiiiii place on y
                    Grid.SetRow(Cell, x);                                     //place on x
                }
            }
        }
예제 #2
0
        private void CreateGrids()
        {
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    //player Field
                    Button Cell = new Button();                               //creates button
                    Cell.DataContext     = game.Player1.Field[x, y];          // sets the cell as the datacontext of the button
                    Cell.Height          = 50;                                // i leik squares
                    Cell.Width           = 50;                                // i leik squares
                    Cell.BorderBrush     = new SolidColorBrush(Colors.Black); //give some definition
                    Cell.BorderThickness = new Thickness(2);                  // more of dat definition
                    Binding b = new Binding                                   //set binding
                    {
                        Path      = new PropertyPath("State"),                //get that state-based binding for color
                        Mode      = BindingMode.OneWay,                       // don't want two way communication. Communtication bad
                        Converter = con                                       //use my converter binding boi
                    };
                    Cell.SetBinding(Button.BackgroundProperty, b);            //Bind the binding to the bound button of bindingness. bind

                    Player1Area.Children.Add(Cell);                           //make sure the button is in the grid
                    Grid.SetColumn(Cell, y);                                  // gitcho place boiiiii place on y
                    Grid.SetRow(Cell, x);                                     //place on x

                    //AI Field
                    Button Cell2 = new Button();                               //creates button
                    Cell2.Tapped         += AISelectBoi;                       //adds on tap method SelectBoi
                    Cell2.DataContext     = game.Player2.Field[x, y];          // sets the cell as the datacontext of the button
                    Cell2.Height          = 50;                                // i leik squares
                    Cell2.Width           = 50;                                // i leik squares
                    Cell2.BorderBrush     = new SolidColorBrush(Colors.Black); //give some definition
                    Cell2.BorderThickness = new Thickness(2);                  // more of dat definition
                    Binding b2 = new Binding                                   //set binding
                    {
                        Path      = new PropertyPath("State"),                 //get that state-based binding for color
                        Mode      = BindingMode.OneWay,                        // don't want two way communication. Communtication bad
                        Converter = con                                        //use my converter binding boi
                    };
                    Cell2.SetBinding(Button.BackgroundProperty, b2);           //Bind the binding to the bound button of bindingness. bind

                    Player2Area.Children.Add(Cell2);                           //make sure the button is in the grid
                    Grid.SetColumn(Cell2, y);                                  // gitcho place boiiiii place on y
                    Grid.SetRow(Cell2, x);                                     //place on x
                }
            }
        } //TODO fix binding