コード例 #1
0
ファイル: Simulation.cs プロジェクト: mgechev/WaTor
 /*
  * Sepia spawn
  * */
 private void SpawnSepia(Sepia creature)
 {
     for (int i = 0; i < _sepiasChildren; i++)
     {
         Creature child;
         child = new Sepia(creature.LifeTime, new Library.Pair());
         if (i == 0)
         {
             KillCreature(creature.Position.X, creature.Position.Y);
             child.Position = creature.Position;
         }
         else
         {
             child.Position = FindPlaceForSepia(child, creature.Position.X, creature.Position.Y);
         }
         _simulationField[child.Position.X, child.Position.Y] = child;
     }
 }
コード例 #2
0
ファイル: Simulation.cs プロジェクト: mgechev/WaTor
        /*
         * Initializing the field
         * */
        private void InitializeField(Library.Pair size)
        {
            _simulationField = new Creature[size.X, size.Y];

            for (int i = 0; i < _sharksCount; i++)
            {
                Library.Pair position = FindPlaceForCreature();
                Shark shark = new Shark(_sharksLifeTime, 0, _sharksHunger, position);
                _simulationField[position.X, position.Y] = shark;
            }
            for (int i = 0; i < _sepiasCount; i++)
            {
                Library.Pair position = FindPlaceForCreature();
                Sepia sepia = new Sepia(_sepiasLifeTime, position);
                _simulationField[position.X, position.Y] = sepia;
            }
        }
コード例 #3
0
ファイル: Simulation.cs プロジェクト: mgechev/WaTor
 /*
  * Moveing Sepia
  * */
 private void MoveSepia(Sepia creature, int x, int y)
 {
     Library.Pair position = FindPlaceForSepia(creature, x, y);
     if (_simulationField[position.X, position.Y] is Shark)
     {
         KillCreature(x, y);
         try
         {
             ((Shark)_simulationField[position.X, position.Y]).Hunger = 0;
         }
         catch (Exception) { }
     }
     else
     {
         _simulationField[x, y] = null;
         _simulationField[position.X, position.Y] = creature;
     }
 }
コード例 #4
0
ファイル: Simulation.cs プロジェクト: mgechev/WaTor
 /*
  * Checking if sepia is old enough to have children
  * */
 private bool CheckForSpawnSepia(Sepia creature)
 {
     if (creature.Age == 2 * creature.LifeTime / 3)
     {
         SpawnSepia(creature);
         return true;
     }
     return false;
 }