예제 #1
0
        private void CreatureInBattle(int i)
        {
            if (i != CreatureBaseObjects.IndexOf(CreatureBaseObjects.Find(c => c.XCordinate == CreatureBaseObjects[i].XCordinate && c.YCordinate == CreatureBaseObjects[i].YCordinate)))
            {
                if (CreatureBaseObjects.Any(c => c.XCordinate == CreatureBaseObjects[i].XCordinate && c.YCordinate == CreatureBaseObjects[i].YCordinate))
                {
                    List <CreatureBaseObject> creaturesInBattle = CreatureBaseObjects.FindAll(c => c.XCordinate == CreatureBaseObjects[i].XCordinate && c.YCordinate == CreatureBaseObjects[i].YCordinate);

                    if (creaturesInBattle.Count != 0)
                    {
                        if (creaturesInBattle[1].TotalDamage > creaturesInBattle[0].Defence)
                        {
                            creaturesInBattle[0].Life -= creaturesInBattle[1].TotalDamage - creaturesInBattle[0].Defence;
                        }
                        if (creaturesInBattle[0].TotalDamage > creaturesInBattle[1].Defence)
                        {
                            creaturesInBattle[1].Life -= creaturesInBattle[0].TotalDamage - creaturesInBattle[1].Defence;
                        }

                        if (creaturesInBattle[0].Dead)
                        {
                            creaturesInBattle[0].AfterBattle(creaturesInBattle[1]);
                        }

                        if (creaturesInBattle[1].Dead)
                        {
                            creaturesInBattle[1].AfterBattle(creaturesInBattle[0]);
                        }

                        CreatureBaseObjects.RemoveAll(c => c.Dead);
                    }
                }
            }
        }
예제 #2
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;
                }
            }
        }
 public override void CreateCreatures()
 {
     CreatureBaseObjects.Add(new Phoenix {
         EquipedAttackBaseObject = new Sword()
     });
     CreatureBaseObjects.Add(new Snake());
     CreatureBaseObjects.Add(new Deamon {
         EquipedAttackBaseObject = new Bow(), DefenceBaseObjects = new List <DefenceBaseObject> {
             new Helm(), new Boot()
         }
     });
 }
예제 #4
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);
                    }
                }
            }
        }
예제 #5
0
        protected void GiveCordinates(List <WorldObject> list)
        {
            bool   notSet;
            Random random = new Random();

            foreach (var o in list)
            {
                notSet = true;
                while (notSet)
                {
                    int cordX = random.Next(Size.GetLength(0));
                    int cordY = random.Next(Size.GetLength(1));

                    if (!CreatureBaseObjects.Any(c => c.XCordinate == cordX && c.YCordinate == cordY) &&
                        !BaseObjects.Any(baseObject => baseObject.XCordinate == cordX && baseObject.YCordinate == cordY))
                    {
                        o.XCordinate = cordX;
                        o.YCordinate = cordY;

                        notSet = false;
                    }
                }
            }
        }