Esempio n. 1
0
        // Ожидание хода противника. Прослушивание данных от сервера
        private void waitForShot()
        {
            string shot = "";

            try {
                shot = receiveData();
            }
            catch {
                MessageBox.Show("Проблемы с сервером");
                this.Close();
            }
            string[] parameters = shot.Split(':');
            string[] indexes    = parameters[1].Split('_');
            int      i          = Convert.ToInt32(indexes[0]);
            int      j          = Convert.ToInt32(indexes[1]);
            Cell     cell       = startfield.getCellByCoordinate(i - 600, j);
            int      state      = cell.getState();
            Graphics g          = CreateGraphics();

            if (state == 2)
            {
                cell.setState(3);
                cell.draw(g);
                sendData("true");
                if (startfield.checkFinishSelf())
                {
                    MessageBox.Show("Поражение " + this.Text.ToString());
                    this.Close();
                }
                waitForShot();
            }
            else
            {
                cell.setState(1);
                cell.draw(g);
                //this.Refresh();
                sendData("false");
                is_your_turn      = true;
                WhoTurnLabel.Text = "Сейчас ваш ход";
                this.Refresh();
            }
        }
Esempio n. 2
0
        // Проверка остатка кораблей для расстановки
        private void ShipRemaining()
        {
            Reset();

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Cell cell = startfield.getCell(i, j);
                    if ((cell.getState() == 2) && (cell.getTag() != 1))
                    {
                        // Случай вправо
                        cell.setTag(1);
                        Cell cell1 = startfield.getCell(i + 1, j);

                        if ((cell1 != null) && (cell1.getState() == 2))
                        {
                            cell1.setTag(1);
                            Cell cell2 = startfield.getCell(i + 2, j);

                            if ((cell2 != null) && (cell2.getState() == 2))
                            {
                                cell2.setTag(1);
                                Cell cell3 = startfield.getCell(i + 3, j);
                                if ((cell3 != null) && (cell3.getState() == 2))
                                {
                                    cell3.setTag(1);
                                    fds--;
                                }
                                else
                                {
                                    tds--;
                                }
                            }
                            else
                            {
                                dds--;
                            }
                        }
                        else
                        {
                            // Случай вниз
                            cell1 = startfield.getCell(i, j + 1);
                            if ((cell1 != null) && cell1.getState() == 2)
                            {
                                cell1.setTag(1);
                                Cell cell2 = startfield.getCell(i, j + 2);

                                if ((cell2 != null) && (cell2.getState() == 2))
                                {
                                    cell2.setTag(1);
                                    Cell cell3 = startfield.getCell(i, j + 3);
                                    if ((cell3 != null) && cell3.getState() == 2)
                                    {
                                        cell3.setTag(1);
                                        fds--;
                                    }
                                    else
                                    {
                                        tds--;
                                    }
                                }
                                else
                                {
                                    dds--;
                                }
                            }
                            else
                            {
                                sds--;
                            }
                        }
                    }
                }
            }
            Set_labels();
        }