Advertisement
Guest User

Figury 7

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.76 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. namespace Figury
  8. {
  9.     public class Punkt
  10.     {
  11.         private int x;
  12.         private int y;
  13.  
  14.         public Punkt() { }
  15.         public Punkt(int _x, int _y) { x = _x; y = _y; }      
  16.         public Punkt(Punkt punkt) { x = punkt.x; y = punkt.y; }
  17.         public void wypisz() { Console.WriteLine(x + " " + y); }
  18.         public int getX() { return x; }
  19.         public int getY() { return y; }
  20.         public void Przesun(int dx, int dy) { x += dx; y += dy; }
  21.  
  22.         public override String ToString() { return "(" + x + "," + y + ")"; }
  23.     }
  24.  
  25.  
  26.  
  27.     public class Linia
  28.     {
  29.         private Punkt pierwszy;
  30.         private Punkt drugi;
  31.  
  32.         public Linia() { }
  33.         public Linia(Linia l) { pierwszy = l.pierwszy; drugi = l.drugi; }
  34.         public Linia(Punkt _pierwszy, Punkt _drugi)
  35.         {
  36.             pierwszy = new Punkt(_pierwszy);
  37.             drugi = new Punkt(_drugi);
  38.         }
  39.         public void Przesun(int dx, int dy) { pierwszy.Przesun(dx, dy); drugi.Przesun(dx, dy); }
  40.         public override String ToString() { return "(" + pierwszy.ToString() + "," + drugi.ToString() + ")"; }
  41.  
  42.     }
  43.  
  44.  
  45.  
  46.     public class Figura
  47.     {
  48.         protected string kolor;
  49.  
  50.         public Figura() { kolor = "bialy"; }
  51.  
  52.         public void Ustawkolor(string cwet)
  53.         {
  54.             kolor = cwet;
  55.         }
  56.         public void Pokazkolor()
  57.         {
  58.             Console.WriteLine(kolor);
  59.         }
  60.     }
  61.  
  62.  
  63.  
  64.     public class Trojkat : Figura
  65.     {
  66.         private Linia pierwsza;
  67.         private Linia druga;
  68.         private Linia trzecia;
  69.         public Trojkat() { kolor = "bialy"; }
  70.         public Trojkat (Linia p, Linia d, Linia t, string cwet)
  71.         {
  72.             pierwsza = new Linia(p);    druga = new Linia(d);   trzecia = new Linia(t);
  73.         }
  74.         public void Przesun(int dx, int dy)
  75.         {
  76.             pierwsza.Przesun(dx, dy); druga.Przesun(dx, dy); trzecia.Przesun(dx, dy);
  77.         }
  78.         public override String ToString()
  79.         {
  80.             return pierwsza.ToString() + " , " + druga.ToString() + " , " + trzecia.ToString();
  81.         }
  82.     }
  83.  
  84.  
  85.  
  86.     public class Czworokat : Figura
  87.     {
  88.         private Linia pierwsza;
  89.         private Linia druga;
  90.         private Linia trzecia;
  91.         private Linia czwarta;
  92.         public Czworokat() { kolor = "bialy"; }
  93.  
  94.         public Czworokat(Linia p, Linia d, Linia t, Linia cz, string cwet)
  95.         {
  96.             pierwsza = new Linia(p); druga = new Linia(d); trzecia = new Linia(t); czwarta = new Linia(cz); kolor = cwet;
  97.         }
  98.         public void Przesun(int dx, int dy)
  99.         {
  100.             pierwsza.Przesun(dx, dy); druga.Przesun(dx, dy); trzecia.Przesun(dx, dy); czwarta.Przesun(dx, dy);
  101.         }
  102.         public override String ToString()
  103.         {
  104.             return pierwsza.ToString() + "," + druga.ToString() + "," + trzecia.ToString() + "," + czwarta.ToString();
  105.         }
  106.     }
  107.  
  108.  
  109.  
  110.  
  111.     public class Prostokat : Czworokat
  112.     {
  113.         public Prostokat() { kolor = "bialy"; }
  114.         public Prostokat(Linia p, Linia d, Linia t, Linia cz, string cwet) :base( p,  d,  t,  cz, cwet)
  115.         {        
  116.         }
  117.         public Prostokat(Punkt p1, Punkt p3, string cwet)
  118.         {
  119.             Punkt p2 = new Punkt(p1.getX(), p3.getY());
  120.             Punkt p4 = new Punkt(p3.getX(), p1.getY());
  121.  
  122.             Linia l1 = new Linia(p1, p2);
  123.             Linia l2 = new Linia(p2, p3);
  124.             Linia l3 = new Linia(p3, p4);
  125.             Linia l4 = new Linia(p4, p1);
  126.            
  127.         }
  128.  
  129.     }
  130.  
  131.     public class Kwadrat : Prostokat
  132.     {
  133.         public Kwadrat() { kolor = "bialy"; }
  134.         public Kwadrat(Linia p, Linia d, Linia t, Linia cz, string cwet) : base(p,d,t,cz,cwet)
  135.         {
  136.         }
  137.     }
  138.  
  139.  
  140.  
  141.     public class Obraz
  142.     {
  143.         List<Trojkat> Trojkaty = new List<Trojkat>();
  144.         List<Czworokat> Czworokaty = new List<Czworokat>();
  145.         List<Prostokat> Prostokaty = new List<Prostokat>();
  146.         List<Kwadrat> Kwadraty = new List<Kwadrat>();
  147.  
  148.         public void DodajTrojkat(Trojkat t) { Trojkaty.Add(t); }
  149.         public void DodajCzworokat(Czworokat c) { Czworokaty.Add(c); }
  150.         public void DodajProstokat(Prostokat p) { Prostokaty.Add(p); }
  151.         public void DodajKwadrat(Kwadrat k) { Kwadraty.Add(k); }
  152.         public void WyswietlTrojkat()
  153.         {
  154.             foreach (Trojkat x in Trojkaty)
  155.             {
  156.                 Console.WriteLine(x);
  157.             }
  158.         }
  159.         public void WyswietlCzworokat()
  160.         {
  161.             foreach (Czworokat x in Czworokaty)
  162.             {
  163.                 Console.WriteLine(x); x.Pokazkolor();
  164.             }
  165.         }
  166.         public void WyswietlProstokat()
  167.         {
  168.             foreach (Prostokat x in Prostokaty)
  169.             {
  170.                 Console.WriteLine(x); x.Pokazkolor();
  171.             }
  172.         }
  173.         public void WyswietlKwadrat()
  174.         {
  175.             foreach (Kwadrat x in Kwadraty)
  176.             {
  177.                 Console.WriteLine(x); x.Pokazkolor();
  178.             }
  179.         }
  180.         public void PrzesunTrojkat(int prz1, int prz2)
  181.         {
  182.             foreach (Trojkat x in Trojkaty)
  183.             {
  184.                 x.Przesun(prz1, prz2);
  185.             }
  186.         }
  187.         public void PrzesunCzworokat(int prz1, int prz2)
  188.         {
  189.             foreach (Czworokat x in Czworokaty)
  190.             {
  191.                 x.Przesun(prz1, prz2);
  192.             }
  193.         }
  194.         public void PrzesunProstokat(int przes1, int przes2)
  195.         {
  196.             foreach (Prostokat x in Prostokaty)
  197.             {
  198.                 x.Przesun(przes1, przes2);
  199.             }
  200.         }
  201.         public void PrzesunKwadrat(int przes1, int przes2)
  202.         {
  203.             foreach (Kwadrat x in Kwadraty)
  204.             {
  205.                 x.Przesun(przes1, przes2);
  206.             }
  207.         }
  208.     }
  209.  
  210.  
  211.         //***********************************************************************************************************
  212.         class Program
  213.     {
  214.         static void Main(string[] args)
  215.         {
  216.             int przes1, przes2, wybor = -1;
  217.             double x1, y1, x2, y2, x3, y3, x4, y4, dlugosc;
  218.             string color = "biały";
  219.             Obraz Ala = new Obraz();
  220.             while (wybor != 0)
  221.             {
  222.                 Console.Clear();
  223.                 Console.WriteLine("----------------");
  224.                 Console.WriteLine("1. Dodaj trójkąt");
  225.                 Console.WriteLine("2. Dodaj czworokąt");
  226.                 Console.WriteLine("3. Wyświetl wszystkie trójkąty");
  227.                 Console.WriteLine("4. Przesuń wszystkie trójkąty");
  228.                 Console.WriteLine("5. Wyświetl wszystkie czworokąty");
  229.                 Console.WriteLine("6. Przesun wszystkie czworokąty");
  230.                 Console.WriteLine("7. Dodaj prostokat");
  231.                 Console.WriteLine("8. Wyświetl wszystkie prostokąty");
  232.                 Console.WriteLine("9. Przesun wszystkie prostokąty");
  233.                 Console.WriteLine("10. Dodaj kwadrat");
  234.                 Console.WriteLine("11. Wyświetl wszystkie kwadraty");
  235.                 Console.WriteLine("12. Przesun wszystkie kwadraty");
  236.                 Console.WriteLine("0. Wyjście");
  237.                
  238.                 Console.WriteLine("Twój wybór: ");
  239.                 wybor = Convert.ToInt16(Console.ReadLine());
  240.                 switch (wybor)
  241.                 {
  242.                     //Trojkat
  243.                     case 1:
  244.                         {
  245.                             Console.WriteLine("Współrzędna x 1 punktu: ");
  246.                             x2 = Convert.ToInt16(Console.ReadLine());
  247.                             Console.WriteLine("Współrzędna y 1 punktu: ");
  248.                             y2 = Convert.ToInt16(Console.ReadLine());
  249.                             Punkt pt1 = new Punkt((int)x2, (int)y2);
  250.  
  251.                             Console.WriteLine("Współrzędna x 2 punktu: ");
  252.                             x1 = Convert.ToInt16(Console.ReadLine());
  253.                             Console.WriteLine("Współrzędna y 2 punktu: ");
  254.                             y1 = Convert.ToInt16(Console.ReadLine());
  255.                             Punkt pt2 = new Punkt((int)x1, (int)y1);
  256.  
  257.                             Console.WriteLine("Współrzędna x 3 punktu: ");
  258.                             x2 = Convert.ToInt16(Console.ReadLine());
  259.                             Console.WriteLine("Współrzędna y 3 punktu: ");
  260.                             y2 = Convert.ToInt16(Console.ReadLine());
  261.                            
  262.                             Punkt pt3 = new Punkt((int)x2, (int)y2);
  263.                            
  264.                                 Linia lt1 = new Linia(pt1, pt2);
  265.                                 Linia lt2 = new Linia(pt1, pt3);
  266.                                 Linia lt3 = new Linia(pt2, pt3);
  267.  
  268.                             Console.WriteLine("Podaj kolor: ");
  269.                             color = Console.ReadLine();
  270.                             Ala.DodajTrojkat(new Trojkat(lt1, lt2, lt3, color));
  271.                                 Console.WriteLine("Dodano trójkąt");
  272.                             Console.ReadKey();
  273.                             break;
  274.                         }
  275.                     case 2: //Czworokat
  276.                         {
  277.                             Console.WriteLine("Współrzędna x 1 punktu: ");
  278.                             x1 = Convert.ToInt16(Console.ReadLine());
  279.                             Console.WriteLine("Współrzędna y 1 punktu: ");
  280.                             y1 = Convert.ToInt16(Console.ReadLine());
  281.                             Punkt pc1 = new Punkt((int)x1, (int)y1);
  282.  
  283.                             Console.WriteLine("Współrzędna x 2 punktu: ");
  284.                             x2 = Convert.ToInt16(Console.ReadLine());
  285.                             Console.WriteLine("Współrzędna y 2 punktu: ");
  286.                             y2 = Convert.ToInt16(Console.ReadLine());
  287.                             Punkt pc2 = new Punkt((int)x2, (int)y2);
  288.  
  289.                             Console.WriteLine("Współrzędna x 3 punktu: ");
  290.                             x3 = Convert.ToInt16(Console.ReadLine());
  291.                             Console.WriteLine("Współrzędna y 3 punktu: ");
  292.                             y3 = Convert.ToInt16(Console.ReadLine());
  293.                             Punkt pc3 = new Punkt((int)x3, (int)y3);
  294.  
  295.                             Console.WriteLine("Współrzędna x 4 punktu: ");
  296.                             x4 = Convert.ToInt16(Console.ReadLine());
  297.                             Console.WriteLine("Współrzędna y 4 punktu: ");
  298.                             y4 = Convert.ToInt16(Console.ReadLine());
  299.                             Punkt pc4 = new Punkt((int)x4, (int)y4);
  300.  
  301.                             Linia lc1 = new Linia(pc1, pc2);
  302.                             Linia lc2 = new Linia(pc2, pc3);
  303.                             Linia lc3 = new Linia(pc3, pc4);
  304.                             Linia lc4 = new Linia(pc4, pc1);
  305.                             Console.WriteLine("Podaj kolor: ");
  306.                             color = Console.ReadLine();
  307.                             Ala.DodajCzworokat(new Czworokat(lc1, lc2, lc3, lc4, color));
  308.                             Console.WriteLine("Dodano Czworokąt");
  309.                             Console.ReadKey();
  310.                             break;
  311.                         }
  312.                     case 3:
  313.                         {
  314.                             Ala.WyswietlTrojkat();
  315.                             Console.ReadKey();
  316.                             break;
  317.                         }
  318.                     case 4:
  319.                         {
  320.                             Console.WriteLine("Przesuniecie trójkątów względem x: ");
  321.                             przes1 = Convert.ToInt16(Console.ReadLine());
  322.                             Console.WriteLine("Przesuniecie trójkątów względem y: ");
  323.                             przes2 = Convert.ToInt16(Console.ReadLine());
  324.                             Ala.PrzesunTrojkat(przes1, przes2);
  325.                             break;
  326.                         }
  327.                     case 5:
  328.                         {
  329.                             Ala.WyswietlCzworokat();
  330.                             Console.ReadKey();
  331.                             break;
  332.                         }
  333.                     case 6:
  334.                         {
  335.                             Console.WriteLine("Przesuniecie czworokątów względem x: ");
  336.                             przes1 = Convert.ToInt16(Console.ReadLine());
  337.                             Console.WriteLine("Przesuniecie czworokątów względem y: ");
  338.                             przes2 = Convert.ToInt16(Console.ReadLine());
  339.                             Ala.PrzesunCzworokat(przes1, przes2);
  340.                             break;
  341.                         }
  342.                     case 7:
  343.                         {
  344.                             Console.WriteLine("Współrzędna x 1 punktu: ");
  345.                             x1 = Convert.ToInt16(Console.ReadLine());
  346.                             Console.WriteLine("Współrzędna y 1 punktu: ");
  347.                             y1 = Convert.ToInt16(Console.ReadLine());
  348.                             Punkt pc1 = new Punkt((int)x1, (int)y1);
  349.  
  350.                             Console.WriteLine("Współrzędna x 2 punktu: ");
  351.                             x2 = Convert.ToInt16(Console.ReadLine());
  352.                             Console.WriteLine("Współrzędna y 2 punktu: ");
  353.                             y2 = Convert.ToInt16(Console.ReadLine());
  354.                             Punkt pc3 = new Punkt((int)x2, (int)y2);
  355.                             //Punkt pc2 = new Punkt((int)x1, (int)y2);
  356.                             //Punkt pc4 = new Punkt((int)x2, (int)y1);
  357.  
  358.                             //Linia lc1 = new Linia(pc1, pc2);
  359.                             //Linia lc2 = new Linia(pc2, pc3);
  360.                             //Linia lc3 = new Linia(pc3, pc4);
  361.                             //Linia lc4 = new Linia(pc4, pc1);
  362.  
  363.                             Console.WriteLine("Podaj kolor: ");
  364.                             color = Console.ReadLine();
  365.  
  366.                             //Ala.DodajProstokat(new Prostokat(lc1, lc2, lc3, lc4, color));
  367.                             Ala.DodajProstokat(new Prostokat(pc1, pc3, color));
  368.                             Console.WriteLine("Dodano 'Prostokat'");
  369.                             Console.ReadKey();
  370.                             break;
  371.                         }
  372.                     case 8:
  373.                         {
  374.                             Ala.WyswietlProstokat();
  375.                             Console.ReadKey();
  376.                             break;
  377.                         }
  378.                     case 9:
  379.                         {
  380.                             Console.WriteLine("Przesuniecie Prostokat względem x: ");
  381.                             przes1 = Convert.ToInt16(Console.ReadLine());
  382.                             Console.WriteLine("Przesuniecie Ptostokat względem y: ");
  383.                             przes2 = Convert.ToInt16(Console.ReadLine());
  384.                             Ala.PrzesunProstokat(przes1, przes2);
  385.                             break;
  386.                         }
  387.                     case 10:
  388.                         {
  389.                             Console.WriteLine("Współrzędna x 1 punktu: ");
  390.                             x1 = Convert.ToInt16(Console.ReadLine());
  391.                             Console.WriteLine("Długość boku: ");
  392.                             Console.WriteLine("Współrzędna y 1 punktu: ");
  393.                             y1 = Convert.ToInt16(Console.ReadLine());
  394.                             Punkt pc1 = new Punkt((int)x1, (int)y1);
  395.  
  396.                             Console.WriteLine("Długość boku: ");
  397.                             dlugosc = Convert.ToInt16(Console.ReadLine());
  398.                             x2 = x1; y2 = x1 + dlugosc;
  399.                             Punkt pc2 = new Punkt((int)x2, (int)y2);
  400.                             x3 = x2 + dlugosc; y3 = y2;
  401.                             Punkt pc3 = new Punkt((int)x3, (int)y3);
  402.                             x4 = x3; y4 = y3 - dlugosc;
  403.                             Punkt pc4 = new Punkt((int)x4, (int)y4);
  404.  
  405.                             Linia lc1 = new Linia(pc1, pc2);
  406.                             Linia lc2 = new Linia(pc2, pc3);
  407.                             Linia lc3 = new Linia(pc3, pc4);
  408.                             Linia lc4 = new Linia(pc4, pc1);
  409.  
  410.                             Console.WriteLine("Podaj kolor: ");
  411.                             color = Console.ReadLine();
  412.  
  413.                             Ala.DodajKwadrat(new Kwadrat(lc1, lc2, lc3, lc4, color));
  414.                             Console.WriteLine("Dodano 'Kwadrat'");
  415.                             Console.ReadKey();
  416.                             break;
  417.                         }
  418.                     case 11:
  419.                         {
  420.                             Ala.WyswietlKwadrat();
  421.                             Console.ReadKey();
  422.                             break;
  423.                         }
  424.                     case 12:
  425.                         {
  426.                             Console.WriteLine("Przesuniecie Kwadrat względem x: ");
  427.                             przes1 = Convert.ToInt16(Console.ReadLine());
  428.                             Console.WriteLine("Przesuniecie Kwadrat względem y: ");
  429.                             przes2 = Convert.ToInt16(Console.ReadLine());
  430.                             Ala.PrzesunKwadrat(przes1, przes2);
  431.                             break;
  432.                         }
  433.                 }
  434.  
  435.             }
  436.                 Console.WriteLine("_______________________________________koniec_____________________________________________");
  437.             Console.ReadKey();
  438.         }
  439.     }
  440. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement