I'm working on a simple little program/game where I'm simulating a standoff. I want an event to trigger when one of the enemy objects aims at the other (so that it can adjust its trust properties accordingly).
In the 'Enemy' class, I've put the following (I've cut out the parts with properties and constructors so this doesn't take up so much space):
public event EventHandler RexAim;
public void OnRexAim()
{
if (RexAim != null)
RexAim(this, EventArgs.Empty);
}
public void RexAimAt()
{
Console.WriteLine("This is the aiming method leaping into action.");
OnRexAim();
}
And then in the Program class, I have this:
class Program
{
static void Main(string[] args)
{
// Constructing the characters so I can use them in things:
Enemy rex = new Enemy(100, -100, 5, 2, "Rex");
Enemy pearl = new Enemy(100, -50, -5, 0, "Pearl");
Enemy archie = new Enemy(75, -100, 0, 3, "Archie");
Enemy betty = new Enemy(100, -75, 0, 5, "Betty");
pearl.RexAim += HandleRexAim;
rex.RexAimAt();
}
public static void HandleRexAim(object sender, EventArgs eventArgs)
{
Console.WriteLine("This should show up if the event worked properly.");
}
}
But when I run it, all I get is the "This is the aiming method leaping into action" displayed.
I'm sure I'm making a very elementary mistake here (I'm a beginner at this), but I just can't wrap my head around what's not working.
Thanks in advance for your patience with someone so new to this!