Example #1
0
 /*
  * Finding the next position for any creature with current coordinates (x, y)
  * */
 private Library.Pair FindPlaceForSepia(Creature creature, int x, int y)
 {
     bool positionFound = false;
     Random rand = new Random();
     Library.Pair newPosition = new Library.Pair(0, 0);
     MixPositions();
     for (int i = 0; i < _positionsCatalog.Count; i++)
     {
         if (IsLegal(creature, _positionsCatalog[i].X + x, _positionsCatalog[i].Y + y))
         {
             newPosition.X = _positionsCatalog[i].X + x;
             newPosition.Y = _positionsCatalog[i].Y + y;
             positionFound = true;
         }
     }
     if (!positionFound)
     {
         newPosition.X = x;
         newPosition.Y = y;
     }
     return newPosition;
 }
Example #2
0
 /*
  * Finding next position for any Shark. First the creature is looking
  * for Sepia in the near squares if it did not find it's moving to another free random square.
  * This random position is freePosition variable.
  * */
 private Library.Pair FindPlaceForShark(int x, int y)
 {
     MixPositions();
     Library.Pair freePosition = new Library.Pair();
     bool setFreePosition = false;
     for (int i = 0; i < _positionsCatalog.Count; i++)
     {
         if (IsLegal(_simulationField[x, y], x + _positionsCatalog[i].X, y + _positionsCatalog[i].Y))
         {
             if (_simulationField[x + _positionsCatalog[i].X, y + _positionsCatalog[i].Y] is Sepia)
             {
                 return new Library.Pair(x + _positionsCatalog[i].X, y + _positionsCatalog[i].Y);
             }
             else if (!setFreePosition)
             {
                 freePosition = new Library.Pair(x + _positionsCatalog[i].X, y + _positionsCatalog[i].Y);
                 setFreePosition = true;
             }
         }
     }
     return freePosition;
 }
Example #3
0
        /*
         * Finding random place for creature
         * */
        private Library.Pair FindPlaceForCreature()
        {
            Random rand = new Random();
            Library.Pair position = new Library.Pair(0, 0);
            do
            {
                position.X = rand.Next(0, _simulationField.GetLength(0));
                position.Y = rand.Next(0, _simulationField.GetLength(1));

            } while (_simulationField[position.X, position.Y] != null);

            return position;
        }