Advertisement
sylviapsh

Ship Damage

Dec 27th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. using System;
  2. class ShipDamage
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Inside the sea (a standard Cartesian /rectangular/ coordinate system) we are given a ship S (a rectangle whose sides are parallel to the coordinate axes), a horizontal line H (the horizon) and three catapults, given as coordinates C1, C2 and C3 that will be used to fire the ship. When the attack starts, each catapult hits a projectile exactly into the positions that are symmetrical to C1, C2 and C3 with respect to the horizon H. When a projectile hits some of the corners of the ship, it causes a damage of 25%, when it hits some of the sides of the ship, the damage caused is 50% and when it hits the internal body of the ship, the damage is 100%. When the projectile hit outside of the ship, there is no damage. The total damage is sum of the separate damages and can exceed 100%.
  8.     //Your task is to write a program that calculates the total damage caused after the attack over the ship.
  9.  
  10.     int shipX1 = int.Parse(Console.ReadLine());
  11.     int shipY1 = int.Parse(Console.ReadLine());
  12.     int shipX2 = int.Parse(Console.ReadLine());
  13.     int shipY2 = int.Parse(Console.ReadLine());
  14.     int horizonY = int.Parse(Console.ReadLine());
  15.     int catapultX1 = int.Parse(Console.ReadLine());
  16.     int catapultY1 = int.Parse(Console.ReadLine());
  17.     int catapultX2 = int.Parse(Console.ReadLine());
  18.     int catapultY2 = int.Parse(Console.ReadLine());
  19.     int catapultX3 = int.Parse(Console.ReadLine());
  20.     int catapultY3 = int.Parse(Console.ReadLine());
  21.  
  22.     int totalDamage = 0;
  23.  
  24.     //mirror the catapults Y positon to know the proyectile Y coordinate.
  25.     int mirroredCatapultY1 = -(catapultY1 - horizonY);
  26.     int mirroredCatapultY2 = -(catapultY2 - horizonY);
  27.     int mirroredCatapultY3 = -(catapultY3 - horizonY);
  28.     int horizonedShipY1 = shipY1 - horizonY;
  29.     int horizonedShipY2 = shipY2 - horizonY;
  30.  
  31.     //Define the ship's rectangle area
  32.     int shipTop = Math.Max(horizonedShipY1, horizonedShipY2);
  33.     int shipBottom = Math.Min(horizonedShipY1, horizonedShipY2);
  34.     int shipLeft = Math.Min(shipX1, shipX2);
  35.     int shipRight = Math.Max(shipX1, shipX2);
  36.  
  37.     //Catapult 1
  38.     if (mirroredCatapultY1 > shipBottom && mirroredCatapultY1 < shipTop)
  39.     {
  40.       if (catapultX1 > shipLeft && catapultX1 < shipRight) //Inside the ship
  41.       {
  42.         totalDamage += 100;
  43.       }
  44.       else if (catapultX1 == shipLeft || catapultX1 == shipRight)
  45.       {
  46.         totalDamage += 50; //On the Y sides
  47.       }
  48.     }
  49.     if (mirroredCatapultY1 == shipBottom || mirroredCatapultY1 == shipTop)
  50.     {
  51.       if (catapultX1 == shipLeft || catapultX1 == shipRight)
  52.       {
  53.         totalDamage += 25; //In the corners
  54.       }
  55.       else if (catapultX1 > shipLeft && catapultX1 < shipRight)
  56.       {
  57.         totalDamage += 50; //On the X side
  58.       }
  59.     }
  60.  
  61.     //Catapult 2
  62.  
  63.     if (mirroredCatapultY2 > shipBottom && mirroredCatapultY2 < shipTop)
  64.     {
  65.       if (catapultX2 > shipLeft && catapultX2 < shipRight) //Inside the ship
  66.       {
  67.         totalDamage += 100;
  68.       }
  69.       else if (catapultX2 == shipLeft || catapultX2 == shipRight)
  70.       {
  71.         totalDamage += 50; //On the Y sides
  72.       }
  73.     }
  74.     if (mirroredCatapultY2 == shipBottom || mirroredCatapultY2 == shipTop)
  75.     {
  76.       if (catapultX2 == shipLeft || catapultX2 == shipRight)
  77.       {
  78.         totalDamage += 25; //In the corners
  79.       }
  80.       else if (catapultX2 > shipLeft && catapultX2 < shipRight)
  81.       {
  82.         totalDamage += 50; //On the X side
  83.       }
  84.     }
  85.  
  86.     //Catapult 3
  87.  
  88.     if (mirroredCatapultY3 > shipBottom && mirroredCatapultY3 < shipTop)
  89.     {
  90.       if (catapultX3 > shipLeft && catapultX3 < shipRight) //Inside the ship
  91.       {
  92.         totalDamage += 100;
  93.       }
  94.       else if (catapultX3 == shipLeft || catapultX3 == shipRight)
  95.       {
  96.         totalDamage += 50; //On the Y sides
  97.       }
  98.     }
  99.     if (mirroredCatapultY3 == shipBottom || mirroredCatapultY3 == shipTop)
  100.     {
  101.       if (catapultX3 == shipLeft || catapultX3 == shipRight)
  102.       {
  103.         totalDamage += 25; //In the corners
  104.       }
  105.       else if (catapultX3 > shipLeft && catapultX3 < shipRight)
  106.       {
  107.         totalDamage += 50; //On the X side
  108.       }
  109.     }
  110.     Console.WriteLine(totalDamage + "%");
  111.   }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement