public override void move() { //detect nearest boring and move towards it if (myWorld.stuff.Contains(myWorld.stuff.OfType <Boring>().FirstOrDefault())) { Boring target = myWorld.stuff.OfType <Boring>().FirstOrDefault(); if (this.Xpos < target.Xpos) { this.Xpos += 1; } else if (this.Xpos > target.Xpos) { this.Xpos -= 1; } else if (this.Ypos < target.Ypos) { this.Ypos += 1; } else if (this.Ypos > target.Ypos) { this.Ypos -= 1; } if (this.Ypos == target.Ypos && this.Xpos == target.Xpos) { //eat the Boring myWorld.stuff.Remove(target); } } }
static void Main(string[] args) { World myWorld = new World("bob"); Creature bug = new Creature("logan"); RBug bug3 = new RBug("logan"); myWorld.stuff.Add(bug3); Reptar bug7 = new Reptar("logan"); myWorld.stuff.Add(bug7); Boring bug2 = new Boring("logan", 0, 0); myWorld.stuff.Add(bug2); Knight knight = new Knight("race"); myWorld.stuff.Add(knight); Boring bug47 = new Boring("logan2", 3, 0); myWorld.stuff.Add(bug47); Boring bug42 = new Boring("justin", 0, 3); myWorld.stuff.Add(bug42); Box bugsy = new Box("cj"); myWorld.stuff.Add(bugsy); Hungry bug99 = new Hungry("race", myWorld); myWorld.stuff.Add(bug99); //instantiate and add an instance of your creature subclass to the stuff list in myWorld //Console.WriteLine(myWorld.draw()); //Console.WriteLine(myWorld.sayName()); aTimer = new System.Timers.Timer(); aTimer.Interval = 1000; // Hook up the Elapsed event for the timer. // aTimer.Elapsed += render; aTimer.Elapsed += (sender, e) => render(sender, e, myWorld); // Have the timer fire repeated events (true is the default) aTimer.AutoReset = true; // Start the timer aTimer.Enabled = true; Console.WriteLine("Press the Enter key to exit anytime... "); Console.ReadLine(); }