Exemple #1
0
        public Location GetFreeLocation()
        {
            Location newlocation = null;

            // If no locations return 0,0
            if (World.Instance.GetLocations().Count == 0)
            {
                Position position = new Position(0, 0);
                newlocation = new Location(World.Instance, position, World.Instance.ChooseRandomLocationType());
                World.Instance.AddLocation(newlocation);
            } else
            {
                List<Location> tmpLocations = new List<Location>(World.Instance.GetLocations());

                foreach (Location location in tmpLocations)
                {
                    Position foundemptyposition = World.Instance.GetFreePositionNextToLocation(location);

                    if (foundemptyposition != null)
                    {
                        Position position = new Position(foundemptyposition.GetX(), foundemptyposition.GetY());
                        newlocation = new Location(World.Instance, position, World.Instance.ChooseRandomLocationType());
                        World.Instance.AddLocation(newlocation);
                        continue;
                    }
                }
            }

            return newlocation;
        }
Exemple #2
0
 public Location GenerateRandomLocation()
 {
     Position position = new Position(0, 0);
     Location location = new Location(World.Instance, position, World.Instance.ChooseRandomLocationType());
     return location;
 }
Exemple #3
0
        /*
        public Location GetRandomLocation()
        {
            if (World.Instance.locations.Count < 1)
            {
                // Generate Random Location
                World.Instance.AddLocation(World.Instance.GenerateRandomLocation());
            }

        }*/
        public void AddLocation(Location location)
        {
            World.Instance.locations.Add(location);
        }
Exemple #4
0
        public Position GetFreePositionNextToLocation(Location fromlocation)
        {
            Position foundposition = null;
            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    int checkx = fromlocation.GetPosition().GetX() + x;
                    int checky = fromlocation.GetPosition().GetY() + y;
                    Location location = World.Instance.GetLocations().Where(l => l.GetPosition().GetX() == checkx && l.GetPosition().GetY() == checky ).FirstOrDefault();
                    if (location == null)
                    {
                        foundposition = new Position(checkx, checky);
                    }

                    continue;
                }

                if (foundposition == null)
                {
                    continue;
                }
            }

            return foundposition;
        }
Exemple #5
0
 public void SetLocation(Location location)
 {
     this.location = location;
 }
Exemple #6
0
 public PlayerState(Guid guid, Location location)
 {
     this.playersessionguid = guid;
     this.location = location;
 }