psotirov

Fighter Attack

Dec 10th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2.  
  3. class Plant
  4. {
  5.     int xLeft;
  6.     int yTop;
  7.     int xRight;
  8.     int yBottom;
  9.  
  10.     public Plant(int x1, int y1, int x2, int y2)
  11.     {
  12.         xLeft = Math.Min(x1, x2);
  13.         xRight = Math.Max(x1, x2);
  14.         yTop = Math.Max(y1, y2);
  15.         yBottom = Math.Min(y1, y2);
  16.     }
  17.  
  18.     public bool Damage(int x, int y)
  19.     {
  20.         if (x < xLeft || x > xRight || y < yBottom || y > yTop) return false; // no damage
  21.         return true; // otherwise the hit is inside the body - true
  22.     }
  23. }
  24.  
  25. class FighterAttack
  26. {
  27.     static void Main()
  28.     {
  29.         Plant thePlant = new Plant( int.Parse(Console.ReadLine()), // reads the plant's coordinates: Px1,
  30.                                     int.Parse(Console.ReadLine()), // Py1,
  31.                                     int.Parse(Console.ReadLine()), // Px2,
  32.                                     int.Parse(Console.ReadLine())  // Py2 (and sort them!)
  33.                                );
  34.  
  35.         int Fx = int.Parse(Console.ReadLine()); // reads the x coordinate of a fighter
  36.         int Fy = int.Parse(Console.ReadLine()); // reads the y coordinate of a fighter
  37.         int Dist = int.Parse(Console.ReadLine()); // reads the missale distance
  38.         int damage = 0;
  39.  
  40.         damage += (thePlant.Damage(Fx + Dist, Fy)) ? 100 : 0; // if missle's main target is inside the plant - 100% damage
  41.         damage += (thePlant.Damage(Fx + Dist, Fy - 1)) ? 50 : 0; // if missle's target to the left of main is inside the plant - 50% damage
  42.         damage += (thePlant.Damage(Fx + Dist, Fy + 1)) ? 50 : 0; // if missle's target to the right of main is inside the plant  - 50% damage
  43.         damage += (thePlant.Damage(Fx + Dist + 1, Fy)) ? 75 : 0; // if missle's target one cell forward of main is inside the plant  - 75% damage
  44.  
  45.         Console.WriteLine("{0}%", damage);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment