Advertisement
wozniol

Programowanie zaawansowane #1

Mar 31st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 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 ConsoleApp12
  8. {
  9.     /*
  10.         class Program
  11.         {
  12.             static void Main(string[] args)
  13.             {
  14.                 Knight spk = new Knight();
  15.                 spk.doTask();
  16.                 spk.lives--;
  17.                 Console.WriteLine("Lives: " + spk.lives);
  18.                 spk.task = new SavePrincessTask();
  19.                 spk.doTask();
  20.                 Console.WriteLine("Lives: " + spk.lives);
  21.  
  22.                 Console.ReadKey();
  23.             }
  24.         }
  25.  
  26.         abstract class Task
  27.         {
  28.             public abstract void challengeAccepted();
  29.  
  30.         }
  31.  
  32.         class Knight
  33.         {
  34.            public Task task = new SeatInToiletTask();
  35.  
  36.             public int lives = 3;
  37.  
  38.             public void doTask()
  39.             {
  40.                 task.challengeAccepted();
  41.             }
  42.         }
  43.  
  44.         class SavePrincessTask : Task
  45.         {
  46.             public override void challengeAccepted()
  47.             {
  48.                 Console.WriteLine("Jestem Shrek i uratuje ksiezniczke!");
  49.             }
  50.         }
  51.  
  52.         class SeatInToiletTask : Task
  53.         {
  54.             public override void challengeAccepted()
  55.             {
  56.                 Console.WriteLine("Jestem strachliwym rycerzem...siedze w kiblu i udaje ze mam raczke!");
  57.             }
  58.  
  59.         }
  60.  
  61.         */
  62.     class Program
  63.     {
  64.         static void Main(string[] args)
  65.         {
  66.             Car car_1 = new Car();
  67.             car_1.engine = new ElectriceEngine();
  68.             car_1.startEngine();
  69.  
  70.             Console.ReadKey();
  71.         }
  72.     }
  73.  
  74.     abstract class Vehicle
  75.     {
  76.  
  77.     }
  78.  
  79.     class Car : Vehicle
  80.     {
  81.         public Engine engine;
  82.  
  83.         public void startEngine()
  84.         {
  85.             engine.start();
  86.         }
  87.  
  88.         public void stopEngine()
  89.         {
  90.             engine.stop();
  91.         }
  92.     }
  93.  
  94.     abstract class Engine
  95.     {
  96.         public bool working = false;
  97.         public abstract void start();
  98.         public abstract void stop();
  99.     }
  100.    
  101.     class ElectriceEngine : Engine
  102.     {
  103.         public override void start()
  104.         {
  105.             working = true;
  106.             Console.WriteLine("bezglosnie sie odpalam");
  107.         }
  108.  
  109.         public override void stop()
  110.         {
  111.             working = false;
  112.             Console.WriteLine("Bezglosnie sie wylaczam");
  113.         }
  114.     }
  115.  
  116.     class BenzineEngine : Engine
  117.     {
  118.         public override void start()
  119.         {
  120.             working = true;
  121.             Console.WriteLine("Glosno sie odpalam");
  122.         }
  123.  
  124.         public override void stop()
  125.         {
  126.             working = false;
  127.             Console.WriteLine("Glosno sie wylaczam");
  128.         }
  129.     }
  130.  
  131.     class DieselEngine : Engine
  132.     {
  133.         public override void start()
  134.         {
  135.             working = true;
  136.             Console.WriteLine("Dymie kiedy sie odpalam");
  137.         }
  138.  
  139.         public override void stop()
  140.         {
  141.             working = false;
  142.             Console.WriteLine("Dymie kiedy sie wylaczam");
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement