Skip to content

Defining Game Events

Christian Oeing edited this page Jan 8, 2017 · 1 revision

In the Slash Framework, each event has an event type and event data. You can easily define event types by creating your own enum:

public enum RPGGameEvent
{
	/// <summary>
	///   Entity health has been reduced.
	/// </summary>
	DamageTaken,
  
	/// <summary>
	///   Door has been closed.
	/// </summary>
	DoorClosed,
  
	/// <summary>
	///   Current player turn has ended.
	/// </summary>
	EndOfTurn
}

Some events don’t require more than a single value as data. The DoorClosed event from the above code snipped might be satisfied with just handing over the id of the door entity that has been closed. The EndOfTurn event might require no data at all. In case you need to pass more event data, just create your own data classes:

public class DamageTakenData
{
	/// <summary>
	///   Id of the entity whose health has been reduces.
	/// </summary>
	public int EntityId { get; set; }
  
	/// <summary>
	///   Amount of damage taken by the entity.
	/// </summary>
	public int Damage { get; set; }
}