//Listens to input from mouse and keyboard and carries out appropriate actions
        public void KeyboardListener(KeyboardState CurrentKeyboardState, KeyboardState LastKeyboardState, MouseState CurrentMouseState, MouseState LastMouseState)
        {
            //Creates an instance of a units at the position of the mouse when V is held down and left mouse button clicked
            if ((CurrentMouseState.LeftButton == ButtonState.Released && LastMouseState.LeftButton == ButtonState.Pressed) &&
                (CurrentKeyboardState.IsKeyDown(Keys.V)))
            {
                BaseUnit newUnit;
                newUnit = new Velociraptor();
                newUnit.Build(new Vector2(CurrentMouseState.X, CurrentMouseState.Y));
                mUnits.Add(newUnit);
            }

            if ((CurrentMouseState.LeftButton == ButtonState.Released && LastMouseState.LeftButton == ButtonState.Pressed) &&
            (CurrentKeyboardState.IsKeyDown(Keys.B)))
            {
                BaseUnit newUnit;
                newUnit = new BearCavalry();
                newUnit.Build(new Vector2(CurrentMouseState.X, CurrentMouseState.Y));
                mUnits.Add(newUnit);
            }

            if ((CurrentMouseState.LeftButton == ButtonState.Released && LastMouseState.LeftButton == ButtonState.Pressed) &&
            (CurrentKeyboardState.IsKeyDown(Keys.T)))
            {
                BaseUnit newUnit;
                newUnit = new Tank();
                newUnit.Build(new Vector2(CurrentMouseState.X, CurrentMouseState.Y));
                mUnits.Add(newUnit);
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     var velociraptor = new Velociraptor("Brown", "Small");
     var triceratops  = new Triceratops();
     var dinoHandler  = new DinoHandler();
     var forklift     = new Forklift();
 }
Beispiel #3
0
        private static void WelcomeToTheZoo()
        {
            Console.WriteLine("Welcome to my zoo!");



            Console.Write("We have a Lion that:");

            Lion lion = new Lion();

            Console.WriteLine(lion.Scratch());


            Console.Write("We have a Tiger that:");

            Tiger tiger = new Tiger();

            Console.WriteLine(tiger.Hunt());


            Console.Write("We have a Bear that:");

            Bear bear = new Bear();

            Console.WriteLine(bear.Sleep());


            Console.Write("We have a Crocodile that:");

            Crocodile crocodile = new Crocodile();

            Console.WriteLine(crocodile.Move());


            Console.Write("And a Velociraptor that:");

            Velociraptor velociraptor = new Velociraptor();

            Console.WriteLine(velociraptor.Move());

            Console.WriteLine("This is probably the best zoo ever");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //
            // OLD MACDONALD
            //
            Chicken      chicken = new Chicken();
            Cow          cow     = new Cow();
            Duck         duck    = new Duck();
            Velociraptor cicero  = new Velociraptor();
            Platypus     occam   = new Platypus();

            // Show implicit casting (Chicken to Farm Animal)
            FarmAnimal console = duck;

            Console.WriteLine(console.NameOfAnimal);
            Console.WriteLine(console.MakeSoundOnce());
            Console.WriteLine(console.MakeSoundTwice());
            Console.WriteLine();

            // Show explicit casting (FarmAnimal to Chicken)
            Duck myDuck = (Duck)console;

            Console.WriteLine(myDuck.NameOfAnimal);
            Console.WriteLine(myDuck.MakeSoundOnce());
            Console.WriteLine(myDuck.MakeSoundTwice());
            Console.WriteLine();

            //Applying Polymorphism, we're allowed to work in terms of
            // generic types and not concrete classes. In this case
            // the list holds a collection of IFarmAnimal, meaning
            // any class that implements the IFarmAnimal interface is allowed
            // to be in the list.
            //Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh");

            //Console.WriteLine("And on his farm there was a " + chicken.NameOfAnimal + " ee ay ee ay oh");
            //Console.WriteLine("With a " + chicken.MakeSoundTwice() + " here and a " + chicken.MakeSoundTwice() + " there");
            //Console.WriteLine("Here a " + chicken.MakeSoundOnce() + ", there a " + chicken.MakeSoundOnce() + " everywhere a " + chicken.MakeSoundTwice());
            //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
            //Console.WriteLine();

            //Console.WriteLine("And on his farm there was a " + cow.NameOfAnimal + " ee ay ee ay oh");
            //Console.WriteLine("With a " + cow.MakeSoundTwice() + " here and a " + cow.MakeSoundTwice() + " there");
            //Console.WriteLine("Here a " + cow.MakeSoundOnce() + ", there a " + cow.MakeSoundOnce() + " everywhere a " + cow.MakeSoundTwice());
            //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
            //Console.WriteLine();

            //Console.WriteLine("And on his farm there was a " + duck.NameOfAnimal + " ee ay ee ay oh");
            //Console.WriteLine("With a " + duck.MakeSoundTwice() + " here and a " + duck.MakeSoundTwice() + " there");
            //Console.WriteLine("Here a " + duck.MakeSoundOnce() + ", there a " + duck.MakeSoundOnce() + " everywhere a " + duck.MakeSoundTwice());
            //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
            //Console.WriteLine();

            // ----- THIS IS GETTING REPETITIVE!
            // We can do better
            // How can we use what we've learned about inheritance
            // to help us remove code duplication
            //
            // What if we create some sort of base class that all our animals have in common?

            List <FarmAnimal> animals = new List <FarmAnimal>();

            animals.Add(chicken);
            animals.Add(cow);
            animals.Add(duck);

            Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh");
            foreach (FarmAnimal animal in animals)
            {
                Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh");
                Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there");
                Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice());
                Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
                Console.WriteLine();
            }

            // Interface
            List <IFarmAnimal> interfaceAnimals = new List <IFarmAnimal>();

            interfaceAnimals.Add(cicero);
            interfaceAnimals.Add(occam);

            Console.WriteLine();
            Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh");
            foreach (IFarmAnimal animal in interfaceAnimals)
            {
                Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh");
                Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there");
                Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice());
                Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
                Console.WriteLine();
            }


            George friend = new George();

            friend.Fly();
            Console.WriteLine(friend.NameOfAnimal);
            Console.WriteLine(friend.MakeSoundOnce());
            Console.WriteLine(friend.MakeSoundTwice());
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            int width = 25;

            Console.WriteLine(CreateRow("Employee", "Hours Worked", "Total Weekly Pay", width));
            Console.WriteLine();
            Console.WriteLine(CreateRow("Bob Mackey", "20", "200", width));

            Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Employee", "Hours Worked", "Total Weekly Pay");
            Console.WriteLine();
            Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Bob Mackey", "20", "200");

            Console.ReadKey();
        }
Beispiel #5
0
        public void ShouldMove()
        {
            Velociraptor velocionel = new Velociraptor();

            Assert.Equal(" hops over tables and stairs", velocionel.Move());
        }
Beispiel #6
0
        public void ShouldHunt()
        {
            Velociraptor velocionel = new Velociraptor();

            Assert.Equal(" waits for it's prey to stop moving", velocionel.Hunt());
        }