Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.  
  11.     public class Punkt
  12.     {
  13.  
  14.         public int x = 0, y = 0;
  15.        
  16.         public Punkt() { }
  17.        
  18.         public Punkt(int xx, int yy)
  19.         {
  20.             x = xx; y = yy;
  21.         }
  22.        
  23.         public Punkt(Punkt p)
  24.         {
  25.             x = p.x; y = p.y;
  26.         }
  27.        
  28.         public void przesun(int dx, int dy)
  29.         {
  30.             x += dx; y += dy;
  31.         }
  32.        
  33.         public override String ToString() { return x + "," + y; }
  34.     }
  35.  
  36.     public class Linia
  37.     {
  38.  
  39.         public Punkt p1, p2;
  40.        
  41.         public Linia() { }
  42.        
  43.         public Linia(Punkt q1, Punkt q2)
  44.         {
  45.             p1 = new Punkt(q1); p2 = new Punkt(q2);
  46.         }
  47.        
  48.         public Linia(Linia l)
  49.         {
  50.             p1 = new Punkt(l.p1); p2 = new Punkt(l.p2);
  51.         }
  52.        
  53.         public void przesun(int dx, int dy)
  54.         {
  55.             p1.przesun(dx, dy); p2.przesun(dx, dy);
  56.         }
  57.        
  58.         public override String ToString()
  59.         {
  60.             return "Linia(p1:" + p1.ToString() + ", p2:" + p2.ToString() + ")";
  61.         }
  62.  
  63.     }
  64.  
  65.     public class Trojkat
  66.     {
  67.         public Linia a, b, c;
  68.        
  69.         public Trojkat() { }
  70.        
  71.         private bool tak(Punkt a, Punkt b)
  72.         {
  73.             if (a.x == b.x && a.y == b.y)
  74.                 return true;
  75.             return false;
  76.         }
  77.  
  78.         public Trojkat(Linia x, Linia y, Linia z) {
  79.             int i = 0;
  80.             if(tak(x.p1,y.p1))
  81.             {
  82.                 if(tak(x.p2,z.p1))
  83.                 {
  84.                     if(tak(z.p2,y.p2))
  85.                         i=1;
  86.                 }
  87.                 else if(tak(x.p2,z.p2))
  88.                 {
  89.                     if(tak(z.p1,y.p2)) i=1;
  90.                 }
  91.             }
  92.             else if(tak(x.p1,y.p2))
  93.             {
  94.                 if(tak(x.p2,z.p1))
  95.                 {
  96.                     if(tak(z.p2,y.p1))
  97.                         i=1;
  98.                 }
  99.                 else if(tak(x.p2,z.p2))
  100.                 {
  101.                     if(tak(z.p1,y.p1)) i=1;
  102.                 }
  103.             }
  104.             else if(tak(x.p2,y.p1))
  105.             {
  106.                 if(tak(x.p1,z.p1))
  107.                 {
  108.                     if(tak(z.p2,y.p2))
  109.                         i=1;
  110.                 }
  111.                 else if(tak(x.p1,z.p2))
  112.                 {
  113.                     if(tak(z.p1,y.p2))
  114.                         i=1;
  115.                 }
  116.             }
  117.             else if(tak(x.p2,y.p2))
  118.             {
  119.                 if(tak(x.p1,z.p1))
  120.                 {
  121.                     if(tak(z.p2,y.p1))
  122.                         i=1;
  123.                 }
  124.                 else if(tak(x.p1,z.p2))
  125.                 {
  126.                     if(tak(z.p1,y.p1))
  127.                         i=1;
  128.                 }
  129.             }
  130.  
  131.             if(i==1) Console.WriteLine("DZIALA");
  132.             else Console.WriteLine("CHYBA DZIALA");
  133.                                                 a=new Linia(x);
  134.                                                 b=new Linia(y);
  135.                                                 c=new Linia(z);}
  136.         public Trojkat(Trojkat t)
  137.         {
  138.             a = new Linia(t.a);
  139.             b = new Linia(t.b);
  140.             c = new Linia(t.c);
  141.         }
  142.         public void przesun(int dx, int dy)
  143.         {
  144.             a.przesun(dx, dy);
  145.             b.przesun(dx, dy);
  146.             c.przesun(dx, dy);
  147.         }
  148.        
  149.         public override String ToString()
  150.         {
  151.             return "Trojkat[Pierwsza " + a.ToString() +
  152.                     ", Druga " + b.ToString() +
  153.                     ", Trzecia " + c.ToString() + "]";
  154.         }
  155.     }
  156.  
  157.     public class Czworokat
  158.     {
  159.         public Linia a, b, c, d;
  160.         public Czworokat() { }
  161.         //private bool tak(Point a, Point b){if(a.x==b.x && a.y==b.y) return true; return false}
  162.         public Czworokat(Linia x, Linia y, Linia z, Linia q)
  163.         {
  164.             //if(tak(x.p1,y.p1)||tak(x.p1,y.p2)||tak(x.p2,y.p1))
  165.  
  166.  
  167.             a = new Linia(x);
  168.             b = new Linia(y);
  169.             c = new Linia(z);
  170.             d = new Linia(q);
  171.         }
  172.         public Czworokat(Czworokat t)
  173.         {
  174.             a = new Linia(t.a);
  175.             b = new Linia(t.b);
  176.             c = new Linia(t.c);
  177.             d = new Linia(t.d);
  178.         }
  179.         public void przesun(int dx, int dy)
  180.         {
  181.             a.przesun(dx, dy);
  182.             b.przesun(dx, dy);
  183.             c.przesun(dx, dy);
  184.             d.przesun(dx, dy);
  185.         }
  186.         public String toString()
  187.         {
  188.             return "Czworokat[Pierwsza " + a.ToString() +
  189.                     ", Druga " + b.ToString() +
  190.                     ", Trzecia " + c.ToString() +
  191.                     ", Czwarta " + d.ToString() + "]";
  192.         }
  193.     }
  194.  
  195.     public class Obraz
  196.     {
  197.         public Trojkat[] tab1 = new Trojkat[10];
  198.         public Czworokat[] tab2 = new Czworokat[10];
  199.         // ta sama nazwa, ze wzgledu na rodzja parametru rozróżniamy
  200.        
  201.         public void add(Trojkat x)
  202.         {
  203.             for(int t=0; t<tab1.Length; t++)
  204.                 if(tab1[t]==null)
  205.                 {
  206.                     tab1[t]=new Trojkat(x);break;
  207.                 }
  208.         }
  209.  
  210.         public void add(Czworokat x)
  211.         {
  212.             for(int t=0; t<tab2.Length; t++)
  213.                 if(tab2[t]==null)
  214.                 {
  215.                     tab2[t]=new Czworokat(x);break;
  216.                 }
  217.         }
  218.  
  219.         public void przesun(int dx, int dy)
  220.         {
  221.             for(int t=0; t<tab2.Length; t++)
  222.                 if(tab2[t]!=null)
  223.                     tab2[t].przesun(dx,dy);
  224.            
  225.             for(int t=0; t<tab1.Length; t++)
  226.                 if(tab1[t]!=null)
  227.                     tab1[t].przesun(dx,dy);
  228.         }
  229.    
  230.         public override string ToString()
  231.         {
  232.             String a = "Oto cały obraz:\n";
  233.             for(int t=0; t<tab2.Length; t++)
  234.             {
  235.                 if(tab2[t]!=null) a=a+tab2[t].ToString()+"\n";
  236.             }
  237.             for(int t=0; t<tab1.Length; t++)
  238.             {
  239.                 if(tab1[t]!=null) a=a+tab1[t].ToString()+"\n";
  240.             }
  241.         return a;
  242.         }
  243.     }
  244.  
  245.    
  246.    
  247.    
  248.    
  249.     class Program
  250.     {
  251.         static void Main(string[] args)
  252.         {
  253.      
  254.         Punkt p1=new Punkt(0,0), p2=new Punkt(1,1);
  255.         Linia l1=new Linia(p1, p2), l2=new Linia(p1, p2);
  256.         l1.przesun(5,5);
  257.         Console.WriteLine(l1);
  258.         Console.WriteLine(l2);
  259.         }
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement