示例#1
0
        public ShipPlacement(Battleship.ShipType type, int size, List <int[]> coords, bool horizontal)
        {
            this.type       = type;
            this.hp         = size;
            this.coords     = coords;
            this.horizontal = horizontal;

            if (coords.Count > 0)
            {
                startPos = (int[])coords [0].Clone();
            }
        }
示例#2
0
        private static ShipPlacement decideShipPlacement(bool horizontal, int lineIndex, int startIndex, int size, Battleship.ShipType type)
        {
            int[] startPos = new int[2];

            if (horizontal)
            {
                startPos [0] = startIndex;
                startPos[1]  = lineIndex;
            }
            else
            {
                startPos [0] = lineIndex;
                startPos [1] = startIndex;
            }

            int          xDir       = horizontal ? 1 : 0;
            int          yDir       = horizontal ? 0 : 1;
            List <int[]> tempCoords = new List <int[]> ();

            for (int i = 0; i < size; i++)
            {
                tempCoords.Add(new int[] { startPos [1], startPos [0] });                 // Wtf invert?!

                startPos [0] += xDir;
                startPos [1] += yDir;
            }

            return(new ShipPlacement(type, size, tempCoords, horizontal));
        }