예제 #1
0
        private void CheckCreatureMovement(Random random, int i)
        {
            bool notMoved = true;

            while (notMoved)
            {
                int moveX = random.Next(-1, 2);
                int moveY = random.Next(-1, 2);

                int newXCordinate = CreatureBaseObjects[i].XCordinate + moveX;
                int newYCordinate = CreatureBaseObjects[i].YCordinate + moveY;

                if (newXCordinate >= 0 &&
                    newXCordinate <= Size.GetLength(0) - 1 &&
                    newYCordinate >= 0 &&
                    newYCordinate <= Size.GetLength(1) - 1 &&
                    Size[newXCordinate, newYCordinate].GetType() != typeof(Rock) &&
                    Size[newXCordinate, newYCordinate].GetType() != typeof(Tree))
                {
                    if (Size[newXCordinate, newYCordinate].GetType() == typeof(Chest))
                    {
                        Chest chest = (Chest)Size[newXCordinate, newYCordinate];

                        if (chest.AttackBaseObjectBonus != null)
                        {
                            CreatureBaseObjects[i].EquipedAttackBaseObject = chest.AttackBaseObjectBonus;
                        }

                        if (chest.DefenceBaseObjectBonus != null)
                        {
                            if (!CreatureBaseObjects[i].DefenceBaseObjects.Any(d => d.Name.Contains(chest.DefenceBaseObjectBonus.Name)))
                            {
                                CreatureBaseObjects[i].DefenceBaseObjects.Add(chest.DefenceBaseObjectBonus);
                            }

                            CreatureBaseObjects[i].CalculateDefence();
                        }

                        BaseObjects.Remove(BaseObjects.Find(baseObject => baseObject.XCordinate == newXCordinate && baseObject.YCordinate == newYCordinate));
                    }
                    if (Size[newXCordinate, newYCordinate].GetType() == typeof(Lava))
                    {
                        CreatureBaseObjects[i].Life -= 1;
                        if (CreatureBaseObjects[i].Dead)
                        {
                            CreatureBaseObjects.RemoveAt(i);
                        }
                    }

                    CreatureBaseObjects[i].XCordinate += moveX;
                    CreatureBaseObjects[i].YCordinate += moveY;
                    notMoved = false;
                }
            }
        }
예제 #2
0
        protected void PopulateWorld()
        {
            for (int x = 0; x < Size.GetLength(0); x++)
            {
                for (int y = 0; y < Size.GetLength(1); y++)
                {
                    if (BaseObjects.Any(baseObjects => baseObjects.XCordinate == x && baseObjects.YCordinate == y))
                    {
                        Size[x, y] = BaseObjects.Find(baseObjects => baseObjects.XCordinate == x && baseObjects.YCordinate == y);
                    }

                    if (CreatureBaseObjects.Any(creatureBaseObjects => creatureBaseObjects.XCordinate == x && creatureBaseObjects.YCordinate == y))
                    {
                        Size[x, y] = CreatureBaseObjects.Find(creatureBaseObjects => creatureBaseObjects.XCordinate == x && creatureBaseObjects.YCordinate == y);
                    }
                }
            }
        }