Ejemplo n.º 1
0
        public void PlaceShip(Coordinate startCoordinate, Coordinate endCoordinate)
        {
            // Validate ship location and shape
            if (IsCoordinateOutsideBoard(startCoordinate) || IsCoordinateOutsideBoard(endCoordinate))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (!_shapeValidator.IsValidShapeForShip(startCoordinate, endCoordinate))
            {
                throw new NotValidShapeForShipException();
            }
            var coords = GetShipCoordinates(startCoordinate, endCoordinate);

            // Validate if location is not empty. Not required in our simple exercise, but for a real solution
            if (!IsShipPlaceEmpty(coords))
            {
                throw new ShipPlaceIsNotEmptyException();
            }

            /* all validation passes then
             * 1 - mark all board cells as BoardCellStatus.Ship
             * 2 - and add it to the ship list */
            Array.ForEach(coords, x => _board[x.Row, x.Column] = BoardCellStatus.Ship);
            Ships.Add(new Ship(coords));
        }
Ejemplo n.º 2
0
        public SquadListShip AddShip(GenericShip ship)
        {
            SquadListShip newShip = new SquadListShip(ship, this);

            Ships.Add(newShip);
            return(newShip);
        }
Ejemplo n.º 3
0
        public void AddShipToBoard(int xStartCoordinate, int yStartCoordinate, int length, ShipAlignment alignment)
        {
            try
            {
                xStartCoordinate.ValidateXStartCoordinate();
                yStartCoordinate.ValidateYStartCoordinate();
                length.ValidateLength();

                var ship = new Ship(xStartCoordinate, yStartCoordinate, length, alignment);
                Ships.Add(ship);

                Board.AddShipToBoard(ship);
            }
            catch (XCoordOutOfBoundsException exception)
            {
                Console.WriteLine(exception.Message);
            }
            catch (YCoordOutOfBoundsException exception)
            {
                Console.WriteLine(exception.Message);
            }
            catch (LengthOutOfBoundsException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
Ejemplo n.º 4
0
        private void InitializeShips()
        {
            for (var i = 0; i < Options.OPTIONS["Carrier amount"]; i++)
            {
                Ships.Add(new Carrier());
            }

            for (var i = 0; i < Options.OPTIONS["Battleship amount"]; i++)
            {
                Ships.Add(new BattleShip());
            }

            for (var i = 0; i < Options.OPTIONS["Submarine amount"]; i++)
            {
                Ships.Add(new Submarine());
            }

            for (var i = 0; i < Options.OPTIONS["Cruiser amount"]; i++)
            {
                Ships.Add(new Cruiser());
            }

            for (var i = 0; i < Options.OPTIONS["Patrol amount"]; i++)
            {
                Ships.Add(new Patrol());
            }
        }
Ejemplo n.º 5
0
        public void UpdateInventoryCategories()
        {
            Elixirs.Clear();
            Ships.Clear();
            Weapons.Clear();
            Armor.Clear();

            foreach (var gameItemQuantity in _inventory)
            {
                if (gameItemQuantity.GameObject is Weapons)
                {
                    Weapons.Add(gameItemQuantity);
                }
                if (gameItemQuantity.GameObject is Armor)
                {
                    Armor.Add(gameItemQuantity);
                }
                if (gameItemQuantity.GameObject is Ship)
                {
                    Ships.Add(gameItemQuantity);
                }
                if (gameItemQuantity.GameObject is Elixirs)
                {
                    Elixirs.Add(gameItemQuantity);
                }
            }
        }
Ejemplo n.º 6
0
 public void LoadShips(IEnumerable <long> shipIds)
 {
     shipIds = shipIds.Distinct().Where(w => !Characters.Select(s => s.Id).ToList().Contains(w));
     shipIds.ToList().ForEach(f =>
                              Ships.Add(_mapper.Map <ItemSummary>(
                                            new Devpack.ESI.Models.Universe.ItemType(f))));
 }
Ejemplo n.º 7
0
        public IntVector2 AddShipToFreePosition(Ship ship)
        {
            Ships.Add(ship);
            var coordinates = PlayerArena.AddShipToFreePosition(ship);

            return(coordinates);
        }
        public override void PlaceShip(int size, string tag)
        {
            var loop = true;

            while (loop)
            {
                var direction = GetDirection();
                var coords    = GetShipCoordinates();
                var ship      = new Ship(coords, direction, size, tag);
                if (ship.IsHorizontal && (ship.Size + coords.Row) > 10)
                {
                    continue;
                }
                else if ((!ship.IsHorizontal) && (ship.Size + coords.Column) > 10)
                {
                    continue;
                }
                else if (IsCoordinateTaken(ship))
                {
                    continue;
                }
                else
                {
                    Ships.Add(ship);
                    foreach (var coordinate in ship.ShipCoordinates)
                    {
                        OwnBoard.Board[coordinate.Row][coordinate.Column].Symbol = tag;
                    }
                    loop = false;
                }
            }
        }
Ejemplo n.º 9
0
        public Ship AddShip(int lenght, Int2 position)
        {
            Ship s = new Ship(lenght, position, this, DateTime.Now.Millisecond);

            Ships.Add(s);
            //GenerateCollisionsMap();
            return(s);
        }
 public void AddShips()
 {
     Ships.Add(new Ship("H", 5, Pos, ConsoleColor.Red));
     Ships.Add(new Ship("S", 4, Pos, ConsoleColor.Blue));
     Ships.Add(new Ship("D", 3, Pos, ConsoleColor.Yellow));
     Ships.Add(new Ship("U", 3, Pos, ConsoleColor.Green));
     Ships.Add(new Ship("P", 2, Pos, ConsoleColor.Magenta));
 }
Ejemplo n.º 11
0
        private void Main_Load(object sender, EventArgs e)
        {
            TerrainArea.Width = Main.ActiveForm.Width;
            this.KeyPreview   = true;
            this.KeyPress    += new KeyPressEventHandler(Main_KeyPress);
            Ship newShip = Ships.Add(Ships.ShipTypes.Defender);

            this.Controls.Add(newShip);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add a row of enemies to the block
        /// </summary>
        /// <param name="width">Width of the row</param>
        /// <param name="nbShips">Number of ships</param>
        /// <param name="lives">Amount of lives ship spawn with</param>
        /// <param name="im">Image to illustrate the ship in the row </param>
        public void AddLine(int width, int nbShips, int lives, Bitmap im)
        {
            for (int i = 0; i < nbShips; i++)
            {
                Ships.Add(new SpaceShip(im, new Vecteur2D(Position.x + i * (width / nbShips), Position.y + Size.Height), lives));
            }

            Size.Height += im.Height + 10;
            Size.Width   = width;
        }
Ejemplo n.º 13
0
        private void AddShipToBoard(Ship ship)
        {
            Random rand         = new Random(Guid.NewGuid().GetHashCode());
            int    allowedTries = 5;

            while (allowedTries > 0)
            {
                var startColumn = rand.Next(0, GameBoard.BoardWidth);
                var startRow    = rand.Next(0, GameBoard.BoardHeight);

                int endRow = startRow, endColumn = startColumn;
                var orientation = rand.Next(1, 101) % 2;

                List <int> panelIndexes = new List <int>();
                if (orientation == 0)
                {
                    for (int i = 1; i < ship.Width; i++)
                    {
                        endRow++;
                    }
                }
                else
                {
                    for (int i = 1; i < ship.Width; i++)
                    {
                        endColumn++;
                    }
                }

                // cannot place battleship outside the board.
                if (endColumn > GameBoard.BoardHeight || endRow > GameBoard.BoardWidth)
                {
                    allowedTries--;
                    continue;
                }
                var panelsToUse = GameBoard.Panels.Range(startRow, startColumn, endRow, endColumn);
                if (panelsToUse.Any(x => x.IsOccupied))
                {
                    allowedTries--;
                    continue;
                }

                foreach (var panel in panelsToUse)
                {
                    panel.PanelType = PanelType.Occupied;
                }
                ship.PanelIds.AddRange(panelsToUse.Select(s => s.PanelId).ToList());
                break;
            }
            // able to find panels to fit the ship on the board.
            if (allowedTries > 0)
            {
                Ships.Add(ship);
            }
        }
Ejemplo n.º 14
0
 public void AddShips(int strength, int count)
 {
     if (Ships.ContainsKey(strength))
     {
         Ships[strength] += count;
     }
     else
     {
         Ships.Add(strength, count);
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Places a new ship on the board, or changes an existing ship.
 /// </summary>
 /// <param name="type">The type of ship to place (unique identifier).</param>
 /// <param name="data">Metadata pertaining to this ship.</param>
 public void PlaceShip(ShipType type, Ship data)
 {
     if (Ships.ContainsKey(type))
     {
         Ships[type] = data;
     }
     else
     {
         Ships.Add(type, data);
     }
 }
Ejemplo n.º 16
0
 public void AddShip(Ship ship)
 {
     if (Ships == null)
     {
         Ships = new List <Ship>();
     }
     Ships.Add(ship);
     ShipCount++;
     Size           += ship.Size;
     FlotillaHealth += ship.Health;
 }
Ejemplo n.º 17
0
        private void GuiUpdater(string msg)
        {
            App.Current.Dispatcher.Invoke(
                () => {
                // ShipId@recorder,20000,25000|DVDPlayer,10000,20000|PCs,50000,200000
                string[] entries   = msg.Split('@');
                string[] recCargos = entries[1].Split('|');

                ObservableCollection <CargoVm> shipCargos = new ObservableCollection <CargoVm>();
                int weightSum = 0;

                for (int i = 0; i < recCargos.Length; i++)
                {
                    string[] splittedCargoInf = recCargos[i].Split(',');
                    weightSum += int.Parse(splittedCargoInf[2]);
                    shipCargos.Add(new CargoVm()
                    {
                        Name   = splittedCargoInf[0],
                        Amount = int.Parse(splittedCargoInf[1]),
                        Weight = int.Parse(splittedCargoInf[2])
                    });
                }

                bool newID = true;
                foreach (var item in Ships)
                {
                    if (item.ShipID == entries[0])
                    {
                        foreach (var cargo in shipCargos)
                        {
                            item.Cargos.Add(cargo);
                        }
                        item.WeightSum += weightSum;
                        newID           = false;
                    }
                }

                if (newID)
                {
                    Ships.Add(new ShipVm()
                    {
                        ShipID    = entries[0],
                        Cargos    = shipCargos,
                        WeightSum = weightSum
                    });
                }

                RaisePropertyChanged("Ships");
                RaisePropertyChanged("SelectedShip");
                RaisePropertyChanged("SelectedShip.WeightSum");
                RaisePropertyChanged("Ships.WeightSum");
            });
        }
Ejemplo n.º 18
0
        public void VoegSchipToe(Ship ship)
        {
            if (Ships.Count < 2)
            {
                Ships.Add(ship);
                ship.vloot = this;
            }

            else
            {
                Console.WriteLine($"Vloot: {Name} is vol.\n");
            }
        }
Ejemplo n.º 19
0
 public void AddShips(Dictionary <int, int> new_ships)
 {
     foreach (var i in new_ships)
     {
         if (Ships.ContainsKey(i.Key))
         {
             Ships[i.Key] += i.Value;
         }
         else
         {
             Ships.Add(i.Key, i.Value);
         }
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Returns a value of indicating whether the AI set the ship.
        /// </summary>
        /// <param name="shipType"></param>
        /// <returns>bool</returns>
        private bool SetShip(ShipType shipType)
        {
            try
            {
                Direction shipDirection = Direction.Horizontal;
                int       shipLength    = 0;
                int       horizontalCoordinateStartCell = 0;
                int       verticalCoordinateStartCell   = 0;

                switch (shipType)
                {
                case ShipType.One:
                    shipLength = 1;
                    break;

                case ShipType.Two:
                    shipLength = 2;
                    break;

                case ShipType.Three:
                    shipLength = 3;
                    break;

                case ShipType.Four:
                    shipLength = 4;
                    break;
                }
                var t = (new Random().Next(2));
                shipDirection = ((t == 1) ? Direction.Horizontal : Direction.Vertical);

                horizontalCoordinateStartCell = new Random().Next(10);
                verticalCoordinateStartCell   = new Random().Next(10);

                BaseShip baseShip = new BaseShip(shipDirection, shipLength, verticalCoordinateStartCell, horizontalCoordinateStartCell);
                if (HomeField.IsPossibleToSetShip(baseShip))
                {
                    HomeField.SetShip(baseShip);

                    Ships.Add(baseShip);

                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
            }
            return(false);
        }
Ejemplo n.º 21
0
 public void Merge(Fleet other)
 {
     foreach (var i in other.Ships)
     {
         if (Ships.ContainsKey(i.Key))
         {
             Ships[i.Key] += i.Value;
         }
         else
         {
             Ships.Add(i.Key, i.Value);
         }
     }
     other.RemoveAll();
 }
Ejemplo n.º 22
0
 public bool HasAddedAShip()
 {
     if (FirstRiver.Occupant != null)
     {
         return(false);
     }
     if (random.Next(1, 10) == 1)
     {
         Ship newShip = new Ship(FirstRiver);
         FirstRiver.Occupant = newShip;
         Ships.Add(newShip);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 23
0
        public void UpdateFromInput(int shipCount, int dropoffCount, int halite)
        {
            Halite = halite;

            Ships.Clear();
            for (; shipCount > 0; --shipCount)
            {
                Ships.Add(Factory.CreateShipFromInputLine(Id));
            }

            Dropoffs.Clear();
            for (; dropoffCount > 0; --dropoffCount)
            {
                Dropoffs.Add(Factory.CreateDropoffFromInputLine(Id));
            }
        }
Ejemplo n.º 24
0
 public void Add(PhysicsObj obj)
 {
     Space.Add(obj.Entity);
     if (obj is ShipObj)
     {
         Ships.Add((ShipObj)obj);
     }
     else if (obj is MobileObj)
     {
         Objects.Add((MobileObj)obj);
     }
     else
     {
         Terrain.Add(obj);
     }
 }
 public GameField() : base()
 {
     for (int i = 1; i <= 4; i++)
     {
         Ships.Add(new Ship(i, ShipClass.OneDeck));
     }
     for (int i = 5; i <= 7; i++)
     {
         Ships.Add(new Ship(i, ShipClass.TwoDeck));
     }
     for (int i = 8; i <= 9; i++)
     {
         Ships.Add(new Ship(i, ShipClass.ThreeDeck));
     }
     Ships.Add(new Ship(10, ShipClass.FourDeck));
 }
Ejemplo n.º 26
0
        public void AddShip(Ship ship)
        {
            ValidateCoordinates(ship.Coordinates.Coordinates);

            foreach (var coordinates in ship.Coordinates.Coordinates)
            {
                var cell = _matrix[coordinates.Value];
                if (cell.Ship != null)
                {
                    throw new InvalidBusinessLogicException(
                              $"В ячейке: {coordinates.Value} уже установлен корабль. Повторная установка запрещена.");
                }

                _matrix[coordinates.Value] = new BattleMatrixItem(coordinates, ship);
            }
            Ships.Add(ship);
        }
Ejemplo n.º 27
0
 public void PlaceShip(Ship s, Field[] f)
 {
     if (!ValidateShipPlacement(f))
     {
         //this should be an exception
         Console.WriteLine("Can't add ship. Invalid.");
         return;
     }
     foreach (Field field in f)
     {
         field.HasShip   = true;
         field.WhichShip = s;
     }
     s.PlaceShip(f);
     Ships.Add(s);
     AddInvalidFields(s);
 }
Ejemplo n.º 28
0
        private int CreateShips(GameTime gameTime, float screenWidth, double totalGameTime)
        {
            int score       = 0;
            var enemyTicker = ((int)totalGameTime / 10);
            int enemyCount  = enemyTicker > 100 ? 100 : enemyTicker;

            Color color1 = new Color(0, 50, 255);

            if (Ships.Count < enemyCount + 1)
            {
                var enemy = new Ship(this.Texture, GameRoot.ScaleToHighDPI(this.ScaleX), GameRoot.ScaleToHighDPI(this.ScaleY));
                enemy.Enemy = true; enemy.HITBOXSCALE = .9f;

                int maxEnemySpeed = (int)(shipSpeed + (float)totalGameTime);

                float enemyX  = rand.Next(10, (int)screenWidth - 10);
                float enemyDY = rand.Next((int)shipSpeed, maxEnemySpeed > 500 ? 500 : maxEnemySpeed);
                float enemyDX = 0f;

                if (rand.Next(1, 10) == 1)
                {
                    if (enemyDY > 300)
                    {
                        enemy.Color = new Color(255, 100, 0);
                        enemyDY     = 300f;
                        enemyDX     = GetPositiveOrNegative() * rand.NextFloat(40, 80);
                    }
                    else
                    {
                        enemy.Color = new Color(255, 255, 50);
                        enemyDY     = shipSpeed;
                        enemyDX     = GetPositiveOrNegative() * rand.NextFloat(20, 40);
                    }
                    enemy.SetPosition(new Vector2(enemyX, 0), new Vector2(enemyDX, enemyDY));
                }
                else
                {
                    enemy.Color = GetEnemyColor(enemyDY);
                    enemy.SetPosition(new Vector2(enemyX, 0), new Vector2(0, enemyDY));
                }
                Ships.Add(enemy);
                score++;
            }

            return(score);
        }
        /// <summary>
        /// Выстрел по полю.
        /// </summary>
        /// <param name="location">Позиция выстрела.</param>
        /// <param name="shotResult">Результат выстрела.</param>
        /// <param name="ship">Корабль по которому был произведен выстрел.</param>
        public void Shot(Location location, ShotResult shotResult, Ship ship)
        {
            List <Location> hits = new List <Location>();

            switch (shotResult)
            {
            case ShotResult.Miss:
                hits.Add((Location)location.Clone());
                break;

            case ShotResult.Damage:
                hits.Add((Location)location.Clone());
                break;

            case ShotResult.Kill:
                for (int x = ship.Location.X - 1; x <= ship.Location.X + ship.ShipWidth; x++)
                {
                    for (int y = ship.Location.Y - 1; y <= ship.Location.Y + ship.ShipHeight; y++)
                    {
                        if (x < 10 && y < 10 && x > -1 && y > -1)
                        {
                            hits.Add(new Location(x, y));
                        }
                    }
                }

                Ship s = (Ship)ship.Clone();
                for (int i = 0; i < s.Hits.Length; i++)
                {
                    s.Hits[i] = true;
                }

                Ships.Add(s);
                break;
            }

            foreach (var hit in hits)
            {
                HitsField[hit.X, hit.Y] = true;
            }

            OnEnemyShot(this, new ShotEventArgs(hits, shotResult, ship));
        }
Ejemplo n.º 30
0
 public void Add(PhysicsObj obj)
 {
     Space.Add(obj.Entity);
     if (obj is ShipObj)
     {
         Ships.Add((ShipObj)obj);
     }
     else if (obj is Rocket)
     {
         Objects.Add(obj);
         MessageWriter.ClientEntityCreationMessage(null, NetEntityType.Missile, obj.ID, obj.Position, obj.Orientation, obj.resource_index);
     }
     else if (obj is Character)
     {
     }
     else
     {
         Terrain.Add(obj);
     }
 }