Exemple #1
0
 private void ButtonPlannerRandom_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show("Not tested!");
     DllInterface.fillRandom();
     BoardPlanner.Visibility = Visibility.Collapsed;
     rightGrid.Visibility    = Visibility.Visible;
     setAllButtons(leftGrid, false);
     InitializeBoard(rightGrid, true);
     dllInterface.waitingInPlannerMode.Set();
 }
Exemple #2
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();
            }
        }
Exemple #3
0
 //event handlery
 private void StartButton_Click(object sender, RoutedEventArgs e)
 {
     dllInterface    = new DllInterface(this);
     Menu.Visibility = Visibility.Collapsed;
     dllInterface.initAndRun();
 }