public void AddShip(JsonElement[] sendData) { var connectionId = Context.ConnectionId; int headX = sendData[0].GetInt32(); int headY = sendData[1].GetInt32(); int tailX = sendData[2].GetInt32(); int tailY = sendData[3].GetInt32(); int length = sendData[4].GetInt32(); int playerId = Int32.Parse(sendData[5].GetString()); Game game = _activeGames.GetGameByPlayerId(playerId); Player player = _activeGames.GetPlayerById(playerId); var head = new Coords(headX, headY); var shipInfo = new ShipInformation() { Location = new ShipLocation() { Coords = head, Direction = GetDirection(head, new Coords(tailX, tailY)) }, Ship = new Ship(length) }; bool addedsuccessfull = true; try { game.AddShip(player, shipInfo); } catch (Exception ex) { if (ex.Data["type"] != null && (GameException)ex.Data["type"] == GameException.ShipsTouch) { Clients.Client(connectionId).SendAsync("ShipsCantTouch"); } addedsuccessfull = false; } if (addedsuccessfull) { var jsonCoordList = JsonConvert.SerializeObject(shipInfo.GetCoordsFromShipInformation()); Clients.Client(connectionId).SendAsync("AddShip", jsonCoordList, length); } }