Advertisement
uurha

Untitled

Sep 1st, 2022
1,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private IStrategy currStrategy;
  2.     private Queue<IStrategy> strategies = new Queue<IStrategy>();
  3.  
  4.  
  5.     public void SetStrategy(IStrategy[] strategy)
  6.     {
  7.         currStrategy?.Stop();
  8.  
  9.         strategies = new Queue<IStrategy>(strategy);
  10.     }
  11.  
  12.     public void Stop()
  13.     {
  14.     currStrategy?.Stop();
  15.     strategies.Clear();
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         if(strategies.Count <= 0) return;
  21.         if (currStrategy.Execute())
  22.         {
  23.             currStrategy?.Stop();
  24.             if(strategies.Count <= 0)
  25.             {
  26.                 Stop();
  27.                 return;
  28.             }
  29.             currStrategy = strategies.Dequeue();
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement