public static void buildUnit(IStarWars3DB context, int playerId, UnitType unitType, CellDTO location) { Cell cell = FreeCell(context, location.row, location.col); //UnitLevel uLevel = GetUnitLevel(context, unitType, 0); if (cell != null) { UnitTemplate unitTemplate = context.UnitTemplates.FirstOrDefault(t => t.UnitType == unitType); if (unitTemplate == null) { throw new NullReferenceException("BuildFighter: unitTemplate not found!"); } Unit unit = new Unit() { UnitTemplateId = unitTemplate.Id, PlayerId = playerId, Location = cell, Armor = unitTemplate.Armor, Damage = unitTemplate.Damage, Shield = unitTemplate.Shield, Range = unitTemplate.Range, Speed = unitTemplate.Speed, Health = unitTemplate.Health, FuelConsumption = unitTemplate.FuelConsumption }; context.Units.Add(unit); context.SaveChanges(); } }
public static UnitStatsDTO LocationHasUnit(IStarWars3DB context, int row, int col) { var unit = context.Units .All() .Where(u => u.Location.row == row && u.Location.col == col) .FirstOrDefault(); if (unit != null) { return(new UnitStatsDTO { Id = unit.Id, Armor = unit.Armor, Damage = unit.Damage, FuelConsumption = unit.FuelConsumption, Health = unit.Health, Range = unit.Range, Shield = unit.Shield, Speed = unit.Speed }); } return(null); }
public static int GetPlanetIdByLocation(IStarWars3DB context, CellDTO cell) { int id = context.Planets.FirstOrDefault(p => p.PlanetTemplate.Locations.Any(l => (l.row == cell.row) && (l.col == cell.col))).Id; return(id); }
public static UnitLevel GetUnitLevel(IStarWars3DB context, UnitType unitType, int level) { return(context.UnitLevels.All() .Where(ul => ul.Type == unitType && ul.Level == level) .FirstOrDefault()); }
public static Planet LocationHasPlanet(IStarWars3DB context, int row, int col) { return(context.Planets.All() .Where(p => p.PlanetTemplate.Locations.Any(l => l.row == row && l.col == col)) .FirstOrDefault()); }
protected BaseController(IStarWars3DB data) { if (data == null) { throw new ArgumentException("An instance of IStoreDb is required to use this controller.", "data"); } this.Data = data; }
public static Factory LocationHasBuilding(IStarWars3DB context, int row, int col) { return(context.Factories .All() .Where(l => l.Location.row == row && l.Location.col == col) .FirstOrDefault()); }
protected BaseController(IStarWars3DB data, ApplicationUser userProfile) : this(data) { if (userProfile == null) { throw new ArgumentException("An instance of ApplicationUser is required to use this controller.", "data"); } this.UserProfile = userProfile; }
public static ICollection <PlanetDTO> GetPlanets(IStarWars3DB context) { var planets = context.PlanetTemplates.All().Where(p => p.IsTaken).Select(p => new PlanetDTO { Id = p.Id, Image = p.Image, Cells = p.Locations.Select(l => new CellDTO { row = l.row, col = l.col }).ToList() }).ToList(); return(planets); }
public static ICollection <UnitDTO> GetUnits(IStarWars3DB context) { var units = context.Units.All().Select(p => new UnitDTO { Id = p.Id, Image = p.UnitTemplate.Image, Cell = new CellDTO { row = p.Location.row, col = p.Location.col } }).ToList(); return(units); }
public static ICollection <BuildingDTO> GetBuildings(IStarWars3DB context) { var buildings = context.Factories.All().Select(p => new BuildingDTO { Id = p.Id, Image = p.FactoryTemplate.Image, Cell = new CellDTO { row = p.Location.row, col = p.Location.col } }).ToList(); return(buildings); }
public static PlayerResourcesDTO GetPlayerResources(IStarWars3DB context, int playerId) { var player = context.Players.GetById(playerId); PlayerResourcesDTO playerResourcesDto = new PlayerResourcesDTO() { Gas = player.Gas, Metal = player.Metal, Minerals = player.Minerals }; return(playerResourcesDto); }
public static void ChangeUnitLocation(IStarWars3DB context, CellDTO selectedCell, CellDTO previousCell) { Unit unit = GetUnitByLocation(context, previousCell.row, previousCell.col); Cell newLocation = new Cell { row = selectedCell.row, col = selectedCell.col }; context.Cells.Add(newLocation); unit.Location = newLocation; context.SaveChanges(); }
private static Cell FreeCell(IStarWars3DB context, int r, int c) { int[][] cellArrayOdd = new int[][] { new int[] { (r - 1), c }, new int[] { (r - 1), (c + 1) }, new int[] { r, (c + 1) }, new int[] { (r + 1), (c + 1) }, new int[] { (r + 1), c }, new int[] { r, (c - 1) } }; int[][] cellArrayEven = new int[][] { new int[] { (r - 1), (c - 1) }, new int[] { (r - 1), c }, new int[] { r, (c + 1) }, new int[] { (r + 1), c }, new int[] { (r + 1), (c - 1) }, new int[] { r, (c - 1) } }; int[][] array; if (r % 2 == 0) { array = cellArrayEven; } else { array = cellArrayOdd; } Cell cell = new Cell(); for (int i = 0; i < array.Length; i++) { Unit unit = PlayerService.GetUnitByLocation( context, array[i][0], array[i][1]); Planet planet = PlayerService.LocationHasPlanet( context, array[i][0], array[i][1]); if (unit == null && planet == null) { cell.row = array[i][0]; cell.col = array[i][1]; return(cell); } } return(null); }
public Game(IStarWars3DB data) { this.data = data; if (selectedCell == null) { selectedCell = new CellDTO(); } if (previousCell == null) { previousCell = new CellDTO(); } }
public static int Initialise(string aspNetId, IStarWars3DB context) { int?playerId; if (!(context.Players.Any(p => p.AspNetId == aspNetId))) { Planet planet = new Planet() { PlanetTemplate = context.PlanetTemplates.FirstOrDefault(p => p.IsTaken == false) }; if (planet.PlanetTemplate == null) { throw new ArgumentException("No available planets found"); } planet.PlanetTemplate.IsTaken = true; context.Players.Add(new Player() { AspNetId = aspNetId, Planets = new[] { planet }, Gas = Constants.InitialPlayerGas, Metal = Constants.InitialPlayerMetal, Minerals = Constants.InitialPlayerMinerals }); context.SaveChanges(); } playerId = context.Players.FirstOrDefault(p => p.AspNetId == aspNetId).Id; if (playerId == null) { throw new ArgumentException("Initialise: PlayerId cannot be null"); } return((int)playerId); }
public static void BuildFactory(IStarWars3DB context, FactoryType factoryType, int playerId, CellDTO location) { FactoryTemplate factoryTemplate = context.FactoryTemplates.FirstOrDefault(t => t.FactoryType == factoryType); if (factoryTemplate == null) { throw new NullReferenceException("BuildFactory: Factory type not found!"); } Factory factory = new Factory() { FactoryTemplateId = factoryTemplate.Id, Level = factoryTemplate.Level, PlayerId = playerId, Health = factoryTemplate.Health, Shield = factoryTemplate.Shield, Location = new Cell { row = location.row, col = location.col } }; context.Factories.Add(factory); context.SaveChanges(); }
public UnitTemplatesController(IStarWars3DB data) : base(data) { }
public GameController(IStarWars3DB data) : base(data) { }
public static bool IfNoOtherPlayers(IStarWars3DB context) { return(context.Players.All() == null); }
public AdminController(IStarWars3DB data) : base(data) { }
public FactoryTemplatesController(IStarWars3DB data) : base(data) { }
public static Unit GetUnitByLocation(IStarWars3DB context, int row, int col) { return(context.Units.All().Where(u => u.Location.row == row && u.Location.col == col).FirstOrDefault()); }