Beispiel #1
0
 public int[] FindCreature(Creature creature)
 {
     foreach (int[] list in listOfCoord)
     {
         var iter = map[list[0], list[1]].GetEnumerator();
         while (iter.MoveNext())
         {
             if (iter.Current.Value.Equals(creature))
                 return new int[] { list[0], list[1] };
         }
     }
     return new int[] { -1, -1 };
 }
Beispiel #2
0
 public bool Remove(Creature creature)
 {
     int[] find = this.FindCreature(creature);
     if (find[0]!= -1 || find[1]!= -1)
     {
         map[find[0], find[1]].Remove(creature.Name);
         foreach (int[] val in listOfCoord)
         {
             if (val[0] == find[0] && val[1] == find[1] && map[find[0], find[1]].Count == 0)
             {
                 listOfCoord.Remove(val);
                 return true;
             }
         }
         return true;
     }
     return false;
 }
Beispiel #3
0
 public void spawnCreature(Creature creature)
 {
     int x = rand.Next(Width), y = rand.Next(Height);
     map[x, y].Add(creature.Name, creature);
     AddToListCoord(x, y);
 }
Beispiel #4
0
 public void SetPosition(Creature creature, int x, int y)
 {
     int[] coord = FindCreature(creature);
     int newX, newY;
     if (coord[0] != -1 || coord[1] != -1)
     {
         newX = coord[0] + x;
         newY = coord[1] + y;
         Remove(creature);
         map[newX, newY].Add(creature.Name, creature);
         AddToListCoord(newX, newY);
         return;
     }
     map[x, y].Add(creature.Name, creature);
     AddToListCoord(x, y);
 }