Exemplo n.º 1
0
        private void LoadBoard()
        {
            CustomBasicList <string> tempList = new CustomBasicList <string>
            {
                "Carrier",
                "Battleship",
                "Cruiser",
                "Submarine",
                "Destroyer"
            };

            ShipList = new Dictionary <int, ShipInfoCP>();
            var loopTo = tempList.Count;
            int x;

            for (x = 1; x <= loopTo; x++)
            {
                var ThisShip = new ShipInfoCP();
                ThisShip.ShipName     = tempList[x - 1];
                ThisShip.PieceList    = new Dictionary <int, PieceInfoCP>();
                ThisShip.Visible      = true;
                ThisShip.ShipCategory = (EnumShipList)x; // i think
                ShipList.Add(ShipList.Count + 1, ThisShip);
            }
            x = 0;
            int y;
            int q = default;

            foreach (var tempShip in ShipList.Values)
            {
                x += 1;
                int z;
                if (x == 1)
                {
                    z = 5;
                }
                else if (x == 2)
                {
                    z = 4;
                }
                else if (x == 3)
                {
                    z = 3;
                }
                else
                {
                    z = 2;
                }
                var loopTo1 = z;
                for (y = 1; y <= loopTo1; y++)
                {
                    q += 1;
                    PieceInfoCP thisPiece = new PieceInfoCP();
                    thisPiece.Index = q;
                    tempShip.PieceList !.Add(tempShip.PieceList.Count + 1, thisPiece); //since i had to update the varible name, causing many problems.
                }
            }
        }
Exemplo n.º 2
0
        public void CreateShip(ShipInfoCP thisShip, BattleshipMainViewModel model)
        {
            DataContext = thisShip;
            Grid  thisGrid = new Grid();
            float labelSize;

            labelSize = 40; // can try 40.  can experiment though.
            Button thisBut = new Button();

            GridHelper.AddAutoRows(thisGrid, 1);
            int x;

            for (x = 1; x <= 5; x++)
            {
                GridHelper.AddPixelColumn(thisGrid, (int)labelSize);
            }
            GridHelper.AddPixelColumn(thisGrid, 100); // not sure
            thisBut.BorderBrush     = Brushes.White;
            thisBut.BorderThickness = new Thickness(2, 2, 2, 2);
            thisBut.FontWeight      = FontWeights.Bold;
            thisBut.FontSize        = 14;
            thisBut.Content         = thisShip.ShipName;
            IValueConverter thisConv;

            thisConv = new BooleanToVisibilityConverter();
            var thisBind = new Binding(nameof(ShipInfoCP.Visible));

            thisBind.Converter = thisConv;
            thisBut.SetBinding(VisibilityProperty, thisBind);
            if (thisShip.ShipCategory == EnumShipList.None)
            {
                throw new BasicBlankException("Can't be none");
            }

            thisBut.Name = nameof(BattleshipMainViewModel.ChooseShip);
            GamePackageViewModelBinder.ManuelElements.Add(thisBut); //try this one as well.
            thisBut.CommandParameter = thisShip.ShipCategory;
            thisBut.Margin           = new Thickness(5, 0, 0, 0);
            thisBind                    = new Binding(nameof(BattleshipMainViewModel.ShipSelected));
            thisBind.Source             = model; //try this for now.  otherwise, i have to create custom button control.
            thisConv                    = new ChooseShipConverter();
            thisBind.Converter          = thisConv;
            thisBind.ConverterParameter = thisShip.ShipCategory;
            thisBut.SetBinding(Button.BackgroundProperty, thisBind);
            GridHelper.AddControlToGrid(thisGrid, thisBut, 0, 5);
            x = 0;
            foreach (var thisPiece in thisShip.PieceList !.Values)
            {
                TextBlock thisText   = new TextBlock();
                Border    thisBorder = new Border();
                thisBorder.BorderBrush     = Brushes.Black;
                thisBorder.BorderThickness = new Thickness(2, 2, 2, 2);
                GridHelper.AddControlToGrid(thisGrid, thisBorder, 0, x);
                thisText.DataContext   = thisPiece;
                thisBorder.DataContext = thisPiece; // has to put here as well
                thisConv           = new ShipLabelConverter();
                thisBind           = new Binding(nameof(PieceInfoCP.DidHit));
                thisBind.Converter = thisConv;
                thisBorder.SetBinding(Border.BackgroundProperty, thisBind);
                thisText.FontWeight = FontWeights.Bold;
                thisText.FontSize   = 14;
                thisText.SetBinding(TextBlock.TextProperty, new Binding(nameof(PieceInfoCP.Location)));
                thisText.HorizontalAlignment = HorizontalAlignment.Center;
                thisText.VerticalAlignment   = VerticalAlignment.Center;
                GridHelper.AddControlToGrid(thisGrid, thisText, 0, x);
                x += 1;
            }
            Content = thisGrid;
        }
        public void CreateShip(ShipInfoCP thisShip, BattleshipMainViewModel model)
        {
            BindingContext = thisShip;
            Grid  thisGrid = new Grid();
            float labelSize;

            labelSize              = 40; // can try 40.  can experiment though.
            thisGrid.RowSpacing    = 0;
            thisGrid.ColumnSpacing = 0;
            Button thisBut = new Button();

            GridHelper.AddPixelRow(thisGrid, 50);
            int x;

            for (x = 1; x <= 5; x++)
            {
                GridHelper.AddPixelColumn(thisGrid, (int)labelSize);
            }
            GridHelper.AddPixelColumn(thisGrid, 120); // not sure
            thisBut.BorderColor    = Color.White;
            thisBut.BorderWidth    = 2;
            thisBut.FontAttributes = FontAttributes.Bold;
            thisBut.FontSize       = 14;
            thisBut.Text           = thisShip.ShipName;
            var thisBind = new Binding(nameof(ShipInfoCP.Visible));

            thisBut.SetBinding(IsVisibleProperty, thisBind);
            if (thisShip.ShipCategory == EnumShipList.None)
            {
                throw new BasicBlankException("Can't be none");
            }

            thisBut.SetName(nameof(BattleshipMainViewModel.ChooseShip));
            GamePackageViewModelBinder.ManuelElements.Add(thisBut); //try this one as well.
            thisBut.CommandParameter = thisShip.ShipCategory;
            thisBut.Margin           = new Thickness(5, 0, 0, 0);
            thisBind        = new Binding(nameof(BattleshipMainViewModel.ShipSelected));
            thisBind.Source = model;
            IValueConverter thisConv = new ChooseShipConverter();

            thisBind.Converter          = thisConv;
            thisBind.ConverterParameter = thisShip.ShipCategory;
            thisBut.SetBinding(BackgroundColorProperty, thisBind);
            GridHelper.AddControlToGrid(thisGrid, thisBut, 0, 5);
            x = 0;
            foreach (var thisPiece in thisShip.PieceList !.Values)
            {
                Label thisText = new Label();
                thisText.BindingContext = thisPiece;
                thisConv           = new ShipLabelConverter();
                thisBind           = new Binding(nameof(PieceInfoCP.DidHit));
                thisBind.Converter = thisConv;
                thisText.SetBinding(BackgroundColorProperty, thisBind);
                thisText.FontAttributes = FontAttributes.Bold;
                thisText.FontSize       = 14;
                thisText.TextColor      = Color.Black;
                thisText.SetBinding(Label.TextProperty, new Binding(nameof(PieceInfoCP.Location)));
                thisText.HorizontalTextAlignment = TextAlignment.Center;
                thisText.VerticalTextAlignment   = TextAlignment.Center;
                GridHelper.AddControlToGrid(thisGrid, thisText, 0, x);
                x += 1;
            }
            Content = thisGrid;
        }