コード例 #1
0
        //wyłącza pola pod stawianym statkiem
        private void DisableSquaresUnderShip(ShipInfo ship)
        {
            int x = ship.x - 1;
            int y = ship.y - 1;

            for (int i = 0; i < ship.size; i++)
            {
                leftBoard[x, y].IsEnabled = false;
                if (ship.direction == 'H')
                {
                    x++;
                }
                else if (ship.direction == 'V')
                {
                    y++;
                }
                else
                {
                    throw new Exception("Invalid ship direction!");                     //nie powinno nigdy wystąpić!
                }
            }
        }
コード例 #2
0
 //usuwa statek z planszy
 private void DeleteShip(Grid grid, ShipInfo ship)
 {
     grid.Children.Remove(ship.drawObj);
 }
コード例 #3
0
        private void Square_Click(object sender, RoutedEventArgs e)
        {
            Button square = (Button)sender;
            int    x      = (int)square.GetValue(Grid.ColumnProperty);
            int    y      = (int)square.GetValue(Grid.RowProperty);

            //MessageBox.Show("Kliknięto pole (" + x + "," + y + ").");
            if (mode == Mode.PLANNER && selectedShip > 0 && selectedDirection != '0')
            {
                ShipInfo ship = new ShipInfo {
                    size      = selectedShip,
                    x         = x,
                    y         = y,
                    direction = selectedDirection,
                    sunk      = false
                };
                if (DllInterface.placeShip(ship.size, ship.x - 1, ship.y - 1, ship.direction) == true)
                {
                    DrawShip((Grid)square.Parent, ship);
                    switch (ship.size)
                    {
                    case 5:
                        PlannerCount5.Content = 1 - ++ship5placed;
                        if (ship5placed == 1)
                        {
                            selectedShip             = 0;
                            PlannerLabel5.FontWeight = FontWeights.Light;
                        }
                        break;

                    case 4:
                        PlannerCount4.Content = 2 - ++ship4placed;
                        if (ship4placed == 2)
                        {
                            selectedShip             = 0;
                            PlannerLabel4.FontWeight = FontWeights.Light;
                        }
                        break;

                    case 3:
                        PlannerCount3.Content = 3 - ++ship3placed;
                        if (ship3placed == 3)
                        {
                            selectedShip             = 0;
                            PlannerLabel3.FontWeight = FontWeights.Light;
                        }
                        break;

                    case 2:
                        PlannerCount2.Content = 4 - ++ship2placed;
                        if (ship2placed == 4)
                        {
                            selectedShip             = 0;
                            PlannerLabel2.FontWeight = FontWeights.Light;
                        }
                        break;

                    default:
                        throw new Exception("Incorrect ship size");
                    }
                    if (ship5placed == 1 && ship4placed == 2 && ship3placed == 3 && ship2placed == 4)
                    {
                        ButtonPlannerConfirm.IsEnabled = true;
                    }
                }
            }
            else if (mode == Mode.GAME)
            {
                square.IsEnabled = false;
                shotPoint        = new Point()
                {
                    x = x - 1,
                    y = y - 1
                };
                dllInterface.waitingForCoords.Set();
            }
        }