Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Figury
- {
- public class Punkt
- {
- private int x;
- private int y;
- public Punkt() { }
- public Punkt(int _x, int _y) { x = _x; y = _y; }
- public Punkt(Punkt punkt) { x = punkt.x; y = punkt.y; }
- public void wypisz() { Console.WriteLine(x + " " + y); }
- public int getX() { return x; }
- public int getY() { return y; }
- public void Przesun(int dx, int dy) { x += dx; y += dy; }
- public override String ToString() { return "(" + x + "," + y + ")"; }
- }
- public class Linia
- {
- private Punkt pierwszy;
- private Punkt drugi;
- public Linia() { }
- public Linia(Linia l) { pierwszy = l.pierwszy; drugi = l.drugi; }
- public Linia(Punkt _pierwszy, Punkt _drugi)
- {
- pierwszy = new Punkt(_pierwszy);
- drugi = new Punkt(_drugi);
- }
- public void Przesun(int dx, int dy) { pierwszy.Przesun(dx, dy); drugi.Przesun(dx, dy); }
- public override String ToString() { return "(" + pierwszy.ToString() + "," + drugi.ToString() + ")"; }
- }
- public class Figura
- {
- protected string kolor;
- public Figura() { kolor = "bialy"; }
- public void Ustawkolor(string cwet)
- {
- kolor = cwet;
- }
- public void Pokazkolor()
- {
- Console.WriteLine(kolor);
- }
- }
- public class Trojkat : Figura
- {
- private Linia pierwsza;
- private Linia druga;
- private Linia trzecia;
- public Trojkat() { kolor = "bialy"; }
- public Trojkat (Linia p, Linia d, Linia t, string cwet)
- {
- pierwsza = new Linia(p); druga = new Linia(d); trzecia = new Linia(t);
- }
- public void Przesun(int dx, int dy)
- {
- pierwsza.Przesun(dx, dy); druga.Przesun(dx, dy); trzecia.Przesun(dx, dy);
- }
- public override String ToString()
- {
- return pierwsza.ToString() + " , " + druga.ToString() + " , " + trzecia.ToString();
- }
- }
- public class Czworokat : Figura
- {
- private Linia pierwsza;
- private Linia druga;
- private Linia trzecia;
- private Linia czwarta;
- public Czworokat() { kolor = "bialy"; }
- public Czworokat(Linia p, Linia d, Linia t, Linia cz, string cwet)
- {
- pierwsza = new Linia(p); druga = new Linia(d); trzecia = new Linia(t); czwarta = new Linia(cz); kolor = cwet;
- }
- public void Przesun(int dx, int dy)
- {
- pierwsza.Przesun(dx, dy); druga.Przesun(dx, dy); trzecia.Przesun(dx, dy); czwarta.Przesun(dx, dy);
- }
- public override String ToString()
- {
- return pierwsza.ToString() + "," + druga.ToString() + "," + trzecia.ToString() + "," + czwarta.ToString();
- }
- }
- public class Prostokat : Czworokat
- {
- public Prostokat() { kolor = "bialy"; }
- public Prostokat(Linia p, Linia d, Linia t, Linia cz, string cwet) :base( p, d, t, cz, cwet)
- {
- }
- public Prostokat(Punkt p1, Punkt p3, string cwet)
- {
- Punkt p2 = new Punkt(p1.getX(), p3.getY());
- Punkt p4 = new Punkt(p3.getX(), p1.getY());
- Linia l1 = new Linia(p1, p2);
- Linia l2 = new Linia(p2, p3);
- Linia l3 = new Linia(p3, p4);
- Linia l4 = new Linia(p4, p1);
- }
- }
- public class Kwadrat : Prostokat
- {
- public Kwadrat() { kolor = "bialy"; }
- public Kwadrat(Linia p, Linia d, Linia t, Linia cz, string cwet) : base(p,d,t,cz,cwet)
- {
- }
- }
- public class Obraz
- {
- List<Trojkat> Trojkaty = new List<Trojkat>();
- List<Czworokat> Czworokaty = new List<Czworokat>();
- List<Prostokat> Prostokaty = new List<Prostokat>();
- List<Kwadrat> Kwadraty = new List<Kwadrat>();
- public void DodajTrojkat(Trojkat t) { Trojkaty.Add(t); }
- public void DodajCzworokat(Czworokat c) { Czworokaty.Add(c); }
- public void DodajProstokat(Prostokat p) { Prostokaty.Add(p); }
- public void DodajKwadrat(Kwadrat k) { Kwadraty.Add(k); }
- public void WyswietlTrojkat()
- {
- foreach (Trojkat x in Trojkaty)
- {
- Console.WriteLine(x);
- }
- }
- public void WyswietlCzworokat()
- {
- foreach (Czworokat x in Czworokaty)
- {
- Console.WriteLine(x); x.Pokazkolor();
- }
- }
- public void WyswietlProstokat()
- {
- foreach (Prostokat x in Prostokaty)
- {
- Console.WriteLine(x); x.Pokazkolor();
- }
- }
- public void WyswietlKwadrat()
- {
- foreach (Kwadrat x in Kwadraty)
- {
- Console.WriteLine(x); x.Pokazkolor();
- }
- }
- public void PrzesunTrojkat(int prz1, int prz2)
- {
- foreach (Trojkat x in Trojkaty)
- {
- x.Przesun(prz1, prz2);
- }
- }
- public void PrzesunCzworokat(int prz1, int prz2)
- {
- foreach (Czworokat x in Czworokaty)
- {
- x.Przesun(prz1, prz2);
- }
- }
- public void PrzesunProstokat(int przes1, int przes2)
- {
- foreach (Prostokat x in Prostokaty)
- {
- x.Przesun(przes1, przes2);
- }
- }
- public void PrzesunKwadrat(int przes1, int przes2)
- {
- foreach (Kwadrat x in Kwadraty)
- {
- x.Przesun(przes1, przes2);
- }
- }
- }
- //***********************************************************************************************************
- class Program
- {
- static void Main(string[] args)
- {
- int przes1, przes2, wybor = -1;
- double x1, y1, x2, y2, x3, y3, x4, y4, dlugosc;
- string color = "biały";
- Obraz Ala = new Obraz();
- while (wybor != 0)
- {
- Console.Clear();
- Console.WriteLine("----------------");
- Console.WriteLine("1. Dodaj trójkąt");
- Console.WriteLine("2. Dodaj czworokąt");
- Console.WriteLine("3. Wyświetl wszystkie trójkąty");
- Console.WriteLine("4. Przesuń wszystkie trójkąty");
- Console.WriteLine("5. Wyświetl wszystkie czworokąty");
- Console.WriteLine("6. Przesun wszystkie czworokąty");
- Console.WriteLine("7. Dodaj prostokat");
- Console.WriteLine("8. Wyświetl wszystkie prostokąty");
- Console.WriteLine("9. Przesun wszystkie prostokąty");
- Console.WriteLine("10. Dodaj kwadrat");
- Console.WriteLine("11. Wyświetl wszystkie kwadraty");
- Console.WriteLine("12. Przesun wszystkie kwadraty");
- Console.WriteLine("0. Wyjście");
- Console.WriteLine("Twój wybór: ");
- wybor = Convert.ToInt16(Console.ReadLine());
- switch (wybor)
- {
- //Trojkat
- case 1:
- {
- Console.WriteLine("Współrzędna x 1 punktu: ");
- x2 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 1 punktu: ");
- y2 = Convert.ToInt16(Console.ReadLine());
- Punkt pt1 = new Punkt((int)x2, (int)y2);
- Console.WriteLine("Współrzędna x 2 punktu: ");
- x1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 2 punktu: ");
- y1 = Convert.ToInt16(Console.ReadLine());
- Punkt pt2 = new Punkt((int)x1, (int)y1);
- Console.WriteLine("Współrzędna x 3 punktu: ");
- x2 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 3 punktu: ");
- y2 = Convert.ToInt16(Console.ReadLine());
- Punkt pt3 = new Punkt((int)x2, (int)y2);
- Linia lt1 = new Linia(pt1, pt2);
- Linia lt2 = new Linia(pt1, pt3);
- Linia lt3 = new Linia(pt2, pt3);
- Console.WriteLine("Podaj kolor: ");
- color = Console.ReadLine();
- Ala.DodajTrojkat(new Trojkat(lt1, lt2, lt3, color));
- Console.WriteLine("Dodano trójkąt");
- Console.ReadKey();
- break;
- }
- case 2: //Czworokat
- {
- Console.WriteLine("Współrzędna x 1 punktu: ");
- x1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 1 punktu: ");
- y1 = Convert.ToInt16(Console.ReadLine());
- Punkt pc1 = new Punkt((int)x1, (int)y1);
- Console.WriteLine("Współrzędna x 2 punktu: ");
- x2 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 2 punktu: ");
- y2 = Convert.ToInt16(Console.ReadLine());
- Punkt pc2 = new Punkt((int)x2, (int)y2);
- Console.WriteLine("Współrzędna x 3 punktu: ");
- x3 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 3 punktu: ");
- y3 = Convert.ToInt16(Console.ReadLine());
- Punkt pc3 = new Punkt((int)x3, (int)y3);
- Console.WriteLine("Współrzędna x 4 punktu: ");
- x4 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 4 punktu: ");
- y4 = Convert.ToInt16(Console.ReadLine());
- Punkt pc4 = new Punkt((int)x4, (int)y4);
- Linia lc1 = new Linia(pc1, pc2);
- Linia lc2 = new Linia(pc2, pc3);
- Linia lc3 = new Linia(pc3, pc4);
- Linia lc4 = new Linia(pc4, pc1);
- Console.WriteLine("Podaj kolor: ");
- color = Console.ReadLine();
- Ala.DodajCzworokat(new Czworokat(lc1, lc2, lc3, lc4, color));
- Console.WriteLine("Dodano Czworokąt");
- Console.ReadKey();
- break;
- }
- case 3:
- {
- Ala.WyswietlTrojkat();
- Console.ReadKey();
- break;
- }
- case 4:
- {
- Console.WriteLine("Przesuniecie trójkątów względem x: ");
- przes1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Przesuniecie trójkątów względem y: ");
- przes2 = Convert.ToInt16(Console.ReadLine());
- Ala.PrzesunTrojkat(przes1, przes2);
- break;
- }
- case 5:
- {
- Ala.WyswietlCzworokat();
- Console.ReadKey();
- break;
- }
- case 6:
- {
- Console.WriteLine("Przesuniecie czworokątów względem x: ");
- przes1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Przesuniecie czworokątów względem y: ");
- przes2 = Convert.ToInt16(Console.ReadLine());
- Ala.PrzesunCzworokat(przes1, przes2);
- break;
- }
- case 7:
- {
- Console.WriteLine("Współrzędna x 1 punktu: ");
- x1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 1 punktu: ");
- y1 = Convert.ToInt16(Console.ReadLine());
- Punkt pc1 = new Punkt((int)x1, (int)y1);
- Console.WriteLine("Współrzędna x 2 punktu: ");
- x2 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Współrzędna y 2 punktu: ");
- y2 = Convert.ToInt16(Console.ReadLine());
- Punkt pc3 = new Punkt((int)x2, (int)y2);
- //Punkt pc2 = new Punkt((int)x1, (int)y2);
- //Punkt pc4 = new Punkt((int)x2, (int)y1);
- //Linia lc1 = new Linia(pc1, pc2);
- //Linia lc2 = new Linia(pc2, pc3);
- //Linia lc3 = new Linia(pc3, pc4);
- //Linia lc4 = new Linia(pc4, pc1);
- Console.WriteLine("Podaj kolor: ");
- color = Console.ReadLine();
- //Ala.DodajProstokat(new Prostokat(lc1, lc2, lc3, lc4, color));
- Ala.DodajProstokat(new Prostokat(pc1, pc3, color));
- Console.WriteLine("Dodano 'Prostokat'");
- Console.ReadKey();
- break;
- }
- case 8:
- {
- Ala.WyswietlProstokat();
- Console.ReadKey();
- break;
- }
- case 9:
- {
- Console.WriteLine("Przesuniecie Prostokat względem x: ");
- przes1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Przesuniecie Ptostokat względem y: ");
- przes2 = Convert.ToInt16(Console.ReadLine());
- Ala.PrzesunProstokat(przes1, przes2);
- break;
- }
- case 10:
- {
- Console.WriteLine("Współrzędna x 1 punktu: ");
- x1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Długość boku: ");
- Console.WriteLine("Współrzędna y 1 punktu: ");
- y1 = Convert.ToInt16(Console.ReadLine());
- Punkt pc1 = new Punkt((int)x1, (int)y1);
- Console.WriteLine("Długość boku: ");
- dlugosc = Convert.ToInt16(Console.ReadLine());
- x2 = x1; y2 = x1 + dlugosc;
- Punkt pc2 = new Punkt((int)x2, (int)y2);
- x3 = x2 + dlugosc; y3 = y2;
- Punkt pc3 = new Punkt((int)x3, (int)y3);
- x4 = x3; y4 = y3 - dlugosc;
- Punkt pc4 = new Punkt((int)x4, (int)y4);
- Linia lc1 = new Linia(pc1, pc2);
- Linia lc2 = new Linia(pc2, pc3);
- Linia lc3 = new Linia(pc3, pc4);
- Linia lc4 = new Linia(pc4, pc1);
- Console.WriteLine("Podaj kolor: ");
- color = Console.ReadLine();
- Ala.DodajKwadrat(new Kwadrat(lc1, lc2, lc3, lc4, color));
- Console.WriteLine("Dodano 'Kwadrat'");
- Console.ReadKey();
- break;
- }
- case 11:
- {
- Ala.WyswietlKwadrat();
- Console.ReadKey();
- break;
- }
- case 12:
- {
- Console.WriteLine("Przesuniecie Kwadrat względem x: ");
- przes1 = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("Przesuniecie Kwadrat względem y: ");
- przes2 = Convert.ToInt16(Console.ReadLine());
- Ala.PrzesunKwadrat(przes1, przes2);
- break;
- }
- }
- }
- Console.WriteLine("_______________________________________koniec_____________________________________________");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement