예제 #1
0
        /// <summary>
        ///  Makes CustomPins and Polylines for each location
        /// </summary>
        /// <param name="shipLocation"></param>
        private void RegisterLive(ShipLocation shipLocation)
        {
            ColorTypeConverter colorTypeConverter = new ColorTypeConverter();

            Location lastLocation  = shipLocation.LocationsRegistrations.ElementAt(0);
            Location firstLocation = shipLocation.LocationsRegistrations.ElementAt(shipLocation.LocationsRegistrations.Count - 1);

            if (shipLocation.LocationsRegistrations.Count != 0)
            {
                Polyline polyline = new Polyline
                {
                    StrokeWidth = 8,
                    StrokeColor = (Color)colorTypeConverter.ConvertFromInvariantString(shipLocation.Color)
                };
                for (int i = 0; i < shipLocation.LocationsRegistrations.Count; i++)
                {
                    Location currentLocationRegistration = shipLocation.LocationsRegistrations[i];
                    polyline.Geopath.Add(new Position(currentLocationRegistration.Latitude, currentLocationRegistration.Longtitude));
                }
                sharedData.Direction = (float)CalculateDirection(firstLocation, lastLocation);

                CustomPin pin = new CustomPin
                {
                    Type     = PinType.Place,
                    Position = new Position(polyline.Geopath.ElementAt(0).Latitude, polyline.Geopath.ElementAt(0).Longitude),
                    Label    = String.Empty,
                    Address  = "" + shipLocation.ShipId,
                    Name     = "Ship",
                    ShipId   = "" + shipLocation.ShipId,
                    TeamName = shipLocation.TeamName
                };
                mapView.LoadPoints(polyline, pin, shipLocation.ShipId);
            }
        }
예제 #2
0
        public void PlaceShip(ShipLocation shipLocation)
        {
            _playerValidator.ValidateNumberOfPlacedShips(shipLocation.Ship, _ships);

            _ships.Add(shipLocation.Ship);
            OwnBoard.SetShip(shipLocation);
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ShipLocation shipLocation = db.ShipLocations.Find(id);

            db.ShipLocations.Remove(shipLocation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #4
0
 internal void ValidateShipCanBePlacedOnBoard(IField[,] board, ShipLocation shipLocation)
 {
     if (!DoesShipFitOnBoard(board, shipLocation))
     {
         throw new InvalidOperationException(
                   $"Cannot place ship x: {shipLocation.Row}, y: {shipLocation.Column}");
     }
 }
예제 #5
0
        public T AddShip(IShip ship)
        {
            _ship = new ShipLocation()
            {
                Ship = ship
            };

            return((T)this);
        }
예제 #6
0
        public void SetShip(ShipLocation shipLocation)
        {
            _validator.ValidateCoordinates(Board, shipLocation.Coordinate);
            _validator.ValidateShipCanBePlacedOnBoard(Board, shipLocation);

            var fields = Board.GetFieldsForShip(shipLocation);

            SetShipOnFields(fields, shipLocation.Ship);
        }
예제 #7
0
 public ActionResult Edit(ShipLocation shipLocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shipLocation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TugId = new SelectList(db.Tugs, "TugId", "TugName", shipLocation.TugId);
     return(View(shipLocation));
 }
예제 #8
0
        public ActionResult Create(ShipLocation shipLocation)
        {
            if (ModelState.IsValid)
            {
                db.ShipLocations.Add(shipLocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TugId = new SelectList(db.Tugs, "TugId", "TugName", shipLocation.TugId);
            return(View(shipLocation));
        }
예제 #9
0
        // GET: ShipLocations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShipLocation shipLocation = db.ShipLocations.Find(id);

            if (shipLocation == null)
            {
                return(HttpNotFound());
            }
            return(View(shipLocation));
        }
예제 #10
0
        // GET: ShipLocations/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShipLocation shipLocation = db.ShipLocations.Find(id);

            if (shipLocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TugId = new SelectList(db.Tugs, "TugId", "TugName", shipLocation.TugId);
            return(View(shipLocation));
        }
예제 #11
0
    // Declare member variables here. Examples:
    // private int a = 2;
    // private string b = "text";

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        ShipLocation loc = new ShipLocation(0, 0);
        int          i   = 0;

        foreach (var n in GetChildren())
        {
            ModuleLocationButton mlb = n as ModuleLocationButton;
            if (mlb != null)
            {
                mlb.Location = ShipLocation.FromIndex(i);
                mlb.Connect("ModuleSelected", this, "onInnerModuleSelected");
                i++;
            }
        }
    }
예제 #12
0
        internal static IEnumerable <IField> GetFieldsForShip(this IField[,] fields, ShipLocation shipLocation)
        {
            int changingStartingIndex = shipLocation.Direction == Direction.Horizontal ? shipLocation.Column : shipLocation.Row;

            var fieldList = new List <IField>(shipLocation.ShipSize);

            for (int i = changingStartingIndex; i <= changingStartingIndex + shipLocation.ShipSize - 1; i++)
            {
                int row    = shipLocation.Direction == Direction.Horizontal ? shipLocation.Row : i;
                int column = shipLocation.Direction == Direction.Horizontal ? i : shipLocation.Column;

                fieldList.Add(fields[row, column]);
            }

            return(fieldList);
        }
예제 #13
0
        public Ship shippiar(ShipView shipView)
        {
            var ship = new Ship();

            ship.Id        = shipView.Id;
            ship.Type      = shipView.Type;
            ship.Locations = new List <ShipLocation>();
            foreach (ShipLocationView shipVLoc in shipView.Locations)
            {
                ShipLocation shipLoca = new ShipLocation();
                shipLoca.Location = shipVLoc.Location;
                shipLoca.Id       = shipVLoc.Id;
                ship.Locations.Add(shipLoca);
            }
            return(ship);
        }
예제 #14
0
        private void createBoat(int size, int qty)
        {
            for (int i = 0; i < qty; i++)
            {
                ShipLocation shipLocation = getEmptyPoint(size);
                Barco        barco;

                if (size == SUBMARINO)
                {
                    barco = new Submarine();
                }
                else if (size == DESTRUCTOR)
                {
                    barco = new Destroyer();
                }
                else if (size == CRUCERO)
                {
                    barco = new Crucero();
                }
                else
                {
                    barco = new Portaviones();
                }


                for (int j = 0; j < size; j++)
                {
                    if (shipLocation.Orientation == UP)
                    {
                        matrix[shipLocation.Row - j, shipLocation.Col] = barco;
                    }
                    else if (shipLocation.Orientation == DOWN)
                    {
                        matrix[shipLocation.Row + j, shipLocation.Col] = barco;
                    }
                    else if (shipLocation.Orientation == LEFT)
                    {
                        matrix[shipLocation.Row, shipLocation.Col - j] = barco;
                    }
                    else if (shipLocation.Orientation == RIGHT)
                    {
                        matrix[shipLocation.Row, shipLocation.Col + j] = barco;
                    }
                }
                rodearConAgua(shipLocation);
            }
        }
예제 #15
0
        /// <summary>
        /// Makes CustomPins and Polylines for each location
        /// </summary>
        /// <param name="shipLocation">The ShipLocation object that will be made CustomPins and Polylines according to</param>
        /// <param name="currentIndex">The current number of locations already gone through</param>
        /// <param name="amount">The amount of locations to go through</param>
        private void RegisterReplay(ShipLocation shipLocation, int currentIndex, int amount)
        {
            if (amount > 0)
            {
                ColorTypeConverter colorTypeConverter = new ColorTypeConverter();

                int lastIndex = currentIndex + amount - 1;

                Location lastLocation  = shipLocation.LocationsRegistrations.ElementAt(lastIndex);
                Location firstLocation = shipLocation.LocationsRegistrations.ElementAt(currentIndex);


                if (shipLocation.LocationsRegistrations.Count != 0)
                {
                    Polyline polyline = new Polyline
                    {
                        StrokeWidth = 8,
                        StrokeColor = (Color)colorTypeConverter.ConvertFromInvariantString(shipLocation.Color)
                    };
                    for (int i = currentIndex; i < currentIndex + amount; i++)
                    {
                        Location currentLocationRegistration = shipLocation.LocationsRegistrations[i];
                        polyline.Geopath.Add(new Position(currentLocationRegistration.Latitude, currentLocationRegistration.Longtitude));
                        ShipLocation sortedLocation = sortedLocations.Where(l => l.ShipId == shipLocation.ShipId).FirstOrDefault();
                        sortedLocation.LocationsRegistrations.Add(currentLocationRegistration);
                        sortedLocation.Color = shipLocation.Color;
                    }

                    sharedData.Direction = (float)CalculateDirection(firstLocation, lastLocation);

                    CustomPin pin = new CustomPin
                    {
                        Type     = PinType.Place,
                        Position = new Position(polyline.Geopath.ElementAt(amount - 1).Latitude, polyline.Geopath.ElementAt(amount - 1).Longitude),
                        Label    = String.Empty,
                        Address  = "" + shipLocation.ShipId,
                        Name     = "Ship",
                        ShipId   = "" + shipLocation.ShipId,
                        TeamName = shipLocation.TeamName
                    };
                    mapView.LoadPoints(polyline, pin, shipLocation.ShipId);
                }
            }
        }
예제 #16
0
 private void rodearConAgua(ShipLocation shipLocation)
 {
     for (int i = 0; i < shipLocation.Size; i++)
     {
         if (shipLocation.Orientation == UP)
         {
             rodeaCasilladeAgua(shipLocation.Row - i, shipLocation.Col);
         }
         else if (shipLocation.Orientation == DOWN)
         {
             rodeaCasilladeAgua(shipLocation.Row + i, shipLocation.Col);
         }
         else if (shipLocation.Orientation == LEFT)
         {
             rodeaCasilladeAgua(shipLocation.Row, shipLocation.Col - i);
         }
         else if (shipLocation.Orientation == RIGHT)
         {
             rodeaCasilladeAgua(shipLocation.Row, shipLocation.Col + i);
         }
     }
 }
예제 #17
0
 public ShipModule(ShipLocation loc, ModuleType empty)
 {
     this.loc        = loc;
     this.moduleType = empty;
     //TODO: setup module type
 }
예제 #18
0
 internal bool DoesShipFitOnBoard(IField[,] fields, ShipLocation shipLocation)
 {
     return(shipLocation.Direction == Direction.Horizontal
         ? shipLocation.ShipSize + shipLocation.Column - 1 < fields.GetLength(1)
         : shipLocation.ShipSize + shipLocation.Row - 1 < fields.GetLength(0));
 }
예제 #19
0
    public override void _Ready()
    {
        Viewport root = GetTree().Root;

        cScene = root.GetChild(root.GetChildCount() - 1);
        GD.Print("Hello Homecomer!!!"); //printout to confirm node is active.

        //set c# singleton instance access (more direct than Godot singleton system)
        instance = this;

        gameMonth = 0;

        shipModules = new ShipModule[FULL_SHIP_SIZE];
        for (int i = 0; i < FULL_SHIP_SIZE; i++)
        {
            //the module value is properly corrected in the constructor. No need to calculate and correct it twice.
            ShipLocation loc = new ShipLocation(i, i / MODULES_PER_SECTION);
            shipModules[i] = new ShipModule(loc, ModuleType.empty);
        }

        shipCrew = new List <Crewman>();

        Random r = new Random(0);

        //Adding initial crew. Note birthdate is in months before game start. A birthdate of -360 equals means age 30 years at game turn 0.
        shipCrew.Add(new Crewman("Hugh Frost", CrewGender.male, -381, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.socialization, CrewSkill.navigation })
                     );

        shipCrew.Add(new Crewman("Zach Frost", CrewGender.male, -360, CrewAge.adult)
                     .generateSkills(r, 50, 20, 10, 50, new CrewSkill[] { CrewSkill.artifice, CrewSkill.doctoring })
                     );

        shipCrew.Add(new Crewman("Cole Rowe", CrewGender.male, -570, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 30, new CrewSkill[] { CrewSkill.combat, CrewSkill.weaponry })
                     );

        shipCrew.Add(new Crewman("George Hawkins", CrewGender.male, -312, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.socialization, CrewSkill.doctoring })
                     );

        shipCrew.Add(new Crewman("Eden Day", CrewGender.female, -408, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.artifice })
                     );

        shipCrew.Add(new Crewman("Rosie Connor", CrewGender.male, -308, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.navigation })
                     );

        shipCrew.Add(new Crewman("Jessie Marshall", CrewGender.female, -400, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 30, new CrewSkill[] { CrewSkill.navigation })
                     );

        shipCrew.Add(new Crewman("Ciara Palmer", CrewGender.female, -302, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.artifice })
                     );

        shipCrew.Add(new Crewman("Alicia Hatcher", CrewGender.female, -320, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.weaponry })
                     );

        shipCrew.Add(new Crewman("Norma López", CrewGender.female, -432, CrewAge.adult)
                     .generateSkills(r, 60, 20, 10, 50, new CrewSkill[] { CrewSkill.socialization, CrewSkill.combat })
                     );

        int[] foo = { 1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5 };
        foreach (int f in foo)
        {
            GD.Print(f);
        }
    }
예제 #20
0
 internal bool CanShipBePlaced(IField[,] board, ShipLocation shipLocation)
 {
     return(board.GetFieldsForShip(shipLocation)
            .All(f => f.IsFree));
 }
예제 #21
0
 public ShipLocationView(ShipLocation locations)
 {
     Id       = locations.Id;
     Location = locations.Location;
 }