public ShipsGameStatus UpdateBoard(ShipsBoard shipsBoard, string roomId) { GameTask task = gameHelper.gameTasks.Where(g => g.Game.Room.Id == Convert.ToInt32(roomId)).First(); var gameStatus = task.GameStatus; if (gameStatus.Boards[0].PlayerId == shipsBoard.PlayerId) { gameStatus.Boards[0].Board = shipsBoard.Board; gameStatus.Boards[0].AreShipsAllocated = true; } else if (gameStatus.Boards[1].PlayerId == shipsBoard.PlayerId) { gameStatus.Boards[1].Board = shipsBoard.Board; gameStatus.Boards[1].AreShipsAllocated = true; } return(gameStatus); }
public async Task AlocateShips(string gameId, ShipsBoard board) { await SendGameStatus(gameId, _shipsService.UpdateBoard(board, gameId)); }
private ValueTuple <string, ShipsBoard> Shoot(int intCoordinates, char charCoordinates, ShipsBoard board, ShipsGameStatus gameStatus) { int i = charCoordinates - 'A'; ShipsField field = board.Board[intCoordinates - 1][i]; string message; field.TriedToShoot = true; var move = new Move { Field = field, PlayerId = board.PlayerId }; gameStatus.CurrentMove = move; if (field.IsShip) { field.IsShot = true; field.PartsDestroyed++; if (field.ShipType == ShipType.Ship1 || IsSunk(field)) { field.IsSunk = true; message = "Congrats! Ship sunk!"; board.ShipsSunk++; } else { message = "Great! You shot this ship!"; } } else { message = "Nothing there, try again!"; } board.Board[intCoordinates - 1][i] = field; return(message, board); }