Esempio n. 1
0
        public virtual async Task <GameState> FireCannonProcessResult(FireCannonCallbackDto fireResult)
        {
            GameState g = await FindActiveGameAsync(fireResult.GameId);

            if (g == null)
            {
                return(null);
            }

            g.ClientBoard.Board[fireResult.CellId] = fireResult.Result ? (int)ClientCellState.CellFiredAndShipHit : (int)ClientCellState.CellFiredButEmpty;
            g.IsAwaitingServerTurn = fireResult.Result;

            //if we ship is hit but not destoyed - try to make fires around it on next turn
            if (fireResult.ShipDestroyed == null && fireResult.Result)
            {
                g.CurrentShip.Add(fireResult.CellId);
            }

            //record destroyed ship
            if (fireResult.ShipDestroyed != null)
            {
                bool     isVertical = fireResult.ShipDestroyed.Length > 1 && fireResult.ShipDestroyed[1] - fireResult.ShipDestroyed[0] == 10;
                ShipInfo ship       = new ShipInfo(isVertical, fireResult.ShipDestroyed);
                g.ClientBoard.Ships.Add(ship);
                _gameLogic.MarkCellsAroundShip(g.ClientBoard, ship);
                g.CurrentShip.Clear();
            }

            g = await _storage.UpdateGameAsync(g);

            return(g);
        }
Esempio n. 2
0
        //Called by client in response to server move (signal R)
        public async Task <IActionResult> FireCannonProcessResult([FromBody] FireCannonCallbackDto dto)
        {
            var game = await _gameSvc.FireCannonProcessResult(dto);

            if (game == null)
            {
                return(BadRequest());
            }

            return(Ok(new { }));
        }