Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public static UnitLevel GetUnitLevel(IStarWars3DB context, UnitType unitType, int level)
 {
     return(context.UnitLevels.All()
            .Where(ul =>
                   ul.Type == unitType &&
                   ul.Level == level)
            .FirstOrDefault());
 }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
        protected BaseController(IStarWars3DB data)
        {
            if (data == null)
            {
                throw new ArgumentException("An instance of IStoreDb is required to use this controller.", "data");
            }

            this.Data = data;
        }
Exemplo n.º 7
0
 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());
 }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        public Game(IStarWars3DB data)
        {
            this.data = data;

            if (selectedCell == null)
            {
                selectedCell = new CellDTO();
            }

            if (previousCell == null)
            {
                previousCell = new CellDTO();
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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();
        }
Exemplo n.º 18
0
 public UnitTemplatesController(IStarWars3DB data)
     : base(data)
 {
 }
Exemplo n.º 19
0
 public GameController(IStarWars3DB data) : base(data)
 {
 }
Exemplo n.º 20
0
 public static bool IfNoOtherPlayers(IStarWars3DB context)
 {
     return(context.Players.All() == null);
 }
Exemplo n.º 21
0
 public AdminController(IStarWars3DB data)
     : base(data)
 {
 }
Exemplo n.º 22
0
 public FactoryTemplatesController(IStarWars3DB data)
     : base(data)
 {
 }
Exemplo n.º 23
0
 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());
 }