Ejemplo n.º 1
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new[] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );



                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1,          3, map)),
                    new PowerfulTower(new MapLocation(3,  3, map)),
                    new LongrangeTower(new MapLocation(4, 4, map)),
                    new AccurateTower(new MapLocation(5,  3, map))
                };

                Level leve1 = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = leve1.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            //debugging tools
            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                });

                Invader[] invaders =
                {
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                    new Invader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map))
                };


                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();


                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                //used for future proofing
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception)
            {
                //used for future proofing
                Console.WriteLine("Unhandled Exception");
            }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            //Tower tower = new Tower(); // TypeOfObject NameOfObject = new TowerObject (A tower instance)
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map),
                }
                    );

                Invader[] invaders =
                {
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                    new Invader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map)),
                };

                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }

            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }

            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            // this creates a new variable "map" that is of type Map and assigns it a new Map() object
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map),
                }
                    );

                Invader[] invaders =
                {
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map)),
                };

                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
            // declaring a variable for the exception "ex"
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                });

                Invader[] invaders =
                {
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                    new Invader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map)),
                };

                Level level = new Level(invaders)
                {
                    towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefeseException)
            {
                Console.WriteLine("Unhandles TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandles Exception: " + ex);
            }

            // Console.WriteLine("barhoring");
            // Point y = new MapLocation(7, 6, map);
        }
Ejemplo n.º 6
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                });
                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new BasicArmedInvader(path),
                    new ResurrectingInvader(path),
                    new ResurrectingInvader(path),
                    new BasicInvader(path),
                };
                Tower[] towers = new Tower[]
                {
                    new Tower(new MapLocation(1, 3, map), map, path),
                    new Tower(new MapLocation(4, 3, map), map, path),
                    new Tower(new MapLocation(2, 1, map), map, path),
                    new StrongTower(new MapLocation(7, 3, map), map, path),
                    new SniperTower(new MapLocation(3, 3, map), map, path)
                };
                Level level = new Level(invaders)
                {
                    Towers = towers
                };
                bool playerWon = level.Play();
                Console.WriteLine($"Player " + (playerWon? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex);
            }
            catch (TreehouseDefenseException ex)
            {
                Console.WriteLine($"Unhandled TreehouseDefenseException: {ex}");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 7
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map),
                }
                    );

                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path)
                    new ResurrectingInvader(path),
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map)),
                };

                Level level = new Level(invaders);
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Map  map  = new Map(8, 5);
            Path path = new Path(
                new[] {
                new MapLocation(0, 2, map),
                new MapLocation(1, 2, map),
                new MapLocation(2, 2, map),
                new MapLocation(3, 2, map),
                new MapLocation(4, 2, map),
                new MapLocation(5, 2, map),
                new MapLocation(6, 2, map),
                new MapLocation(7, 2, map),
            });

            var invaders = new Invader[]
            {
                new Invader(path),
                new Invader(path),
                new Invader(path),
                new Invader(path)
            };

            var towers = new Tower[]
            {
                new Tower(new MapLocation(1, 3, map), path),
                new Tower(new MapLocation(3, 3, map), path),
                new Tower(new MapLocation(5, 3, map), path),
            };

            Level level = new Level(invaders)
            {
                Towers = towers
            };

            Console.WriteLine("Player " + (level.Play() ? "won" : "lost"));
            Console.ReadKey(intercept: true);
        }
Ejemplo n.º 9
0
        public LevelOne()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new []
                {
                    new MapLocation(0, 1, map),
                    new MapLocation(1, 1, map),
                    new MapLocation(2, 1, map),
                    new MapLocation(3, 1, map),
                    new MapLocation(4, 1, map),
                    new MapLocation(5, 1, map),
                    new MapLocation(6, 1, map),
                    new MapLocation(7, 1, map),
                }
                    );

                IInvader[] invaders =
                {
                    new BasicInvader(path),
                    new BasicInvader(path),
                    new ShieldedInvader(path),
                    new FastInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation((PlayersTowers1.tower1X - 1),      (PlayersTowers1.tower1Y - 1), map), map),
                    new Tower(new MapLocation((PlayersTowers1.tower2X - 1),      (PlayersTowers1.tower2Y - 1), map), map),
                    new Tower(new MapLocation((PlayersTowers1.tower3X - 1),      (PlayersTowers1.tower3Y - 1), map), map),
                    new PowerTower(new MapLocation((PlayersTowers1.tower4X - 1), (PlayersTowers1.tower4Y - 1), map), map)
                };

                Level level = new Level(invaders)
                {
                    towers = towers
                };

                bool playwerWon = level.Play();
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("You " + (playwerWon ? "Won!" : "lost..."));
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            catch (OutOfBoundsException ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            catch (TreehouesDefenseException)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Unhandled TreehouseDefenseException");
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Unhandled Exception: " + ex);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
Ejemplo n.º 10
0
        public static void Main(String[] args)
        {
            // Outputs empty line.
            Console.WriteLine("");
            // Outputs to the console.
            Console.WriteLine("############# Running Program ##################");
            // Outputs empty line.
            Console.WriteLine("");

            // Builds object from the class Map.
            // Constructor takes two parameters.
            Map map = new Map(8, 5);

            // Builds object from the MapLocation
            // class. Constuctor takes three parameters.
            // variables x and y and an object from the class
            // map.
            // Builds try and catch exception
            try {
                // Builds object from the class Path.
                // Constructor takes one parameter,
                // an array of objects from the class MapLocation.
                Path path = new Path(

                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }

                    );


                // Builds object from the class MapLocation.
                // Contructor takes three parameters.
                MapLocation location = new MapLocation(0, 2, map);

                // Builds an array of object from the interface IInvaders.
                // This code below is an example of polymorphism.
                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };

                // Builds an array of objects from the class Tower.
                Tower[] towers =
                {
                    // Builds object.
                    // Takes three parameters.
                    new Tower(new MapLocation(1,          3, map)),
                    new PowerfulTower(new MapLocation(3,  3, map)),
                    new SniperTower(new MapLocation(5,    3, map)),
                    new LongRangeTower(new MapLocation(2, 4, map))
                };

                // Builds object from the class Level.
                // Takes one parameter,
                // the array of objects from the class level.
                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                // Initializes variable.
                // Stores method call.
                // Takes no parameters.
                bool playerWon = level.Play();

                // Outputs to the console.
                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            } catch (OutOfBoundsException ex) {
                // Outputs to the console
                // if exception is thrown.
                Console.WriteLine(ex.Message);
            } catch (TreehouseDefenseException) {
                // Outputs to the console.
                Console.WriteLine("unhandled TreehouseDefenseException");
            } catch (Exception ex) {
                // Outputs to the console.
                Console.WriteLine("Unhandled Exception: " + ex);
            }


            // Outputs empty line.
            Console.WriteLine("");
            // Outputs to the console.
            Console.WriteLine("###################### Exiting Program #####################");
            // Outputs empty line.
            Console.WriteLine("");
        }
Ejemplo n.º 11
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new[] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                MapLocation location = new MapLocation(0, 2, map);

                if (path.IsOnPath(location))
                {
                    Console.WriteLine(location + " is on the path");
                    return;
                }

                Invader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1,          3, map)),
                    new PowerfulTower(new MapLocation(3,  3, map)),
                    new SniperTower(new MapLocation(5,    3, map)),
                    new LongrangeTower(new MapLocation(2, 4, map))
                };

                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreeHouseDefenseException)
            {
                Console.WriteLine("Unhandled TreeHouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex.Message);
            }
        }
Ejemplo n.º 12
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                Invader[] invaders =
                {
                    new Invader(path),
                    new Invader(path),
                    new Invader(path),
                    new Invader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map))
                };
                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool PlayerWon = level.Play();

                Console.WriteLine("Player " + (PlayerWon?"Won!":"Lost!"));
                Console.ReadLine();
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled Treehouse Defense exception!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled exception!" + ex);
            }

            /*
             * Point point = new Point(4,2);
             * Point point2= new Point(4,4);
             *
             * Console.WriteLine(point.DistanceTo(5,5));
             * Console.WriteLine(point.DistanceTo(point2));
             */
        }
Ejemplo n.º 13
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new[] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                IInvader[] invaders =
                { new ShieldedInvader(path),
                  new FastInvader(path),
                  new StrongInvader(path),
                  new BasicInvader(path),
                  new ResurrectingInvader(path) };

                //TODO: Prompt user to place towers via command-line
                Console.WriteLine("Enter x coordinate for Tower 1:");
                string towerOneX = Console.ReadLine();
                Console.WriteLine("Enter y coordinate for Tower 1:");
                string towerOneY = Console.ReadLine();
                Console.WriteLine("Enter x coordinate for Tower 2:");
                string towerTwoX = Console.ReadLine();
                Console.WriteLine("Enter y coordinate for Tower 2:");
                string towerTwoY = Console.ReadLine();
                Console.WriteLine("Enter x coordinate for Tower 3:");
                string towerThreeX = Console.ReadLine();
                Console.WriteLine("Enter y coordinate for Tower 3:");
                string towerThreeY = Console.ReadLine();


                Tower[] towers =
                {
                    new Tower(new MapLocation(int.Parse(towerOneX),   int.Parse(towerOneY),   map)),
                    new Tower(new MapLocation(int.Parse(towerTwoX),   int.Parse(towerTwoY),   map)),
                    new Tower(new MapLocation(int.Parse(towerThreeX), int.Parse(towerThreeY), map)),
                };

                //Construct Level object and pass it the invaders that will be in the level
                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreeHouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 14
0
        static void Main()
        {
            // convention is to name classes with upper case first letter, so you can name the object by their type (class)
            //object is an instance of a class
            Tower tower = new Tower();

            Map map = new Map(8, 5);
            // map.Width = 8;  //can not do, due to readonly access

            Point point  = new Point(9, 6);
            Point point2 = new Point(2, 3);


            Console.WriteLine(map.Width);
            Console.WriteLine(map.OnMap(point));    //not in bound
            Console.WriteLine(map.OnMap(point2));   //in bound

            Console.WriteLine("---------Overload----------");
            Console.WriteLine(point.DistanceTo(2, 3));
            Console.WriteLine(point.DistanceTo(point2));


            Console.WriteLine("---------Inheritance----------");
            MapLocation mappoint = new MapLocation(4, 2, map);

            Console.WriteLine("MapLocation using Point class's distance to: " + mappoint.DistanceTo(point2));
            Console.WriteLine(mappoint is MapLocation);
            Console.WriteLine(mappoint is Point);

            Console.WriteLine("----------Exception---------");
            //exception
            try
            {
                //maplocation throws exception in the constructor (MapLocation.cs)
                MapLocation mapLocation = new MapLocation(1000, 1000, map);
            }
            catch (OutOfBoundsException o_ex)
            {
                Console.WriteLine(o_ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("----------Level---------");
            Path path = new Path(
                new[]
            {
                new MapLocation(0, 2, map),
                new MapLocation(1, 1, map)
            }
                );

            IInvader[] invaders =
            {
                new BasicInvader(path),
                new BasicInvader(path),
                new BasicInvader(path)
            };

            Tower[] towers =
            {
                new Tower(new MapLocation(2, 3, map)),
                new Tower(new MapLocation(3, 3, map))
            };

            Level level = new Level(invaders)
            {
                Towers = towers
            };

            bool playerWon = level.Play();


            Console.ReadLine();
        }
Ejemplo n.º 15
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                MapLocation location = new MapLocation(0, 2, map);

                /*if(path.IsOnPath(location))
                 * {
                 *  Console.WriteLine(location + " is on the path");
                 *  return; // will exit the function called at this point
                 * }*/

                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1, 3, map)),
                    new Tower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5, 3, map))
                };

                Level leve1 = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = leve1.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 16
0
        public static void Main() //first method that is run in the game
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );
//                MapLocation location = new MapLocation(0,2,map);
//
//                if(path.IsOnPath(location))
//                   {
//                      Console.WriteLine(location + "Location is on the path");
//                      return;
//                   }
//
                IInvader[] invaders =  //Had to change Invader[] = To IInvader[] because ResurrectingInvader is not a type Invader But a IInvader type
                {
//                    new ShieldedInvader(path),
//                    new FastInvader(path),
//                    new StrongInvader(path),
//                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };

                Tower[] towers =
                {
                    new LongRangeTower(new MapLocation(1, 3, map)),
//                    new SniperTower(new MapLocation(3, 3, map)),
//                    new PowerfullTower(new MapLocation(5, 3, map)),
                    new Tower(new MapLocation(7,          3, map)),
                };

                Level leve1 = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = leve1.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 17
0
        public LevelTwo()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new []
                {
                    new MapLocation(0, 3, map),
                    new MapLocation(1, 3, map),
                    new MapLocation(2, 3, map),
                    new MapLocation(3, 3, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(3, 1, map),
                    new MapLocation(4, 1, map),
                    new MapLocation(5, 1, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                IInvader[] invaders =
                {
                    new BasicInvader(path),
                    new BasicInvader(path),
                    new ShieldedInvader(path),
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new ResurrectingInvader(path),
                    new ResurrectingInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation((PlayersTowers2.tower1x - 1),       (PlayersTowers2.tower1y - 1), map), map),
                    new Tower(new MapLocation((PlayersTowers2.tower2x - 1),       (PlayersTowers2.tower2y - 1), map), map),
                    new PowerTower(new MapLocation((PlayersTowers2.tower3x - 1),  (PlayersTowers2.tower2y - 1), map), map),
                    new PowerTower(new MapLocation((PlayersTowers2.tower4x - 1),  (PlayersTowers2.tower3y - 1), map), map),
                    new SniperTower(new MapLocation((PlayersTowers2.tower5x - 1), (PlayersTowers2.tower4y - 1), map), map),
                    new SniperTower(new MapLocation((PlayersTowers2.tower6x - 1), (PlayersTowers2.tower5y - 1), map), map),
                };

                Level level = new Level(invaders)
                {
                    towers = towers
                };

                bool playwerWon = level.Play();
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("You " + (playwerWon ? "Won!" : "lost..."));
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            catch (OutOfBoundsException ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            catch (TreehouesDefenseException)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Unhandled TreehouseDefenseException");
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Unhandled Exception: " + ex);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
Ejemplo n.º 18
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                IInvader[] invaders =
                {
                    new ResurrectingInvader(path),
                    new FastInvader(path),
                    new ShieldedInvader(path),
                    new BasicInvader(path),
                    new FastInvader(path),
                    new ShieldedInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ShieldedInvader(path),
                    new StrongInvader(path)
                };

                // could use the console to let the user assign towers. for now we'll make permanent stuff.
                Tower[] towers =
                {
                    new SniperTower(new MapLocation(6, 4, map)),
                    new PowerTower(new MapLocation(2,  3, map)),
                    new SuperTower(new MapLocation(4,  4, map)),
                    new Tower(new MapLocation(3,       3, map)),
                    new Tower(new MapLocation(3,       3, map)),
                    new RangerTower(new MapLocation(7, 4, map))
                };


                Level level = new Level(invaders)
                {
                    // property intialization list.
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefense Exception");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception." + ex);
            }
        }
Ejemplo n.º 19
0
        public static void Main()
        {
            //Map grid dimensions
            Map map = new Map(8, 5);

            //Invader path
            try
            {
                Path path = new Path(
                    new[] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                }
                    );

                //adding Invaders to the path
                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };

                // adding towers to gameplay
                Tower[] towers =
                {
                    new Tower(new MapLocation(1,       3, map)),
                    new SniperTower(new MapLocation(3, 3, map)),
                    new Tower(new MapLocation(5,       3, map))
                };

                Level level = new Level(invaders)
                {
                    towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player has " + (playerWon ? "won" : "lost"));
                Console.ReadKey();
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }

            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Ejemplo n.º 20
0
        static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                Path path = new Path(
                    new [] {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                });
                Console.WriteLine(value: "Welcome!");

                // MapLocation location = new MapLocation(0, 2, map);

                // if(path.IsOnPath(location))
                // {
                //     Console.WriteLine(location + " is on the path.");
                //     return;
                // }

                IInvader[] invaders =
                {
                    new SpeedBot(path),
                    new ShieldBot(path),
                    new ZomBot(path),
                    new PlainBot(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1,      3, map)),
                    new PowerTower(new MapLocation(3, 1, map)),
                    new Tower(new MapLocation(5,      3, map))
                };

                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
                // Setting using a setter method:
                // invader.SetLocation(location);

                // Setting using a Property setter:
                // invader.Location = location;
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }