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;
- namespace Zad_5
- {
- class Czajnik
- {
- public string Name { get; set; }
- public int Power { get; set; }
- private bool isActive;
- public Czajnik()
- {
- this.Name = "Undefined";
- this.Power = 0;
- this.isActive = false;
- }
- public Czajnik(string Name, int Power, bool isActive = false)
- {
- this.Name = Name;
- this.Power = Power;
- this.isActive = isActive;
- }
- public Czajnik(Czajnik czajnik)
- {
- this.Name = czajnik.Name;
- this.Power = czajnik.Power;
- this.isActive = czajnik.isActive;
- }
- public void TurnOn()
- {
- this.isActive = true;
- }
- public void TurnOff()
- {
- this.isActive = false;
- }
- public void ChangeActive()
- {
- if(isActive)
- {
- TurnOff();
- Console.WriteLine("Czajnik został wyłączony!");
- }
- else
- {
- TurnOn();
- Console.WriteLine("Czajnik został włączony!");
- }
- }
- public void Print()
- {
- Console.WriteLine("Jestem czajnik");
- if (this.Name != "Undefined" && this.Name != "")
- {
- Console.WriteLine("Nazywam sie: " + Name);
- }
- Console.WriteLine("Zużywam " + Power + " Wattów");
- if (isActive)
- {
- Console.WriteLine("Aktualnie jestem włączony");
- }
- else
- {
- Console.WriteLine("Aktualnie jestem wyłączony");
- }
- }
- public void PrintMenu()
- {
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.Clear();
- Console.WriteLine("=====MENU=====");
- Console.WriteLine("===CZAJNIK====");
- Console.WriteLine("1 - Włącz/Wyłącz czajnik");
- Console.WriteLine("2 - Wyświetl dane");
- Console.WriteLine("3 - Funkcja 'costam'");
- Console.WriteLine("q - Powrót");
- Console.WriteLine("==============");
- Console.WriteLine("==============");
- }
- public bool costam(int a)
- {
- a *= 2;
- if(a >= 10)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool costam(ref int a)
- {
- a *= 2;
- if (a >= 10)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void costam(int a, out bool output)
- {
- a *= 2;
- if (a >= 10)
- {
- output = true;
- }
- else
- {
- output = false;
- }
- }
- }
- class Radio
- {
- public string Name { get; set; }
- protected int NumberOfBeeps;
- private bool isActive;
- public Radio()
- {
- this.Name = "Undefined";
- this.NumberOfBeeps = 0;
- this.isActive = false;
- }
- public Radio(string Name, int NumberOfBeeps = 0, bool isActive = false)
- {
- this.Name = Name;
- this.NumberOfBeeps = NumberOfBeeps;
- this.isActive = isActive;
- }
- public Radio(Radio radio)
- {
- this.Name = radio.Name;
- this.NumberOfBeeps = radio.NumberOfBeeps;
- this.isActive = radio.isActive;
- }
- public void Print()
- {
- Console.WriteLine("Jestem radio");
- if (this.Name != "Undefined" && this.Name != "")
- {
- Console.WriteLine("Nazywam sie: " + Name);
- }
- Console.WriteLine("Będę pikał " + NumberOfBeeps + " razy");
- if (isActive)
- {
- Console.WriteLine("Aktualnie jestem włączony");
- }
- else
- {
- Console.WriteLine("Aktualnie jestem wyłączony");
- }
- }
- public void PrintMenu()
- {
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- Console.Clear();
- Console.WriteLine("=====MENU=====");
- Console.WriteLine("====RADIO=====");
- Console.WriteLine("1 - Włącz/Wyłącz radio");
- Console.WriteLine("2 - Wyświetl dane");
- Console.WriteLine("3 - Muzyczka z mario");
- Console.WriteLine("q - Powrót");
- Console.WriteLine("==============");
- Console.WriteLine("==============");
- }
- public void MakeSound()
- {
- if (!isActive)
- {
- Console.WriteLine("Radio jest wyłączone!");
- return;
- }
- for (int i = 0; i < NumberOfBeeps; i++)
- {
- Console.Beep();
- }
- }
- public void MakeSound(int Frequency, int Duration)
- {
- if (!isActive)
- {
- Console.WriteLine("Radio jest wyłączone!");
- return;
- }
- for (int i = 0; i < NumberOfBeeps; i++)
- {
- Console.Beep(Frequency, Duration);
- }
- }
- public void TurnOn()
- {
- this.isActive = true;
- }
- public void TurnOff()
- {
- this.isActive = false;
- }
- public void ChangeActive()
- {
- if (isActive)
- {
- TurnOff();
- Console.WriteLine("Radio zostało wyłączone!");
- }
- else
- {
- TurnOn();
- Console.WriteLine("Radio zostało włączone!");
- }
- }
- public void SetNumberOfBeeps(int value)
- {
- NumberOfBeeps = value;
- }
- public void PlayMusic()
- {
- Console.Beep(659, 125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(523, 125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(784, 125);
- Thread.Sleep(375);
- Console.Beep(392, 125);
- Thread.Sleep(375);
- Console.Beep(523, 125);
- Thread.Sleep(250);
- Console.Beep(392, 125);
- Thread.Sleep(250);
- Console.Beep(330, 125);
- Thread.Sleep(250);
- Console.Beep(440, 125);
- Thread.Sleep(125);
- Console.Beep(494, 125);
- Thread.Sleep(125);
- Console.Beep(466, 125);
- Thread.Sleep(42);
- Console.Beep(440, 125);
- Thread.Sleep(125);
- Console.Beep(392, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(784, 125);
- Thread.Sleep(125);
- Console.Beep(880, 125);
- Thread.Sleep(125);
- Console.Beep(698, 125);
- Console.Beep(784, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(587, 125);
- Console.Beep(494, 125);
- Thread.Sleep(125);
- Console.Beep(523, 125);
- Thread.Sleep(250);
- Console.Beep(392, 125);
- Thread.Sleep(250);
- Console.Beep(330, 125);
- Thread.Sleep(250);
- Console.Beep(440, 125);
- Thread.Sleep(125);
- Console.Beep(494, 125);
- Thread.Sleep(125);
- Console.Beep(466, 125);
- Thread.Sleep(42);
- Console.Beep(440, 125);
- Thread.Sleep(125);
- Console.Beep(392, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(784, 125);
- Thread.Sleep(125);
- Console.Beep(880, 125);
- Thread.Sleep(125);
- Console.Beep(698, 125);
- Console.Beep(784, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(587, 125);
- Console.Beep(494, 125);
- Thread.Sleep(375);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(415, 125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(698, 125);
- Thread.Sleep(125);
- Console.Beep(698, 125);
- Console.Beep(698, 125);
- Thread.Sleep(625);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(415, 125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(622, 125);
- Thread.Sleep(250);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(523, 125);
- Thread.Sleep(1125);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(415, 125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(698, 125);
- Thread.Sleep(125);
- Console.Beep(698, 125);
- Console.Beep(698, 125);
- Thread.Sleep(625);
- Console.Beep(784, 125);
- Console.Beep(740, 125);
- Console.Beep(698, 125);
- Thread.Sleep(42);
- Console.Beep(622, 125);
- Thread.Sleep(125);
- Console.Beep(659, 125);
- Thread.Sleep(167);
- Console.Beep(415, 125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Thread.Sleep(125);
- Console.Beep(440, 125);
- Console.Beep(523, 125);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(622, 125);
- Thread.Sleep(250);
- Console.Beep(587, 125);
- Thread.Sleep(250);
- Console.Beep(523, 125);
- }
- }
- class Program
- {
- static void PrintMainMenu()
- {
- Console.ForegroundColor = ConsoleColor.DarkGray;
- Console.Clear();
- Console.WriteLine("=====MENU=====");
- Console.WriteLine("==============");
- Console.WriteLine("1 - Czajnik");
- Console.WriteLine("2 - Radio");
- Console.WriteLine("q - Wyjście");
- Console.WriteLine("==============");
- Console.WriteLine("==============");
- }
- static void Pause()
- {
- Console.WriteLine("\n\nAby kontynuować wciśnij dowolny klawisz...");
- Console.ReadKey(true);
- }
- static void Main(string[] args)
- {
- string input;
- Czajnik czajnik = new Czajnik("Eduardo", 45);
- Radio radio = new Radio("Juan");
- while(true)
- {
- PrintMainMenu();
- input = Console.ReadKey(true).Key.ToString();
- if(input == "Q")
- {
- break;
- }
- else if(input == "D1")
- {
- while (true)
- {
- czajnik.PrintMenu();
- input = Console.ReadKey(true).Key.ToString();
- if (input == "Q")
- {
- break;
- }
- else if (input == "D1")
- {
- Console.Clear();
- czajnik.ChangeActive();
- Pause();
- }
- else if (input == "D2")
- {
- Console.Clear();
- czajnik.Print();
- Pause();
- }
- else if (input == "D3")
- {
- Console.Clear();
- Console.WriteLine(czajnik.costam(3));
- Pause();
- }
- }//END OF WHILE
- }//END OF ELSE IF
- else if (input == "D2")
- {
- while (true)
- {
- radio.PrintMenu();
- input = Console.ReadKey(true).Key.ToString();
- if (input == "Q")
- {
- break;
- }
- else if (input == "D1")
- {
- Console.Clear();
- radio.ChangeActive();
- Pause();
- }
- else if (input == "D2")
- {
- Console.Clear();
- radio.Print();
- Pause();
- }
- else if (input == "D3")
- {
- Console.Clear();
- Console.WriteLine("Trwa odtwarzanie muzyczki!");
- radio.PlayMusic();
- }
- }//END OF WHILE
- }//END OF ELSE IF
- }//END OF WHILE
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement