Esempio n. 1
1
        public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
        {
            var cell = Map.PointToCell(destination);
            var obj = Game.Map.GetObjectFromCell(cell);

            var largeObjectOuter = obj as LargeObjectOuterAbstract;

            if(largeObjectOuter == null)
                return destination;

            var startingPoint = new Point(cell.X - largeObjectOuter.PlaceInObject.X, cell.Y - largeObjectOuter.PlaceInObject.Y);

            var innerObject = largeObjectOuter.InnerObject as Wickiup;
            var totDist = Int32.MaxValue;
            Point p = null;
            var heroPos = Map.PointToCell(hero.Position);

            for (int i = 0; i < (int)innerObject.Size.Width + 2; i++ )
            {
                for (int j = 0; j < (int) innerObject.Size.Height + 2; j++)
                {
                    if (i > 0 && i < (int) innerObject.Size.Width + 1 && j > 0 && j < (int) innerObject.Size.Height + 1)
                        continue;

                    var curPoint = new Point(i - 1, j - 1);
                    bool isPassable;

                    if (j == 0 || j == (int) innerObject.Size.Height + 1)
                    {
                        isPassable = innerObject.HorizontalBorder[i, j == 0 ? 0 : 1];
                    }
                    else
                    {
                        isPassable = innerObject.VerticalBorder[j - 1, i == 0 ? 0 : 1];
                    }

                    if (!isPassable)
                        continue;

                    int totdistX = Math.Abs(heroPos.X - startingPoint.X - curPoint.X);
                    int totdistY = Math.Abs(heroPos.Y - startingPoint.Y - curPoint.Y);

                    var curtotDist = totdistX*totdistX + totdistY*totdistY;

                    if (curtotDist < totDist)
                    {
                        totDist = curtotDist;
                        p = curPoint;
                    }
                }
            }

            var newCenterPoint = Map.CellToPoint(new Point(startingPoint.X + p.X, startingPoint.Y + p.Y));
            var x = newCenterPoint.X + Map.CELL_MEASURE / 2 + (p.X > -1 && p.X < innerObject.Size.Width ? 0 :  p.X == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2);
            var y = newCenterPoint.Y + Map.CELL_MEASURE / 2 + (p.Y > -1 && p.Y < innerObject.Size.Height ? 0 : p.Y == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2);

            innerPoint = startingPoint;

            return new Point(x, y);
        }
Esempio n. 2
0
File: Game.cs Progetto: norniel/Game
        public Game(IDrawer drawer, uint width, uint height)
        {
            curRect.Width = width;
            curRect.Height = height;

            Intervals = Observable.Interval(TimeSpan.FromMilliseconds(TimeStep));
            _unityContainer = new UnityContainer();
            this.RegisterInUnityContainer();

            StateQueueManager = _unityContainer.Resolve<StateQueueManager>();
            Map = _unityContainer.Resolve<Map>();

            loadSaveManager = new LoadSaveManager();
            loadSaveManager.LoadSnapshot(Map);

            _hero = _unityContainer.Resolve<Hero>();
            _hero.Map = Map;

            ActionRepository = _unityContainer.Resolve<IActionRepository>();

            _drawer = drawer;

            Intervals.Subscribe(StateQueueManager);

            _dayNightCycle = new DayNightCycle();
            Intervals.Subscribe(_dayNightCycle);
        }
Esempio n. 3
0
        public virtual bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            if (!_isInitialized)
            {
                Initialize(hero, objects);
                _isInitialized = true;
            }

            bool isOver = false;

            if (TotalActionTime <= ElapsedActionTime)
            {
                DoLast(hero, objects);
                isOver = true;
            }
            else
            {
                isOver = DoNotLast(hero, objects);
                ElapsedActionTime++;
            }

            if (isOver)
            {
                ClearAfterLast();
            }

            return isOver;
        }
Esempio n. 4
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var innerObject = objects.OfType<Wickiup>().First();
            Game.Map.SetInnerMap(innerObject._map, innerPoint);

            innerPoint = null;
            return true;
        }
Esempio n. 5
0
        public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var bed = (LargeObjectInner)objects.FirstOrDefault(o => o.Properties.Any(IsApplicable));

            if (bed != null && bed.IsBuild)
            {
                yield return new List<GameObject>() { bed };
            }
        }
Esempio n. 6
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            foreach (var removableObject in objects.OfType<IEatable>())
            {
                hero.Eat(removableObject.Satiety);
                (removableObject as GameObject).RemoveFromContainer();
            }

            return true;
        }
Esempio n. 7
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            foreach (var removableObject in objects)
            {
                Map.SetHObjectFromDestination(hero.Position, removableObject as FixedObject);
              //  removableObject.RemoveFromContainer();
            }

            return true;
        }
Esempio n. 8
0
        public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var objectsToEnter = objects.Where(o =>
            {
                var largeObj = o as LargeObjectInner;
                return largeObj == null || largeObj.IsBuild;
            }).ToList();

            return objectsToEnter.Any() ? new[] { objectsToEnter } : new List<GameObject>[] {};
        }
Esempio n. 9
0
        public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var allObjects = objects.Union(hero.GetContainerItems()).Distinct();

            var stones = allObjects.Where(o => o is Rock).Take(2).ToList();

            if (stones.Count == 2)
            {
                yield return stones;
            }
        }
Esempio n. 10
0
        public override IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var cuttableObject = objects.FirstOrDefault(o => o.Properties.Contains(Property.Cuttable));

            // TODO: implement choosing cutters with different quility
            var cutter = hero.GetContainerItems().FirstOrDefault(o => o.Properties.Contains(Property.Cutter));

            if (cuttableObject != null && cutter != null)
            {
                yield return new List<GameObject> { cuttableObject, cutter };
            }
        }
Esempio n. 11
0
        public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var allObjects =
                objects.Union(hero.GetContainerItems()).Distinct();

            var branch = allObjects.FirstOrDefault(ao => ao is Branch);
            var stone = allObjects.FirstOrDefault(ao => ao.Properties.Contains(Property.Cutter));

            if (branch != null && stone != null)
            {
                yield return new List<GameObject> { branch, stone };
            }
        }
Esempio n. 12
0
        public override IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var roastingObjects = hero.GetContainerItems()
                .Where(o => o.Properties.Contains(Property.Roastable) && o is IRoastable)
                .GroupBy(o => o.GetType())
                .Select(gr => gr.Take(3));

            var twig = hero.GetContainerItems().OfType<Twig>().FirstOrDefault();

            if (twig != null)
                return roastingObjects.Select(bo => bo.Union(new List<GameObject> {twig}).Union(objects).ToList());

            return new List<List<GameObject>>();
        }
Esempio n. 13
0
        public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
        {
            var allObjects =
                objects.Union(hero.GetContainerItems()).Distinct();

            var branches = allObjects.Where(ao => ao is Branch).Select(ao => ao).Take(2).ToList();
            var plant = allObjects.FirstOrDefault(ao => ao is Plant);

            if (branches.Count == 2 && plant != null)
            {
                branches.Add(plant);
                yield return branches.ToList();
            }
        }
Esempio n. 14
0
        protected override void DoLast(Hero hero, IEnumerable<GameObject> objects)
        {
            var cuttableObject = objects.SingleOrDefault(o => o.Properties.Contains(Property.Cuttable));
            var cutter = objects.SingleOrDefault(o => o.Properties.Contains(Property.Cutter));

            if (cuttableObject == null || cutter == null)
            {
                return;
            }

            cuttableObject.RemoveFromContainer();

            Map.SetHObjectFromDestination(hero.Position, new Log());
            return;
        }
Esempio n. 15
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var burnable = objects.FirstOrDefault(o => o is IBurnable);
            var burning = objects.OfType<IBurning>().FirstOrDefault();

            if (burnable == null || burning == null)
            {
                return true;
            }

            burning.TimeOfBurning += ((IBurnable)burnable).TimeOfBurning;
            burnable.RemoveFromContainer();

            return true;
        }
Esempio n. 16
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var branches = objects.Where(o => o is Branch).ToList();
            var plant = objects.SingleOrDefault(o => o is Plant);

            if (branches.Count != 2 || plant == null)
                return true;

            branches.ForEach(b => b.RemoveFromContainer());
            plant.RemoveFromContainer();
            var fire = new Fire();

            Map.SetHObjectFromDestination(hero.Position, fire as FixedObject);

            return true;
        }
Esempio n. 17
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var stones = objects.Where(o => o is Rock).Take(2).ToList();

            if (stones.Count < 2)
                return true;

            stones.First().RemoveFromContainer();
            var sharpStone = new SharpStone();

            if (!hero.AddToBag(sharpStone))
            {
                Game.Map.SetHObjectFromDestination(hero.Position, sharpStone);
            }

            return true;
        }
Esempio n. 18
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var branch = objects.SingleOrDefault(o => o is Branch);
            var stone = objects.SingleOrDefault(ao => ao.Properties.Contains(Property.Cutter));

            if (branch == null || stone == null)
                return true;

            branch.RemoveFromContainer();
            var diggingStick = new DiggingStick();

            if (!hero.AddToBag(diggingStick))
            {
                Game.Map.SetHObjectFromDestination(hero.Position, diggingStick);
            }

            return true;
        }
Esempio n. 19
0
        public bool Do(Hero hero, IEnumerable<GameObject> objects)
        {
            var branch = objects.SingleOrDefault(o => o is Branch);
            var stone = objects.SingleOrDefault(o => o is Rock);

            if (branch == null || stone == null)
                return true;

            branch.RemoveFromContainer();
            stone.RemoveFromContainer();
            var axe = new StoneAxe();

            if (!hero.AddToBag(axe))
            {
                Game.Map.SetHObjectFromDestination(hero.Position, axe);
            }

            return true;
        }
Esempio n. 20
0
        protected override void DoLast(Hero hero, IEnumerable<GameObject> objects)
        {
            var burnable = objects.FirstOrDefault(o => o is IBurnable);
            var twig = objects.OfType<Twig>().FirstOrDefault();
            var roastable = objects.OfType<IRoastable>().ToList();

            if (burnable == null || twig == null || !roastable.Any())
            {
                return;
            }

            twig.RemoveFromContainer();
            foreach (var r in roastable)
            {
                var roasted = r.GetRoasted();

                if (!hero.AddToBag(roasted))
                    break;

                ((GameObject)r).RemoveFromContainer();
            }
        }
Esempio n. 21
0
 protected virtual void Initialize(Hero hero, IEnumerable<GameObject> objects)
 {
 }
Esempio n. 22
0
 protected abstract bool DoNotLast(Hero hero, IEnumerable<GameObject> objects);
Esempio n. 23
0
 protected abstract void DoLast(Hero hero, IEnumerable<GameObject> objects);
Esempio n. 24
0
 public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
 {
     return destination;
 }
Esempio n. 25
0
 public abstract IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero);
Esempio n. 26
0
 public abstract bool CanDo(Hero hero, IEnumerable<GameObject> objects);
Esempio n. 27
0
 public Unconscios(Hero hero)
 {
     _hero = hero;
 }
Esempio n. 28
0
 public IEnumerable<List<GameObject>> GetActionsWithNecessaryObjects(IEnumerable<GameObject> objects, Hero hero)
 {
     yield return objects.Where(x => x.Properties.Contains(Property.Pickable)).ToList();// && hero.HasEmpptyContainer;
 }
Esempio n. 29
0
 public Sleeping(Hero hero)
 {
     _hero = hero;
     this.timestamp = 0;
 }
Esempio n. 30
0
 public bool CanDo(Hero hero, IEnumerable<GameObject> objects)
 {
     throw new System.NotImplementedException();
 }