Exemple #1
0
 public void CreatePlayers(UpdatableObjects updatableObjects, DrawableObjects drawableObjects, bool isPlayer, int quantity)
 {
     for (int i = 0; i < quantity; i++)
     {
         CreatePlayer(updatableObjects, drawableObjects, isPlayer);
     }
 }
Exemple #2
0
 public void CreateFood(UpdatableObjects updatableObjects, DrawableObjects drawableObjects, int quantity)
 {
     for (int i = 0; i < quantity; i++)
     {
         Food food = new Food();
         RegisterObject(updatableObjects, drawableObjects, food);
     }
 }
Exemple #3
0
        public void CreatePlayer(UpdatableObjects updatableObjects, DrawableObjects drawableObjects, bool isPlayer)
        {
            Player newPlayer = new Player();

            newPlayer.Init();
            newPlayer.SetIsPlayer(isPlayer);
            RegisterObject(updatableObjects, drawableObjects, newPlayer);
        }
Exemple #4
0
 public void UnregisterObject(UpdatableObjects updatableObjects, DrawableObjects drawableObjects, IUpdatable updatable)
 {
     if (updatable is IUpdatable)
     {
         updatableObjects.Remove(updatable);
     }
     if (updatable is IDrawable)
     {
         drawableObjects.Remove(updatable as IDrawable);
     }
 }
Exemple #5
0
 public void RegisterObject(UpdatableObjects updatableObjects, DrawableObjects drawableObjects, IUpdatable updatable)
 {
     if (updatable is IUpdatable)
     {
         updatableObjects.Add(updatable);
     }
     if (updatable is IDrawable)
     {
         drawableObjects.Add(updatable as IDrawable);
     }
 }
Exemple #6
0
        public void RemoveCachedObjectsAndCreateNew(UpdatableObjects updatableObjects, DrawableObjects drawable)
        {
            foreach (IUpdatable updatable in objectsToRemove)
            {
                UnregisterObject(updatableObjects, drawable, updatable);
                if (updatable is Player)
                {
                    CreatePlayer(updatableObjects, drawable, false);
                }
                if (updatable is Food)
                {
                    RegisterObject(updatableObjects, drawable, new Food());
                }
            }

            objectsToRemove = new List <IUpdatable>();
        }
Exemple #7
0
        public void ChangePlayerAndReplaceBots(UpdatableObjects updatableObjects)
        {
            Player player        = null;
            Player currentPlayer = updatableObjects.GetPlayer();
            Random rand          = new Random();
            int    r             = rand.Next(0, updatableObjects.GetBots().Count);
            int    i             = 0;

            foreach (Player bot in updatableObjects.GetBots())
            {
                if (i == r)
                {
                    player = bot;
                }
                i++;
            }
            ReplaceBotAndChangeStatus(currentPlayer, player);
        }