Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Flocking
  5. {
  6.     public class SubMission
  7.     {  
  8.         private List<Goal> goals; // goals that need to be accomplished for this mission
  9.        
  10.         public SubMission()
  11.         {
  12.             goals = new List<Goal>();
  13.         }
  14.        
  15.         public void AddGoal(Goal goal)
  16.         {
  17.             goals.Add(goal);
  18.         }
  19.        
  20.         public void Update(float dt)
  21.         {
  22.             foreach(var goal in goals)
  23.                 goal.Update(dt);
  24.         }
  25.        
  26.         public Goal.State GetState()
  27.         {
  28.             int goalsInProgress = 0;
  29.            
  30.             foreach(var goal in goals)
  31.             {
  32.                 switch(goal.GetState())
  33.                 {
  34.                 // if a goal has failed, return Failed
  35.                 case Goal.State.Failed:
  36.                     return Goal.State.Failed;
  37.                    
  38.                 case Goal.State.InProgress:
  39.                     ++goalsInProgress;
  40.                     break;
  41.                 }
  42.             }
  43.            
  44.             // if there are no goals in progress, it means all goals were completed
  45.                 if( goalsInProgress == 0 )
  46.                     return Goal.State.Accomplished;
  47.                
  48.                 return Goal.State.InProgress;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement