Example #1
0
        public void ArrangeShips(int complexity)
        {
            shiplist = new List<Ship>();// по делу оно не тут должно быть
            Random rnd = new Random();
            Ship shp;
                foreach (var value in Enum.GetValues(typeof(NumShip)))
                {
                    if ((NumShip)value == NumShip.empty)
                        break;
                    if ((NumShip)value == NumShip.single_ship_1)
                        EmptyCount(complexity);
                    while (true)
                    {
                        shp = new Ship((NumShip)value, (Direction)rnd.Next(4), new Square((NumShip)value, ShipState.clear, (int)rnd.Next(10), (int)rnd.Next(10)));
                        if (CheckingSpace(shp))
                        {
                            shiplist.Add(shp);
                            for (int i = 0; i < shp.coordinateslist.Count; i++)
                                squareArr[shp.coordinateslist[i].x, shp.coordinateslist[i].y] = shp.coordinateslist[i];
                                break;

                        }
                    }
                }
        }
        private void GoOverShip(Ship ship, ref int[,] grille)
        {
            foreach (var square in ship.coordinateslist)
            {
                ourbtnlist[square.x * 10 + square.y].Background = new SolidColorBrush(Colors.White);

                if (!((square.x - 1) < 0 || square.y < 0 || (square.x - 1) > 9 || square.y > 9))
                    ourbtnlist[(square.x - 1) * 10 + square.y].Background = new SolidColorBrush(Colors.White);
                if (!((square.x + 1) < 0 || square.y < 0 || (square.x + 1) > 9 || square.y > 9))
                    ourbtnlist[(square.x + 1) * 10 + square.y].Background = new SolidColorBrush(Colors.White);
                if (!(square.x < 0 || (square.y - 1) < 0 || square.x > 9 || (square.y - 1) > 9))
                    ourbtnlist[square.x * 10 + (square.y - 1)].Background = new SolidColorBrush(Colors.White);
                if (!(square.x < 0 || (square.y + 1) < 0 || square.x > 9 || (square.y + 1) > 9))
                    ourbtnlist[square.x * 10 + (square.y + 1)].Background = new SolidColorBrush(Colors.White);

                if (!((square.x - 1) < 0 || (square.y - 1) < 0 || (square.x - 1) > 9 || (square.y - 1) > 9))
                    ourbtnlist[(square.x - 1) * 10 + (square.y - 1)].Background = new SolidColorBrush(Colors.White);
                if (!((square.x + 1) < 0 || (square.y + 1) < 0 || (square.x + 1) > 9 || (square.y + 1) > 9))
                    ourbtnlist[(square.x + 1) * 10 + (square.y + 1)].Background = new SolidColorBrush(Colors.White);
                if (!((square.x + 1) < 0 || (square.y - 1) < 0 || (square.x + 1) > 9 || (square.y - 1) > 9))
                    ourbtnlist[(square.x + 1) * 10 + (square.y - 1)].Background = new SolidColorBrush(Colors.White);
                if (!((square.x - 1) < 0 || (square.y + 1) < 0 || (square.x - 1) > 9 || (square.y + 1) > 9))
                    ourbtnlist[(square.x - 1) * 10 + (square.y + 1)].Background = new SolidColorBrush(Colors.White);

            }
            foreach (var ddd in ship.coordinateslist)
                ourbtnlist[ddd.x * 10 + ddd.y].Background = new SolidColorBrush(Colors.Gray);

            /*foreach (var ourbtn in ourbtnlist)
                if(ourbtn.Background == )*/
        }
 private void GoFindHierShip(Ship ship, ref int[,] grille)
 {
     throw new NotImplementedException();
 }
Example #4
0
        public bool CheckingSpace(Ship s)
        {
            int pre_x = -1;
            int pre_y = -1;
            foreach (var value in s.coordinateslist)
            {

                if (!(value.x < 0 || value.x > 9 || value.y < 0 || value.y > 9))
                {
                    if (squareArr[value.x, value.y].nship != 0)
                        return false;
                }
                else return false;

                if (!(value.x - 1 < 0 || value.x - 1 > 9 || value.y < 0 || value.y > 9))
                {
                    if (value.x - 1 != pre_x && value.y != pre_y)
                        if (squareArr[value.x - 1, value.y].nship != 0)
                            return false;
                }

                if (!(value.x + 1 < 0 || value.x + 1 > 9 || value.y < 0 || value.y > 9))
                {
                    if (value.x + 1 != pre_x && value.y != pre_y)
                        if (squareArr[value.x + 1, value.y].nship != 0)
                            return false;
                }

                if (!(value.x < 0 || value.x > 9 || value.y + 1 < 0 || value.y + 1 > 9))
                {
                    if (value.x != pre_x && value.y + 1 != pre_y)
                        if (squareArr[value.x, value.y + 1].nship != 0)
                            return false;
                }

                if (!(value.x < 0 || value.x > 9 || value.y - 1 < 0 || value.y - 1 > 9))
                {
                    if (value.x != pre_x && value.y - 1 != pre_y)
                        if (squareArr[value.x, value.y - 1].nship != 0)
                            return false;
                }

                if (!(value.x - 1 < 0 || value.x - 1 > 9 || value.y - 1 < 0 || value.y - 1 > 9))
                {
                    if (value.x - 1 != pre_x && value.y - 1 != pre_y)
                        if (squareArr[value.x - 1, value.y - 1].nship != 0)
                            return false;
                }

                if (!(value.x + 1 < 0 || value.x + 1 > 9 || value.y + 1 < 0 || value.y + 1 > 9))
                {
                    if (value.x + 1 != pre_x && value.y + 1 != pre_y)
                        if (squareArr[value.x + 1, value.y + 1].nship != 0)
                            return false;
                }

                if (!(value.x - 1 < 0 || value.x - 1 > 9 || value.y + 1 < 0 || value.y + 1 > 9))
                {
                    if (value.x - 1 != pre_x && value.y + 1 != pre_y)
                        if (squareArr[value.x - 1, value.y + 1].nship != 0)
                            return false;
                }

                if (!(value.x + 1 < 0 || value.x + 1 > 9 || value.y - 1 < 0 || value.y - 1 > 9))
                {
                    if (value.x + 1 != pre_x && value.y - 1 != pre_y)
                        if (squareArr[value.x + 1, value.y - 1].nship != 0)
                            return false;
                }

                pre_x = value.x;
                pre_y = value.y;

            }
               return true;
        }