public EventPacket MakeMouseEventPacket(MouseState mouseState, Position mousePosition)
 {
   MouseEvent mouseEvent = new MouseEvent(mouseState,mousePosition);
   byte[] data = EventCodec.Instance.Serialize<MouseEvent>(mouseEvent);
   EventPacket packet = new EventPacket(EventTypes.MOUSE_INPUT, data);
   return packet;
 }
 public EventPacket MakeKeyboardEventPacket(KeyboardState keyboardState)
 {
   KeyboardEvent keyboardEvent = new KeyboardEvent(keyboardState);
   byte[] data = EventCodec.Instance.Serialize<KeyboardEvent>(keyboardEvent);
   EventPacket packet = new EventPacket(EventTypes.KEYBOARD_INPUT, data);
   return packet;
 }
 void spawnExplosion(EventPacket newEvent)
 {
   //Position position = EventCodec.Instance.BytesToPosition(newEvent.Data);
   ExplosionEvent explosionEvent = EventCodec.Instance.Deserialize<ExplosionEvent>(newEvent.Data);
   IGameObject explosion = _objectFactory.MakeExplosion(explosionEvent.Position, explosionEvent.Intensity);
   _objectContainer.Add(explosion);
 }
 void spawnAirBurst(EventPacket newEvent)
 {
   //Position position = EventCodec.Instance.BytesToPosition(newEvent.Data);
   AirBurstEvent explosionEvent = EventCodec.Instance.Deserialize<AirBurstEvent>(newEvent.Data);
   IGameObject airburst = _objectFactory.MakeAirBurst(explosionEvent.Position, explosionEvent.Intensity);
   _objectContainer.Add(airburst);
 }
Exemple #5
0
 void notifyObservers(EventPacket pendingEvent)
 {
   foreach (IObserver observer in listenerTable[pendingEvent.Type])
   {
     observer.Notify(pendingEvent);
   }
 }
 public EventPacket MakeExplosionEventPacket(Position position, double intensity)
 {
   ExplosionEvent explosion = new ExplosionEvent(position, intensity);
   Console.WriteLine("EvtFact, position is: " + position.X + ":" + position.Y);
   byte[] data = EventCodec.Instance.Serialize<ExplosionEvent>(explosion);
   EventPacket packet = new EventPacket(EventTypes.EXPLOSION, data);
   return packet;
 }
 public EventPacket MakeAirBurstEventPacket(Position position, double intensity)
 {
   AirBurstEvent airBurstEvent = new AirBurstEvent(position, intensity);
   Console.WriteLine("EvtFact, airburst position is: " + position.X + ":" + position.Y);
   byte[] data = EventCodec.Instance.Serialize<AirBurstEvent>(airBurstEvent);
   EventPacket packet = new EventPacket(EventTypes.AIR_BURST, data);
   return packet;
 }
    /// <summary>
    /// Given an initialization vector, returns a packet describing a missile spawn event.
    /// </summary>
    /// <param name="startVector"></param>
    /// <returns>A missile spawn event packet.</returns>
    public EventPacket MakeSpawnMissileEventPacket(Particle startVector)
    {
      SpawnMissileEvent missileSpawn = new SpawnMissileEvent(startVector);
      byte[] eventData = EventCodec.Instance.Serialize<SpawnMissileEvent>(missileSpawn);
      EventPacket eventPacket = new EventPacket(EventTypes.SPAWN_MISSILE, eventData);

      return eventPacket;
    }
 /// <summary>
 /// spawnExplosion() spawns an explosion at an exact location. This version spawns an
 /// explosion at a random location very near to the position specific by event, for a nice
 /// multi-explosion effect.
 /// </summary>
 /// <param name="newEvent"></param>
 void spawnFuzzyExplosion(EventPacket newEvent)
 {
   //Position position = EventCodec.Instance.BytesToPosition(newEvent.Data);
   ExplosionEvent explosionEvent = EventCodec.Instance.Deserialize<ExplosionEvent>(newEvent.Data);
   Position fuzzyPosition = Position.GetFuzzyPosition(explosionEvent.Position, GameParameters.MISSILE_DETONATION_FUZZ_FACTOR);
   IGameObject explosion = _objectFactory.MakeExplosion(fuzzyPosition, explosionEvent.Intensity);
   _objectContainer.Add(explosion);
 }
    /// <summary>
    /// Only discrete mouse clicks are handled for now, which trigger
    /// turret shots, if in active region.
    /// </summary>
    void handleMouseClick(EventPacket newEvent)
    {
      MouseEvent mouseEvent = EventCodec.Instance.Deserialize<MouseEvent>(newEvent.Data);

      //only detect left click rising edge
      if (mouseEvent.IsLeftClick)
      {
        Position target = mouseEvent.EventPosition;
        fireTurret(target);
      }
    }
 /*
  Could demux these using Chain of Responsibility pattern: have this class deque events,
  * then iterate list of listeners, cal dispatch on each, first that returns true break loop
  * and pass event into object.
  */
 public void Notify(EventPacket newEvent)
 {
   switch (newEvent.Type)
   {
     case EventTypes.AIR_BURST:
       spawnAirBurst(newEvent);
       spawnFuzzyAirBurst(newEvent);
       spawnFuzzyAirBurst(newEvent);
       break;
     case EventTypes.SPAWN_MIRV:
       spawnMirv(newEvent);
       break;
     case EventTypes.CITY_DESTROYED:
       break;
     case EventTypes.SPAWN_BOMBER:
       spawnBomber(newEvent);
       break;
     case EventTypes.SPAWN_MISSILE:
       spawnMissile(newEvent);
       break;
     case EventTypes.COLLISION:
       break;
     case EventTypes.EXPLOSION:
       spawnExplosion(newEvent);
       spawnFuzzyExplosion(newEvent);
       spawnFuzzyExplosion(newEvent);
       break;
     case EventTypes.OUT_OF_AMMO:
       break;
     case EventTypes.TURRET_SHOT:
       spawnTurretShot(newEvent);
       break;
     case EventTypes.MOUSE_INPUT:
       handleMouseClick(newEvent);
       break;
     case EventTypes.KEYBOARD_INPUT:
       //Console.WriteLine("Keyboard input received as null...");
       break;
     default:
       Console.WriteLine("ERROR ExplosionObserver notified of unmapped event type: " + newEvent.Type.ToString());
       //GameLogger.Instance.Write("ERROR ExplosionObserver notified of unmapped event type: " + newEvent.Type.ToString());
       break;
   }
 }
 void spawnMirv(EventPacket newEvent)
 {
   SpawnMirvEvent mirvEvent = EventCodec.Instance.Deserialize<SpawnMirvEvent>(newEvent.Data);
   IGameObject mirv = _objectFactory.MakeMirv(mirvEvent.StartVector, mirvEvent.DeployAltitude);
   _objectContainer.Add(mirv);
 }
 void spawnTurretShot(EventPacket newEvent)
 {
   SpawnTurretShotEvent turretShotEvent = EventCodec.Instance.Deserialize<SpawnTurretShotEvent>(newEvent.Data);
   double ang = Position.pointTangent(turretShotEvent.Source,turretShotEvent.Target);
   Particle initialVector = new Particle(GameParameters.TURRET_SHOT_VELOCITY, GameParameters.TURRET_SHOT_ACCELERATION, ang, turretShotEvent.Source);
   IGameObject turretShot = _objectFactory.MakeTurretShot(initialVector,turretShotEvent.Target);
   _objectContainer.Add(turretShot);
 }
 void spawnBomber(EventPacket newEvent)
 {
   SpawnBomberEvent bomberEvent = EventCodec.Instance.Deserialize<SpawnBomberEvent>(newEvent.Data);
   IGameObject bomber = _objectFactory.MakeBomber(bomberEvent.StartPosition);
   _objectContainer.Add(bomber);
 }
 void spawnMissile(EventPacket newEvent)
 {
   SpawnMissileEvent missileSpawn = EventCodec.Instance.Deserialize<SpawnMissileEvent>(newEvent.Data);
   IGameObject missile = _objectFactory.MakeMissile(missileSpawn._startVector);
   _objectContainer.Add(missile);
 }
Exemple #16
0
 public void Receive(EventPacket newEvent)
 {
   eventQueue.Enqueue(newEvent);
 }
Exemple #17
0
    //this is really just an isNullOrEmpty check on the observer list for this key
    public bool HasObservers(EventPacket pendingEvent)
    {
      bool hasObserver = listenerTable[pendingEvent.Type] != null;

      if(listenerTable[pendingEvent.Type] == null)
      {
        hasObserver = false;
      }
      else if (listenerTable[pendingEvent.Type].Count == 0)
      {
        hasObserver = false;
      }

      return hasObserver;
    }
    /// <summary>
    /// For now, this parameterless version just assumes build a random start position
    /// for the bomber. There isn't much randomness except the height.
    /// </summary>
    /// <param name="startPosition"></param>
    /// <returns></returns>
    public EventPacket MakeSpawnBomberEventPacket(Position startPosition)
    {
      SpawnBomberEvent bomberEvent = new SpawnBomberEvent(startPosition);
      byte[] data = EventCodec.Instance.Serialize<SpawnBomberEvent>(bomberEvent);
      EventPacket eventPacket = new EventPacket(EventTypes.SPAWN_BOMBER, data);

      return eventPacket;
    }
    public EventPacket MakeSpawnMirvEventPacket(Particle startVector, double deployAltitude)
    {
      SpawnMirvEvent missileSpawn = new SpawnMirvEvent(startVector,deployAltitude);
      byte[] eventData = EventCodec.Instance.Serialize<SpawnMirvEvent>(missileSpawn);
      EventPacket eventPacket = new EventPacket(EventTypes.SPAWN_MIRV, eventData);

      return eventPacket;
    }
    public EventPacket MakeTurretShotEventPacket(Position source, Position target)
    {
      SpawnTurretShotEvent turretShot = new SpawnTurretShotEvent(source, target);
      byte[] eventData = EventCodec.Instance.Serialize<SpawnTurretShotEvent>(turretShot);
      EventPacket eventPacket = new EventPacket(EventTypes.TURRET_SHOT, eventData);

      return eventPacket;
    }
    /// <summary>
    /// spawnExplosion() spawns an explosion at an exact location. This version spawns an
    /// explosion at a random location very near to the position specific by event, for a nice
    /// multi-explosion effect.
    /// </summary>
    /// <param name="newEvent"></param>
    void spawnFuzzyAirBurst(EventPacket newEvent)
    {
      AirBurstEvent airBurstEvent = EventCodec.Instance.Deserialize<AirBurstEvent>(newEvent.Data);
      Position fuzzyPosition = Position.GetFuzzyPosition(airBurstEvent.Position, GameParameters.MISSILE_DETONATION_FUZZ_FACTOR);

      IGameObject explosion = _objectFactory.MakeAirBurst(fuzzyPosition, airBurstEvent.Intensity);
      _objectContainer.Add(explosion);
    }
Exemple #22
0
 /*
  Notifies subscribers/observers of a dequeued event.
  */
 public void Process(EventPacket pendingEvent)
 {
   if (listenerTable.Keys.Contains(pendingEvent.Type))
   {
     if (HasObservers(pendingEvent))
     {
       notifyObservers(pendingEvent);
     }
     else
     {
       GameLogger.Instance.Write("WARN event type has no observers: " + pendingEvent.Type.ToString());
     }
   }
   else 
   {
     GameLogger.Instance.Write("ERROR EventSystem.Process listener table key not found: "+pendingEvent.Type.ToString());
   }
 }