Advertisement
d_brezoev

ShipDamageOOP

May 26th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 KB | None | 0 0
  1. namespace ShipDamage
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     class Ship
  8.     {
  9.         public static int Sx1;
  10.         public static int Sx2;
  11.         public static int Sy1;
  12.         public static int Sy2;
  13.         public static int damage;
  14.     }
  15.     class Horizon
  16.     {
  17.         public static int h;
  18.     }
  19.     class Bomb
  20.     {
  21.         public int x;
  22.         public int y;
  23.     }
  24.     class ShipDamage
  25.     {
  26.         static void Main()
  27.         {          
  28.             Ship.Sx1 = int.Parse(Console.ReadLine());
  29.             Ship.Sy1 = int.Parse(Console.ReadLine());
  30.             Ship.Sx2 = int.Parse(Console.ReadLine());
  31.             Ship.Sy2 = int.Parse(Console.ReadLine());
  32.             Horizon.h = int.Parse(Console.ReadLine());
  33.             Bomb bomb1 = new Bomb();
  34.             bomb1.x = int.Parse(Console.ReadLine());
  35.             bomb1.y = int.Parse(Console.ReadLine());
  36.             Bomb bomb2 = new Bomb();
  37.             bomb2.x = int.Parse(Console.ReadLine());
  38.             bomb2.y = int.Parse(Console.ReadLine());
  39.             Bomb bomb3 = new Bomb();
  40.             bomb3.x = int.Parse(Console.ReadLine());
  41.             bomb3.y = int.Parse(Console.ReadLine());
  42.  
  43.             if (Horizon.h>0)
  44.             {
  45.                 Ship.Sy1 -= Math.Abs(Horizon.h);
  46.                 Ship.Sy2 -= Math.Abs(Horizon.h);
  47.                 bomb1.y -= Math.Abs(Horizon.h);
  48.                 bomb2.y -= Math.Abs(Horizon.h);
  49.                 bomb3.y -= Math.Abs(Horizon.h);
  50.                 Horizon.h = Horizon.h - Horizon.h;
  51.             }
  52.             else if (Horizon.h<0)
  53.             {
  54.                 Ship.Sy1 += Math.Abs(Horizon.h);
  55.                 Ship.Sy2 += Math.Abs(Horizon.h);
  56.                 bomb1.y += Math.Abs(Horizon.h);
  57.                 bomb2.y +=Math.Abs(Horizon.h);
  58.                 bomb3.y += Math.Abs(Horizon.h);
  59.                 Horizon.h = Horizon.h + Horizon.h;
  60.             }          
  61.  
  62.             int rightSide = Math.Max(Ship.Sx1, Ship.Sx2);
  63.             int leftSide = Math.Min(Ship.Sx1, Ship.Sx2);
  64.             int upSide = Math.Max(Ship.Sy1, Ship.Sy2);
  65.             int bottomSide = Math.Min(Ship.Sy1, Ship.Sy2);
  66.  
  67.             Bomb[] bombs = new Bomb[3];
  68.             bombs[0] = bomb1;
  69.             bombs[1] = bomb2;
  70.             bombs[2] = bomb3;
  71.             //check where is hit
  72.             foreach (Bomb bomb in bombs)
  73.             {
  74.                 bomb.y = -bomb.y;//reflecting the bomb
  75.                 if (bomb.x<rightSide && bomb.x>leftSide)
  76.                 {            
  77.                     if (bomb.y<upSide && bomb.y>bottomSide)
  78.                     {
  79.                         Ship.damage += 100;
  80.                     }
  81.                     else if (bomb.y == upSide || bomb.y == bottomSide)
  82.                     {
  83.                         Ship.damage += 50;
  84.                     }
  85.                 }
  86.                 else if (bomb.x==rightSide || bomb.x == leftSide)
  87.                 {
  88.                     if (bomb.y<upSide && bomb.y>bottomSide)
  89.                     {
  90.                         Ship.damage += 50;
  91.                     }
  92.                     else if (bomb.y==upSide || bomb.y==bottomSide)
  93.                     {
  94.                         Ship.damage += 25;
  95.                     }                    
  96.                 }
  97.             }
  98.             Console.WriteLine(Ship.damage +"%");
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement