Beispiel #1
0
 public void UnsheathSword(IAlien target)
 {
     this.WriteLinesAboutTheSword();
     Console.WriteLine(
         "The sword targets an alien with {0} eyes.",
         target.NumberOfEyes);
 }
Beispiel #2
0
 public void CheckHit(IAlien alien)
 {
     for (int i = 0; i < laserList.Count; i++)
     {
         laserList[i].CheckHit(alien);
     }
 }
Beispiel #3
0
 public void DisappearAlien(IAlien alien)
 {
     Console.WriteLine(
         "{0} uses his {1} spell power to make the alien with {2} eyes disappear.",
         this.FullName,
         this.SpellPower,
         alien.NumberOfEyes);
 }
        public Game()
        {
            InitializeComponent();

            paper  = gamePictureBox.CreateGraphics();
            user   = new User(userPictureBox);
            alien  = new Alien(alienPictureBox);
            lasers = new Lasers();
            bombs  = new Bombs();
        }
Beispiel #5
0
 public void CheckHit(IAlien alien)
 {
     if ((X > alien.X) &&
         (Y < (alien.Y + alien.Height)) &&
         (X + Width) < (alien.X + alien.Width) &&
         (Y + Height) > (alien.Y))
     {
         alien.Dead = true;
         lasers.Remove(this);
     }
 }
        static void Main(string[] args)
        {
            // Create watch variable to keep of milliseconds. How long the application took to run.
            var watch = System.Diagnostics.Stopwatch.StartNew();

            // Size of the alien army.
            long armySize = 100000000;

            // Tell the user that the army is being created.
            Console.WriteLine("Now creating Home World Army... ... ...\n");

            // Create our factory and random varible.
            AlienFactory HomeWorldFactory = new AlienFactory();
            Random       rnd = new Random();

            // Create a list of our army.
            IAlien[] AlienHomeWorldArmy = new IAlien[armySize];

            // for loop to create 10 aliens for our army.
            for (int i = 0; i < armySize; i++)
            {
                if (rnd.Next(1, 3) == 1)
                {
                    AlienHomeWorldArmy[i] = HomeWorldFactory.prepareAlien("BrawnyAlien");
                }
                else
                {
                    AlienHomeWorldArmy[i] = HomeWorldFactory.prepareAlien("BigBrainAlien");
                }
                //AlienHomeWorldArmy[i].Objective();
            }

            // Stop the watch to see the difference.
            watch.Stop();

            // Output how many milliseconds it took to run the code.
            Console.WriteLine("This is how long it took: " + watch.ElapsedMilliseconds);
        }
Beispiel #7
0
        //LD_FLYWEIGHT_000
        public static void RunFlyweightStructuralPattern()
        {
            AlienFactory factory = new AlienFactory();

            factory.SaveAlien(0, new LargeAlien());
            factory.SaveAlien(1, new LittleAlien());

            //now access the flyweight objects
            IAlien a = factory.GetAlien(0);
            IAlien b = factory.GetAlien(1);

            //show intrinsic states, all accessed in memory without calculations
            Console.WriteLine("Showing intrinsic states...");
            Console.WriteLine("Alien of type 0 is " + a.Shape);
            Console.WriteLine("Alien of type 1 is " + b.Shape);

            //show extrinsic states, need calculations
            Console.WriteLine("Showing extrinsic states...");
            Console.WriteLine("Alien of type 0 is " + a.GetColor(0).ToString());
            Console.WriteLine("Alien of type 0 is " + a.GetColor(1).ToString());
            Console.WriteLine("Alien of type 1 is " + b.GetColor(0).ToString());
            Console.WriteLine("Alien of type 1 is " + b.GetColor(1).ToString());
        }
Beispiel #8
0
 public static void SkipRef()
 {
     Ref = null;
 }
Beispiel #9
0
 public static void Prepare()
 {
     Point ind;
     int i = 0;
     ClearCells();
     while (i < Aliens.Count)
     {
         while ((i < Aliens.Count) && (!CheckDistance(Aliens[i].GetCoords())))
         {
             if (Ref != null)
             {
                 if (Ref.Equals(Aliens[i]))
                     Ref = null;
             }
             Aliens.RemoveAt(i);
         }
         if (i < Aliens.Count)
         {
             ind = Cell.GetCellIndex(Aliens[i].GetCoords());
             Field[ind.X][ind.Y].AddAlienLink(i);
         }
         i++;
     }
 }
Beispiel #10
0
 // -1 -нету, иначе есть
 public static int GetAlien(Point pos)
 {
     int x, y;
     for (int i = 0; i < Aliens.Count; i++)
     {
         x = Aliens[i].GetCoords().X;
         y = Aliens[i].GetCoords().Y;
         if (Aliens[i].GetRadius() >= (int)Math.Sqrt((pos.X - x) * (pos.X - x) + (pos.Y - y) * (pos.Y - y)))
         {
             Ref = Aliens[i];
             return i;
         }
     }
     return -1;
 }
Beispiel #11
0
 public static void CreateWorld(int worldrad)
 {
     Ref = null;
     Aliens = new List<IAlien>();
     Field = new Cell[Cell.MaxInd.X + 1][];
     for (int i = 0; i < Field.Length; i++)
     {
         Field[i] = new Cell[Cell.MaxInd.Y + 1];
         for (int j = 0; j < Field[i].Length; j++)
             Field[i][j] = new Cell(new Point(i, j));
     }
 }
        // Function to create an alien.
        public IAlien prepareAlien(string alienSpecies)
        {
            // Create out alien.
            IAlien newAlien = null;

            /***********************************
             * Code Segment show the shorter time
             ***********************************
             *
             * // If the alien model already exists, use it. Otherwise make a new one.
             * if (AlienArmy.ContainsKey(alienSpecies))
             * {
             *  newAlien = AlienArmy.GetValueOrDefault(alienSpecies);
             * }
             * else
             * {
             *  switch (alienSpecies)
             *  {
             *      // Create a Brawny Alien.
             *      case "BrawnyAlien":
             *          Console.WriteLine("Brawny Alien model has been created.");
             *          newAlien = new BrawnyAlien();
             *          newAlien.SetPowerup("Super Strength");
             *          break;
             *
             *      // Create a Big Brain Alien.
             *      case "BigBrainAlien":
             *          Console.WriteLine("Big Brain Alien model has been created.");
             *          newAlien = new BigBrainAlien();
             *          newAlien.SetPowerup("Telekenesis");
             *          break;
             *
             *      // Obligatory default statement.
             *      default:
             *          Console.WriteLine("Factory has made an illegal Alien spawn request.");
             *          break;
             *  }
             *
             *  // Add our alien model to our dictionary.
             *  AlienArmy.Add(alienSpecies, newAlien);
             *
             * }
             *
             * /**********************************
             * Code Segment show the longer time
             **********************************/

            switch (alienSpecies)
            {
            // Create a Brawny Alien.
            case "BrawnyAlien":
                newAlien = new BrawnyAlien();
                newAlien.SetPowerup("Super Strength");
                break;

            // Create a Big Brain Alien.
            case "BigBrainAlien":
                newAlien = new BigBrainAlien();
                newAlien.SetPowerup("Telekenesis");
                break;

            // Obligatory default statement.
            default:
                Console.WriteLine("Factory has made an illegal Alien spawn request.");
                break;
            }

            /**********************************/

            // Return the alien to the called function.
            return(newAlien);
        }
Beispiel #13
0
 public void SaveAlien(int index, IAlien alien)
 {
     list.Add(index, alien);
 }