Ejemplo n.º 1
0
        public Ship createShip(Ship.ShipType mShipType, GameObject.GameObjectName gameName, int index = 0, float mX = 0.0f, float mY = 0.0f)
        {
            Ship ship = null;

            switch (mShipType)
            {
            case Ship.ShipType.ShipRoot:
                ship = new ShipRoot(gameName, Sprite.SpriteName.NullObject, index, mX, mY);
                GameObjectNodeManager.add(ship, cPCSTree);
                break;

            case Ship.ShipType.CannonShip:
                ship = new CannonShip(gameName, Sprite.SpriteName.CannonShip, index, mX, mY);

                //   ship = cannonShip;
                break;

            case Ship.ShipType.Uninitilized:
                Debug.WriteLine("Missile Type is Uninitilized");
                break;
            }

            this.cPCSTree.Insert(ship, this.cParent);

            // cSpriteBatch.addToBatch(ship.getProxySprite());
            // cSpriteBatch.addToBatch(ship.getCollisionObj().cSpriteBox);
            ship.addSpriteToBatch(this.cSpriteBatch);
            ship.addCollisionToBatch(SpriteBatchManager.find(SpriteBatch.SpriteBatchName.Boxes));
            return(ship);
        }
        public Ocean GetShipsPositionsAndPlaceShipsOnBoard(Ocean ocean)
        {
            // Ship names needed for printing and ship types list
            List <string> shipTypesNames = new List <string> {
                "Carrier (5",
                "Battleship (4",
                "Cruiser (3",
                "Submarine (3",
                "Destroyer (2"
            };

            Ship.ShipType[] shipTypes = new Ship.ShipType[5] {
                Ship.ShipType.CARRIER,
                Ship.ShipType.BATTLESHIP,
                Ship.ShipType.CRUISER,
                Ship.ShipType.SUBMARINE,
                Ship.ShipType.DESTROYER
            };

            // Get data from user where to place each type of the ship
            foreach (string type in shipTypesNames)
            {
                Printer.Print("\nPlease place " + type + " squares) on your ocean:");

                // Ask for ship position (top left Square of the ship) and layout (horizontal/vertical)
                // until the ship can be placed on the ocean (1. is inside board, 2. not overlap with
                // another ship, 3. do not touch another ship)
                bool shipPlacedInTheOcean = false;
                while (shipPlacedInTheOcean == false)
                {
                    int[]  position = GetShipPositionInput(ocean);
                    string layout   = GetShipLayoutInput();

                    // Create new ship object from the input
                    int  index = shipTypesNames.IndexOf(type);
                    Ship ship  = new Ship(shipTypes[index], layout);

                    // Check if ship can be placed in the ocean
                    shipPlacedInTheOcean = ocean.CanPlaceShip(ship, position[0], position[1]);
                    // TODO
                    // Here add check if ships not overlap
                    // Here add check if ships do not touch each other

                    if (shipPlacedInTheOcean == false)
                    {
                        Printer.Print("Not possible to place the ship in the ocean, try again");
                    }
                    else
                    {
                        ocean.PlaceShipAtTheOcean(ship, position[0], position[1]);
                        Printer.Print(ocean, Program.Status.SHIPS_POSITIONING);
                        // ocean.DisplayOcean(Program.Status.SHIPS_POSITIONING);
                    }
                }
            }

            return(ocean);
        }
Ejemplo n.º 3
0
        public void PlaceShip(int x, int y, Ship.ShipType shipType, bool isVertical, ref int availableCount)
        {
            int  shipSize       = Ship.GetShipSizeByShipType(shipType);
            int  startPosition  = (isVertical) ? y : x;
            bool placeAvailable = true;

            for (int i = startPosition; i < (startPosition + shipSize); i++)
            {
                if (isVertical) //y
                {
                    var lengthY = Board.GetLength(1);
                    if (lengthY <= startPosition + shipSize - 1 || Board[x, i].IsAvailable() == false) //if unavailable
                    {
                        placeAvailable = false;
                    }
                }
                else //x
                {
                    var lengthX = Board.GetLength(0);
                    if (lengthX <= startPosition + shipSize - 1 || Board[i, y].IsAvailable() == false) //if unavailable
                    {
                        placeAvailable = false;
                    }
                }
            }

            if (placeAvailable == false)
            {
                System.Console.WriteLine("Ship placement is not available at choosen point ");
                return;
            }

            if (placeAvailable && isVertical)
            {
                availableCount--;
                for (int i = startPosition; i < (startPosition + shipSize); i++)
                {
                    Board[x, i].SetState(Cell.CellState.Ship);
                }

                Console.WriteLine($"Ship placed on position x = {x + 1}, y = {y + 1}");
            }

            if (placeAvailable && !isVertical)
            {
                availableCount--;
                for (int i = startPosition; i < (startPosition + shipSize); i++)
                {
                    Board[i, y].SetState(Cell.CellState.Ship);
                }

                Console.WriteLine($"Ship placed on position x = {x + 1}, y = {y + 1}");
            }
        }
Ejemplo n.º 4
0
        public void Add(Ship.ShipType type, Point hexLocation)
        {
            switch (type)
            {
            case Ship.ShipType.Colony:
            {
                _shipArray.Add(new Colony(_ownerID, hexLocation));
                break;
            }

            case Ship.ShipType.Scout:
            {
                _shipArray.Add(new Scout(_ownerID, hexLocation));
                break;
            }

            case Ship.ShipType.Defender:
            {
                _shipArray.Add(new Defender(_ownerID, hexLocation));
                break;
            }
            }
        }
Ejemplo n.º 5
0
 //new (renamed)
 static void SetPlacingShipType(Ship.ShipType type)
 {
     GameHandler.CheckIsShipAvailable(type);
 }
Ejemplo n.º 6
0
 public AvailableShip(Ship.ShipType type, int numberOfShips)
 {
     this.type          = type;
     this.numberOfShips = numberOfShips;
 }