public static ShipRequest GetLocation(string location) { string strX, strY, strDirection; int x, y; if (location.Split(',').Length == 2) { if (location.Split(',')[0].Trim().Length > 1) { strX = location.Split(',')[0].Trim().Substring(0, 1); strY = location.Split(',')[0].Trim().Substring(1); strDirection = location.Split(',')[1].ToLower().Trim(); x = GetNumberFromLetter(strX); if (x > 0 && x < 11 && int.TryParse(strY, out y) && y > 0 && y < 11 && (strDirection == "l" || strDirection == "r" || strDirection == "u" || strDirection == "d")) { ShipRequest ShipToPlace = new ShipRequest(); ShipToPlace.Direction = getDirection(strDirection); ShipToPlace.Coordinate = new Coordinate(x, y); return(ShipToPlace); } } } return(null); }
public void CanNotOverlapShips() { Panel board = new Panel(); // let's put a carrier at (10,10), (9,10), (8,10), (7,10), (6,10) var carrierRequest = new ShipRequest() { Coordinate = new Coordinate(10, 10), Direction = ShipDirections.Left, ShipType = ShipTypes.Carrier }; var carrierResponse = board.PlaceShip(carrierRequest); Assert.AreEqual(ShipPlacements.Ok, carrierResponse); // now let's put a destroyer overlapping the y coordinate var destroyerRequest = new ShipRequest() { Coordinate = new Coordinate(9, 9), Direction = ShipDirections.Down, ShipType = ShipTypes.Destroyer }; var destroyerResponse = board.PlaceShip(destroyerRequest); Assert.AreEqual(ShipPlacements.Overlap, destroyerResponse); }
public ShotPlace PlaceShip(ShipRequest request) { if (_currentShipIndex > 4) { throw new Exception("You can not add another ship, 5 is the limit!"); } if (!IsValidCoordinate(request.Coordinate)) { return(ShotPlace.NotEnoughSpace); } Ship newShip = ShipMaker.CreateShip(request.ShipType); switch (request.Direction) { case ShipDirection.Down: return(PlaceShipDown(request.Coordinate, newShip)); case ShipDirection.Up: return(PlaceShipUp(request.Coordinate, newShip)); case ShipDirection.Left: return(PlaceShipLeft(request.Coordinate, newShip)); default: return(PlaceShipRight(request.Coordinate, newShip)); } }
/// <summary> /// 提交一个订单生成面单 /// </summary> /// <param name="rateRequest"></param> /// <returns></returns> public static ShipResponse Ship(ShipRequest rateRequest) { var request = new Request("api/ship"); var result = request.Execute(rateRequest); return(XmlUtilHelper.DeSerializedEntity <ShipResponse>(result)); }
public static ShipRequest GetLocationFromComputer() { ShipRequest ShipToPlace = new ShipRequest(); ShipToPlace.Direction = getDirection(GetRandom.GetDirection()); ShipToPlace.Coordinate = new Coordinate(GetRandom.GetLocation(), GetRandom.GetLocation()); return(ShipToPlace); }
public async Task <IActionResult> CreateShip(ShipRequest createShipRequest) { var ship = await _shipService.CreateShip(createShipRequest); var shipUri = new Uri($"/ProducesResponseType/{ship.Id}", UriKind.Relative); return(Created(shipUri, ship)); }
public async Task <IActionResult> Ship([FromBody] ShipRequest request) { AssertExtensions.NotNull(request, nameof(request)); ShipsCreationModel model = _applicationMapper.Map(request); await _seeBattleGameService.AddShips(model); return(Ok()); }
public void CreateShip(UpdateShipList.ShipInfo ship, string name, string password) { ShipRequest request = new ShipRequest(); request.Join = false; request.RequestedShipID = ship.ID; request.Password = password; request.Name = name; Send(request); }
public void JoinShipGame(UpdateShipList.ShipInfo ship, string password) { ShipRequest request = new ShipRequest(); request.Join = true; request.RequestedShipID = ship.ID; request.Password = password; request.Name = ship.Name; Send(request); }
public static async Task <ShipResponse> UpdateShip(string token, int shipId, int x, int x_offset, int y, int y_offset, int shipType) { var shipRequest = new ShipRequest { X = x, XOffset = x_offset, Y = y, YOffset = y_offset, ShipTypeId = shipType }; return(await Update(token, shipId, shipRequest)); }
public static async Task <ShipResponse> CreateShip(string token, string roomId, int x, int x_offset, int y, int y_offset, int shipTypeId) { var shipRequest = new ShipRequest { X = x, XOffset = x_offset, Y = y, YOffset = y_offset, ShipTypeId = shipTypeId }; return(await ShipsService.Create(token, roomId, shipRequest)); }
private static ShipRequest CreateShipRequest() { ShipRequest shipRequest = new ShipRequest(); shipRequest.RequstInfo = new ShipRequestDetail(); shipRequest.RequstInfo.Shipper = new AddressInfo() { PersonName = "test", City = "Portland", PostalCode = "97230", StateOrProvinceCode = "OR", CountryCode = "US", StreetLines = new[] { "14121 NE Airport Way" }, PhoneNumber = "2025551212", }; shipRequest.RequstInfo.Recipient = new AddressInfo() { PersonName = "test", City = "Portland", PostalCode = "97230", StateOrProvinceCode = "OR", CountryCode = "US", StreetLines = new[] { "14121 NE Airport Way" }, PhoneNumber = "2025551212", }; shipRequest.RequstInfo.PackageItems = new List <PackageItemInfo>() { new PackageItemInfo() { Width = 1, Height = 1, Length = 1, Weight = 1 } }; shipRequest.AuthorizedKey = "TESTTOKEN-ske39De3mkC39d"; shipRequest.LabelFormatType = "PDF"; shipRequest.NoBackData = true; //orderid 是用于标识提交的订单的唯一性,会打印到面单上,orderid可为空 // shipRequest.OrderId = "6666666666"; shipRequest.ShipType = ShipTypeEnum.FedEx2Day.ToString(); shipRequest.RequstInfo.LbSize = LabelSize.S4X6.ToString(); shipRequest.RequstInfo.Package = new WaybillInformation(); shipRequest.RequstInfo.Package.ShipDate = DateTime.Now.AddDays(2); //备注,会打印到面单上 shipRequest.RequstInfo.Package.ShippingNotes = "testsetsetsetsteste"; return(shipRequest); }
public void CanNotPlaceShipOffBoard() { Panel board = new Panel(); ShipRequest request = new ShipRequest() { Coordinate = new Coordinate(15, 10), Direction = ShipDirections.Up, ShipType = ShipTypes.Destroyer }; var response = board.PlaceShip(request); Assert.AreEqual(ShipPlacements.NotEnoughSpace, response); }
public void PlaceShipOnBoard(Player player) { for (ShipTypes s = ShipTypes.Destroyer; s <= ShipTypes.Carrier; s++) { ShipRequest ShipToPlace = new ShipRequest(); ShipPlacements result; do { ShipToPlace = ControlInput.GetLocationFromComputer(); ShipToPlace.ShipType = s; result = player.PlayerBoard.PlaceShip(ShipToPlace); } while (result != ShipPlacements.Ok); } }
public void CanNotPlaceShipPartiallyOnBoard() { Panel board = new Panel(); ShipRequest request = new ShipRequest() { Coordinate = new Coordinate(10, 10), Direction = ShipDirections.Right, ShipType = ShipTypes.Carrier }; var response = board.PlaceShip(request); Assert.AreEqual(ShipPlacements.NotEnoughSpace, response); }
public async Task <Ship> CreateShip(ShipRequest shipRequest) { var shipId = Guid.NewGuid(); return(new Ship { Id = shipId, Size = shipRequest.Size, Status = ShipStatus.Active, Positions = new List <ShipPosition>() { new ShipPosition { } } }); }
public static async Task <ShipResponse> Update(string token, int shipId, ShipRequest ship) { var jsonRequest = JsonConvert.SerializeObject(ship); HttpContent content = new StringContent(jsonRequest, Encoding.UTF8, "application/json"); Uri uri = new Uri(BASE_URL + shipId); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var response = await client.PutAsync(uri, content); var jsonResponse = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <ShipResponse>(jsonResponse)); } throw new ApiException(JsonConvert.DeserializeObject <ErrorResponse>(jsonResponse)); } }
public static ShipRequest GetLocationFromUser(string ShipType) { ShipRequest result = null; do { Console.Write("- " + ShipType + ": "); result = GetLocation(Console.ReadLine()); if (result is null) { ; } else { return(result); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input. Please input location and direiction. Ex:) a2, r"); Console.ForegroundColor = ConsoleColor.White; } while (result is null); return(result); }
public async Task <IActionResult> CreateShip(string roomId, ShipRequest request) { var userId = HttpContext.GetUserId(); var shipType = await _context.ShipTypes .AsNoTracking() .SingleOrDefaultAsync(t => t.Id == request.ShipTypeId); if (shipType == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find ship type" } } })); } var room = await _context.Rooms .AsNoTracking() .SingleOrDefaultAsync(r => r.Id == roomId); if (room == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find room by given Id" } } })); } if (room.GuestUserId == null) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to create ship: guest player have not joined room yet" } } })); } var map = await _context.Maps .SingleOrDefaultAsync(m => m.UserId == userId && m.RoomId == roomId); if (map == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find map" } } })); } if (map.IsCompleted) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "This map is already completed" } } })); } var shipGroup = await _context.ShipGroups .SingleOrDefaultAsync(g => g.UserId == userId && g.RoomId == roomId && g.ShipTypeId == request.ShipTypeId); if (shipGroup == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find ship group" } } })); } if (shipGroup.Limit <= shipGroup.Count) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "You can not create no more ships of this type" } } })); } shipGroup.Count++; _context.ShipGroups.Update(shipGroup); await _context.SaveChangesAsync(); var shipGroups = await _context.ShipGroups .AsNoTracking() .Where(g => g.UserId == userId && g.RoomId == roomId).ToListAsync(); if (shipGroups.All(sg => sg.Count >= sg.Limit)) { map.IsCompleted = true; _context.Maps.Update(map); await _context.SaveChangesAsync(); } var ship = _mapper.Map <Ship>(request); ship.UserId = userId; ship.RoomId = roomId; ship.HP = shipType.Size; _context.Ships.Add(ship); await _context.SaveChangesAsync(); return(CreatedAtAction("GetShip", new { shipId = ship.Id }, _mapper.Map <ShipResponse>(ship))); }
public async Task <List <Ship> > HandleAsync(ShipRequest message, IOutputPort <ShipResponse> outputPort) { return(await _cruiseLineRepository.GetShipsAsync(message.nid)); }
public ShipsCreationModel Map(ShipRequest request) { AssertExtensions.NotNull(request, nameof(request)); return(new ShipsCreationModel(request.Coordinates)); }
public ShipResponse Ship([FromBody] ShipRequest request) { return(new ShipResponse()); }
private void HandleShipRequest(object sender, ShipMessage msg) { ShipPeer peer = sender as ShipPeer; ShipRequest request = msg as ShipRequest; JoinShipResponce responce = new JoinShipResponce(); PlayerShip shipToLink = null; if (peer.LinkedShip != null) { shipToLink = peer.LinkedShip; } else { if (request.Join) { shipToLink = PlayerShips.Find((x) => x.LinkedShip.GUID == request.RequestedShipID); if (shipToLink == null || shipToLink.Locked && shipToLink.Password != request.Password) { responce.Error = true; responce.Message = "NoShipToJoin"; peer.Send(responce); return; // nope! } else { if (!shipToLink.ControlingPeers.Contains(peer)) { shipToLink.ControlingPeers.Add(peer); } peer.LinkedShip = shipToLink; } } } if (shipToLink == null) { var template = TemplateDatabase.GetTemplate(request.RequestedShipID); int shipID = ActiveScenario.SpawnPlayableShip(peer.Connection.RemoteUniqueIdentifier.ToString(), template == null ? string.Empty : template.Name, request.Name); var ship = ZoneManager.GetFirstMatch(new PlayableShipFinder(shipID)) as Ship; shipToLink = new PlayerShip(); shipToLink.LinkedShip = ship; shipToLink.ControlingPeers.Add(peer); shipToLink.Locked = request.Password != string.Empty; shipToLink.Password = request.Password; peer.LinkedShip = shipToLink; PlayerShips.Add(shipToLink); } // send back the responce with the ship they are on responce.Error = false; responce.Message = shipToLink.LinkedShip.Name; responce.ShipID = shipToLink.LinkedShip.GUID; peer.Send(responce); // send an info and status update }
public async Task <IActionResult> UpdateShipLocation(int shipId, ShipRequest request) { var userId = HttpContext.GetUserId(); var ship = await _context.Ships.FindAsync(shipId); if (ship == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find ship by given Id" } } })); } if (ship.UserId != userId) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to update ship: you do not have access to it" } } })); } var room = await _context.Rooms .SingleOrDefaultAsync(r => r.Id == ship.RoomId); if (room == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find room" } } })); } if (room.GuestUserId == null) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to update ship: guest player have not joined room yet" } } })); } if (room.GuestUserId != userId && room.HostUserId != userId) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to update ship: you do not have access to this room" } } })); } var maps = await _context.Maps .Where(m => m.RoomId == room.Id) .AsNoTracking() .ToListAsync(); if (maps.Any(m => !m.IsCompleted)) { return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to update ship: not all maps in this room is already completed" } } })); } if ((room.HostUserId == userId && room.IsHostTurn) || (room.GuestUserId == userId && !room.IsHostTurn)) { ship.X = request.X; ship.XOffset = request.XOffset; ship.Y = request.Y; ship.YOffset = request.YOffset; int x1 = ship.XOffset >= 0 ? ship.X : ship.X + ship.XOffset + 1; int x2 = ship.XOffset >= 0 ? ship.X + ship.XOffset - 1 : ship.X; int y1 = ship.YOffset >= 0 ? ship.Y : ship.Y + ship.YOffset + 1; int y2 = ship.YOffset >= 0 ? ship.Y + ship.YOffset - 1 : ship.Y; string enemyId; if (room.HostUserId == userId) { enemyId = room.GuestUserId; } else { enemyId = room.HostUserId; } var enemyMines = await _context.Weapons .Include(w => w.WeaponType) .Where(w => w.UserId == enemyId && w.RoomId == ship.RoomId && w.WeaponType.IsMine && !w.IsUsed && w.X >= x1 && w.X <= x2 && w.Y >= y1 && w.Y <= y2).ToListAsync(); foreach (var mine in enemyMines) { mine.IsUsed = true; _context.Weapons.Update(mine); await _context.SaveChangesAsync(); ship.HP -= 0.5; } _context.Ships.Update(ship); await _context.SaveChangesAsync(); var enemyMap = await _context.Maps .FirstOrDefaultAsync(m => m.UserId == enemyId && m.RoomId == ship.RoomId); if (enemyMap == null) { return(NotFound(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to find enemy map" } } })); } enemyMap.EnemyShot_X = null; enemyMap.EnemyShot_Y = null; _context.Maps.Update(enemyMap); await _context.SaveChangesAsync(); room.IsHostTurn = !room.IsHostTurn; _context.Rooms.Update(room); await _context.SaveChangesAsync(); return(Ok(_mapper.Map <ShipResponse>(ship))); } return(BadRequest(new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Message = "Unable to update ship: it is not your turn" } } })); }