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); } } } }
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); } } } }
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; } } } }