SHOW:
|
|
- or go back to the newest paste.
1 | private IStrategy currStrategy; | |
2 | - | private Queue<IStrategy> strategies; |
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 | } |