Ejemplo n.º 1
0
        private static bool PlacingSuccessful(BattlefieldMap map)
        {
            Gameboard gameboard = new Gameboard((byte)map.Width, (byte)map.Height);

            try
            {
                gameboard.PlaceShips(map.ConvertShipPositionsForEngine());
            }
            catch (GameOverException)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static ShipPosition[] GenerateInitialShipPositions(GameSettings gs)
        {
            BattlefieldMap battlefieldMap = new BattlefieldMap(gs);
            Random         random         = new Random();

            foreach (ShipType shipType in battlefieldMap.ShipTypes)
            {
                bool flag;
                do
                {
                    battlefieldMap.Ships.Add(new ShipPosition(shipType, new Position((byte)random.Next(0, battlefieldMap.Width), (byte)random.Next(0, battlefieldMap.Height)), (Orientation)random.Next(0, 4)));
                    flag = BattlefieldMap.PlacingSuccessful(battlefieldMap);
                    bool flag2 = !flag;
                    if (flag2)
                    {
                        battlefieldMap.Ships.RemoveAt(battlefieldMap.Ships.Count - 1);
                    }
                }while (!flag);
            }
            return(battlefieldMap.ConvertShipPositionsForEngine());
        }