public async Task <IActionResult> CreateBulletForBulletPage([FromBody] BulletDTO bulletDTO, [FromRoute] int bulletPageId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (bulletDTO.Id != 0 || bulletPageId == 0) { return(BadRequest()); } if (!_context.BulletPages.Any(bp => bp.Id == bulletPageId)) { return(NotFound()); } var bulletPage = _context.BulletPages.FirstOrDefault(bp => bp.Id == bulletPageId); var bullet = _mapper.Map <BulletDTO, Bullet>(bulletDTO); bulletPage.Bullets.Add(bullet); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (BulletExists(bulletDTO.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } } return(Ok(bulletDTO)); }
public bool playerGotShot(BulletDTO bullet) { methodCallCounter(); bool result = false; if (Opponents.ContainsKey(Clients.CallerState.UserName)) { PlayerDTO player = Opponents[Clients.CallerState.UserName]; if (Bullets.ContainsKey(bullet.ID) && Bullets.TryRemove(bullet.ID, out BulletDTO bulletDTO)) { Clients.Others.removeBullet(bulletDTO); player.Health -= bulletDTO.Damage; result = true; if (player.Health < 1) { if (Opponents.TryRemove(player.Name, out PlayerDTO deadPlayer)) { Clients.Caller.playerDied(bulletDTO.PlayerID); Clients.Others.removeDeadOpponent(deadPlayer.Name); } else { Console.WriteLine($"playerGotShot Error, Could not remove dead player '{deadPlayer.Name}' from List of Opponents"); } } else { Clients.Caller.updateHealth(player.Health); } } } return(result); }
private static void opponentShoots(BulletDTO bullet) { Bullet newBullet = BulletAdapter.renderBullet(bullet); if (GameController.Bullets.TryAdd(newBullet.ID, newBullet)) { BulletAdapter.addBulletToCanvas(newBullet); } }
public static Bullet renderBullet(BulletDTO bullet) { IRenderable renderable = new Renderable(bulletBorderColor, bulletColor, bulletLineThickness, bulletWidth, bulletHight, bulletVertices); IShape shape = new Shape(bullet.ID, bullet.Ray, renderable, new RenderStrategy()); IMoveable bulletShip = new Moveable(bulletLineMaxVelocity - 1, bulletLineMaxVelocity, 0, 0, shape, new MoveStrategy()); return(new Bullet(bullet.ID, bulletShip, bullet.Damage, bullet.PlayerID)); }
public static BulletDTO bulletToDTO(IBullet bullet) { BulletDTO bulletDTO = new BulletDTO() { ID = bullet.ID, PlayerID = bullet.PlayerID, Ray = (Ray)bullet.BulletShip.Shape.Ray, Damage = bullet.Damage }; return(bulletDTO); }
public async Task <IActionResult> Put(int bulletId, [FromBody] BulletDTO bulletDTO) { if (!BulletExists(bulletId)) { return(NotFound()); } if (bulletId == 0) { return(BadRequest()); } var bullet = _mapper.Map <BulletDTO, Bullet>(bulletDTO); _context.Update(bullet); await _context.SaveChangesAsync(); return(Ok(bullet)); }
public async Task <bool> playerShoots(int damage) { methodCallCounter(); bool result = false; PlayerDTO shootingPlayer = Opponents[Clients.CallerState.UserName]; await Task.Factory.StartNew(() => { if (shootingPlayer != null) { BulletDTO bullet = BulletFactory.generateBullet(damage, shootingPlayer); bool addBullet = Bullets.TryAdd(bullet.ID, bullet); if (addBullet) { result = true; Clients.All.opponentShoots(bullet); } } }); return(result); }
private static void removeBullet(BulletDTO bullet) { BulletAdapter.removeBulletFromCanvas(bullet.ID); }
public async Task <bool> playerGotShot(BulletDTO bullet) { return(await hubProxy.Invoke <bool>("playerGotShot", bullet)); }