Exemple #1
0
        private void flipGrid(PlayerShip ship)
        {
            Grid GridToTurn = ((Grid)(ship.ImageToShow));

            RowDefinitionCollection    rdc = GridToTurn.RowDefinitions;
            ColumnDefinitionCollection cdc = GridToTurn.ColumnDefinitions;

            if (!IsHorizontal)
            {
                double temp = GridToTurn.Width;
                GridToTurn.Width  = GridToTurn.Height;
                GridToTurn.Height = temp;

                foreach (RowDefinition rd in rdc)
                {
                    ColumnDefinition cd = new ColumnDefinition();
                    cd.Width = new GridLength(10, GridUnitType.Star);
                    cdc.Add(cd);
                }

                for (int i = 0; i < GridToTurn.Children.Count; i++)
                {
                    Grid.SetColumn(GridToTurn.Children[i], i);
                    Grid.SetRow(GridToTurn.Children[i], 0);
                }

                while (rdc.Count > 0)
                {
                    rdc.RemoveAt(rdc.Count - 1);
                }
            }
            else
            {
                double temp = GridToTurn.Height;
                GridToTurn.Height = GridToTurn.Width;
                GridToTurn.Width  = temp;

                foreach (ColumnDefinition cd in cdc)
                {
                    RowDefinition rd = new RowDefinition();
                    rd.Height = new GridLength(10, GridUnitType.Star);
                    rdc.Add(rd);
                }

                for (int i = 0; i < GridToTurn.Children.Count; i++)
                {
                    Grid.SetRow(GridToTurn.Children[i], i);
                    Grid.SetColumn(GridToTurn.Children[i], 0);
                }

                while (cdc.Count > 0)
                {
                    cdc.RemoveAt(cdc.Count - 1);
                }
            }

            IsHorizontal = !IsHorizontal;
        }
Exemple #2
0
        public BattleShipUI()
        {
            InitializeComponent();
            pb = new PlayingBoard(this);
            pb.Load();
            rb = new RadarBoard(this);
            rb.Load();
            p  = new HumanPlayer(rb);
            dp = new NotSmartPlayer(pb);

            Grid[] tempShips = { ShipSize30, ShipSize31, ShipSize2, ShipSize4, ShipSize5 };
            for (int i = 0; i < tempShips.Length; i++)
            {
                originalShipPositionX[i] = Canvas.GetLeft(tempShips[i]);
                originalShipPositionY[i] = Canvas.GetTop(tempShips[i]);
                allShips[i] = new PlayerShip(tempShips[i].RowDefinitions.Count, pb, tempShips[i], originalShipPositionX[i], originalShipPositionY[i], LayoutRoot, this);
            }
        }