Exemplo n.º 1
0
        public bool DebugPutRandomlyShip(Square.Mark type)
        {
            bool horizontal = false;
            int  starty, endy, startx, endx, initx, inity, initsize;

            if (random.Next(2) == 1)
            {
                horizontal = true;
            }
            ;
            int x = random.Next(10);
            int y = random.Next(10);

            initx = x;
            inity = y;
            int size = Square.GetOccupiedSquares(type);

            initsize = size;

            if (horizontal && initx + initsize > 9)
            {
                return(false);
            }
            if (!horizontal && inity + initsize > 9)
            {
                return(false);
            }

            if (horizontal)
            {
                //rysujemy na "wysokosci" x wzdluz y (po kazdym y)
                starty = endy = inity;
                startx = endx = initx;
                if (initx > 0)
                {
                    startx = initx - 1;
                }
                if (initx + size < 9)
                {
                    endx = initx + size + 1;
                }
                if (inity > 0)
                {
                    starty = inity - 1;
                }
                if (inity < 9)
                {
                    endy = inity + 1;
                }
                for (int cy = starty; cy < endy; cy++)
                {
                    for (int cx = startx; cx < endx; cx++)
                    {
                        if (!Board[cx, cy].IsAvailable())
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                //rysujemy na "wysokosci" y wzdluz x (po kazdym x)
                startx = endx = initx;
                starty = endy = inity;
                if (inity > 0)
                {
                    starty = starty - 1;
                }
                if (inity + size < 9)
                {
                    endy = inity + size + 1;
                }
                if (initx > 0)
                {
                    startx = initx - 1;
                }
                if (initx < 9)
                {
                    endx = initx + 1;
                }
                for (int cx = startx; cx < endx; cx++)
                {
                    for (int cy = starty; cy < endy; cy++)
                    {
                        if (!Board[cx, cy].IsAvailable())
                        {
                            return(false);
                        }
                    }
                }
            }
            if (horizontal)
            {
                for (int cx = initx; cx < initsize + initx; cx++)
                {
                    Board[cx, inity].SetMark(type);
                }
            }
            else
            {
                for (int cy = inity; cy < initsize + inity; cy++)
                {
                    Board[initx, cy].SetMark(type);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public bool DebugPutShip(Square.Mark type, bool isShipHorizontal, int[] position)
        {
            int positionX = position[1];
            int positionY = position[0];
            int initx     = positionX;
            int inity     = positionY;
            int size      = Square.GetOccupiedSquares(type);

            var startX = positionX;

            if (startX > 0)
            {
                startX--;
            }
            var startY = positionY;

            if (startY > 0)
            {
                startY--;
            }

            var endX = positionX;
            var endY = positionY;

            if (!isShipHorizontal)
            {
                endY += size - 1;
            }
            else
            {
                endX += size - 1;
            }
            // if end point is not the last coordinate check one past it.
            if (endY < 9)
            {
                endY++;
            }

            if (endX < 9)
            {
                endX++;
            }

            if (!IsInsideBoard(9, startX, startY, endX, endY))
            {
                return(false);
            }

            for (int cy = startY; cy <= endY; cy++)
            {
                for (int cx = startX; cx <= endX; cx++)
                {
                    if (!Board[cx, cy].IsAvailable())
                    {
                        return(false);
                    }
                }
            }

            if (isShipHorizontal)
            {
                for (int cx = initx; cx < size + initx; cx++)
                {
                    Board[cx, inity].SetMark(type);
                }
            }
            else
            {
                for (int cy = inity; cy < size + inity; cy++)
                {
                    Board[initx, cy].SetMark(type);
                }
            }
            return(true);
        }