예제 #1
0
        public void FireIfYouLike(StaticItem source, World world)
        {
            Direction firingDirection = DetermineFiringDirection(source.TilePosition, world.Player.TilePosition);
            if (firingDirection == Direction.None)
                return;
            if (!DoesMonsterHaveClearShotAtPlayer(world, source.TilePosition, firingDirection))
                return;

            var startPos = source.TilePosition.ToPosition() + firingDirection.ToVector() * new Vector2(Tile.Width, Tile.Height) / 2;
            var shot = new StandardShot(world, startPos, firingDirection, source.Energy >> 2, ShotType.Monster);
            world.AddShot(shot);
            world.Game.SoundPlayer.Play(GameSound.MonsterShoots);
        }
        public ShotAndStaticItemInteraction(World world, Shot shot, StaticItem staticItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (shot == null)
                throw new ArgumentNullException("shot");
            if (staticItem == null)
                throw new ArgumentNullException("staticItem");
            if (staticItem is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem");

            this._world = world;
            this._shot = shot;
            this._staticItem = staticItem;
        }
예제 #3
0
        public int CalculateEnergyToRemove(StaticItem si)
        {
            if (!this.IsExtant)
                return 0;

            int r = si.Energy; // LDA &0C0E
            r >>= 2; // LSR A : LSR A
            r -= si.Energy; // SEC : SBC &0C0E
            r ^= 0xFF; // EOR #&FF
            r++; // CLC : ADC #01
            r &= 0xFF;

            int result = si.Energy - r;
            return result;
        }
        public StaticItemAndStaticItemInteraction(World world, StaticItem staticItem1, StaticItem staticItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (staticItem1 == null)
                throw new ArgumentNullException("staticItem1");
            if (staticItem2 == null)
                throw new ArgumentNullException("staticItem2");
            if (staticItem1 is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem1");
            if (staticItem2 is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem2");

            this._world = world;
            this._staticItem1 = staticItem1;
            this._staticItem2 = staticItem2;
        }
        public MovingItemAndStaticItemInteraction(World world, MovingItem movingItem, StaticItem staticItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem == null)
                throw new ArgumentNullException("movingItem");
            if (staticItem == null)
                throw new ArgumentNullException("staticItem");

            if (movingItem is Shot)
                throw new ArgumentOutOfRangeException("movingItem");
            if (staticItem is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem");

            this._world = world;
            this._movingItem = movingItem;
            this._staticItem = staticItem;
        }
예제 #6
0
        public void Fire(StaticItem source, World world, FiringState firingState, Direction direction)
        {
            if (direction == Direction.None)
                throw new ArgumentOutOfRangeException("direction");

            if (firingState != FiringState.Pulse || source.Energy < 4)
                return;
            var startPos = source.TilePosition.ToPosition();
            var shot = new StandardShot(world, startPos, direction, source.Energy >> 2, ShotType.Player);
            if (!shot.CanMoveInDirection(direction))
                return;
            startPos += direction.ToVector() * Tile.Size / 2;
            shot.SetPosition(startPos);

            world.AddShot(shot);
            world.Game.SoundPlayer.Play(GameSound.PlayerShoots);
            _countOfShotsBeforeCostingEnergy--;
            if (_countOfShotsBeforeCostingEnergy < 0)
                {
                _countOfShotsBeforeCostingEnergy = 3;
                source.ReduceEnergy(1);
                }
        }
예제 #7
0
        public IEnumerable<StaticItem> GetGameObjects(World world)
        {
            var exceptions = new List<TileException>();
            Tile[,] tiles;

            var result = new List<StaticItem>();
            var walls = GetLayout(world, out tiles);
            result.AddRange(walls);

            int initialWorldId = GetStartingWorldAreaId();
            StartState ss = GetStartStateForWorldAreaId(initialWorldId);

            var player = new Player(world, ss.PlayerPosition.ToPosition(), ss.PlayerEnergy);
            result.Add(player);
            var playerStartPositions = this._worldAreas.Where(wa => wa.StartState != null).Select(wa => new Grave(world, wa.StartState.PlayerPosition.ToPosition()));
            exceptions.AddRange(SetTileOccupation(ref tiles, playerStartPositions, false));

            var objects = this._xmlDoc.SelectNodes("World/Objects/*");
            if (objects == null)
                throw new InvalidOperationException("No Objects node in world definition.");
            foreach (XmlElement definition in objects)
                {
                StaticItem[] newItems;

                switch (definition.LocalName)
                    {
                    case "Boulder":
                        {
                        newItems = new StaticItem[] { GetBoulder(world, definition) };
                        break;
                        }

                    case "Monster":
                        {
                        newItems = new StaticItem[] { GetMonster(world, definition) };
                        break;
                        }

                    case "Crystal":
                        {
                        newItems = new StaticItem[] { GetCrystal(world, definition) };
                        break;
                        }

                    case "ForceField":
                        {
                        newItems = GetForceFields(world, definition).Cast<StaticItem>().ToArray();
                        break;
                        }

                    case "CrumblyWall":
                        {
                        newItems = new StaticItem[] { GetCrumblyWall(world, definition) };
                        break;
                        }

                    default:
                        throw new InvalidOperationException("Unknown object " + definition.LocalName);
                    }

                result.AddRange(newItems);
                exceptions.AddRange(SetTileOccupation(ref tiles, newItems.Where(item => !(item is Monster.Monster) || ((Monster.Monster) item).IsStill), false));
                }

            var fruit = GetListOfFruit(world, ref tiles);
            result.AddRange(fruit);

            exceptions.AddRange(SetTileOccupation(ref tiles, result.OfType<Monster.Monster>().Where(m => !m.IsStill), true));

            ReviewPotentiallyOccupiedTiles(ref tiles, exceptions);

            if (exceptions.Count != 0)
                {
                string message = string.Empty;
                var errors = exceptions.Where(te=>te.Type == TileExceptionType.Error).ToList();
                var warnings = exceptions.Where(te=>te.Type == TileExceptionType.Warning).ToList();
                foreach (TileException te in errors)
                    {
                    if (message.Length != 0)
                        message += "\r\n";
                    message += string.Format("{0} - {1}", te.Type, te.Message);
                    }
                if (warnings.Any())
                    {
                    if (message.Length != 0)
                        message += "\r\n";
                    foreach (TileException te in warnings)
                        {
                        if (message.Length != 0)
                            message += "\r\n";
                        message += string.Format("{0} - {1}", te.Type, te.Message);
                        }
                    }
                if (errors.Any())
                    throw new InvalidOperationException(message);
                Trace.WriteLine(message);
                var dr = MessageBox.Show(message, "Warnings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dr == DialogResult.Cancel)
                    throw new InvalidOperationException(message);
                }

            this._tiles = tiles;
            return result;
        }
예제 #8
0
        private IInteraction BuildInteraction(StaticItem thisGameItem, StaticItem thatGameItem)
        {
            IInteraction result;
            var items = new[] { thisGameItem, thatGameItem };
            var staticItem = items.FirstOrDefault(item => !(item is MovingItem));
            if (staticItem != null)
                {
                var otherItem = items.Single(item => item != staticItem);
                var movingItem = otherItem as MovingItem;
                if (otherItem is MovingItem)
                    result = new InteractionWithStaticItems(this, staticItem, movingItem);
                else
                    result = new StaticItemAndStaticItemInteraction(this, staticItem, otherItem);
                }
            else
                {
                result = new InteractionWithMovingItems(this, (MovingItem) thisGameItem, (MovingItem) thatGameItem);
                }

            //var shot = items.OfType<Shot>().FirstOrDefault();
            //if (shot != null)
            //    {
            //    var otherItem = items.Single(item => item != shot);
            //    var movingItem = otherItem as MovingItem;
            //    result = movingItem != null
            //        ? (IInteraction) new ShotAndMovingItemInteraction(this, shot, movingItem)
            //        : new ShotAndStaticItemInteraction(this, shot, otherItem);
            //    }
            //else
            //    {
            //    var movingItem = items.OfType<MovingItem>().FirstOrDefault();
            //    if (movingItem != null)
            //        {
            //        var otherItem = items.Single(item => item != movingItem);
            //        var otherMovingItem = otherItem as MovingItem;
            //        result = otherMovingItem != null
            //            ? (IInteraction) new MovingItemAndMovingItemInteraction(this, movingItem, otherMovingItem)
            //            : new MovingItemAndStaticItemInteraction(this, movingItem, otherItem);
            //        }
            //    else
            //        result = new StaticItemAndStaticItemInteraction(this, thisGameItem, thatGameItem);
            //    }
            return result;
        }