Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace Schemat_GUI
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- }
- }
- struct MousePosition
- {
- public int X { get; set; }
- public int Y { get; set; }
- MousePosition(int x, int y)
- {
- X = x;
- Y = y;
- }
- }
- interface IGUIElement
- {
- void Draw();
- void Click(MousePosition mousePosition);
- }
- class Logic
- {
- public void Run()
- {
- Button calculateMeanButton = new Button(MeanButtonClick);
- List<IGUIElement> elements = new List<IGUIElement> { calculateMeanButton };
- Menu mainMenu = new Menu(elements);
- while (mainMenu.GetIsOpen())
- {
- mainMenu.Draw();
- //if (mouse.IsClicked())
- //{
- // mainMenu.Clikc(getMousePosition());
- //}
- }
- }
- private void MeanButtonClick()
- {
- double mean = Calculator.Mean(Calculator.Generate(10));
- File.WriteAllText("wynik.txt", mean.ToString());
- DisplayWindow display = new DisplayWindow(mean.ToString());
- display.Draw();
- }
- }
- class Menu : IGUIElement
- {
- private List<IGUIElement> elements;
- private bool isOpen = true;
- public bool GetIsOpen() { return isOpen; }
- public void Close() { isOpen = false; }
- public void Draw() { }
- public void Click(MousePosition mousePosition)
- {
- foreach (var element in elements)
- {
- element.Click(mousePosition);
- }
- }
- public Menu(List<IGUIElement> elements)
- {
- this.elements = elements;
- }
- }
- class Button : IGUIElement
- {
- Action onClick;
- public void Draw() { }
- public void Click(MousePosition mousePosition)
- {
- //if mousPositon is in buttonArea
- onClick();
- }
- public Button (Action onClick)
- {
- this.onClick = onClick;
- }
- }
- class DisplayWindow : IGUIElement
- {
- private string content;
- public void Click(MousePosition mousePosition)
- {
- // if close icon clicked
- Close();
- }
- public void Draw()
- {
- //Display content
- }
- public void Close() { }
- public DisplayWindow(string content)
- {
- this.content = content;
- }
- }
- class Calculator
- {
- public static List<int> Generate(int howMany)
- {
- List<int> randomNumbers = new List<int>(howMany);
- Random random = new Random();
- for (int i = 0; i < howMany; i++)
- {
- randomNumbers.Add(random.Next());
- }
- return randomNumbers;
- }
- public static int Sum(List<int> numbers)
- {
- int sum = 0;
- foreach (var number in numbers)
- {
- sum += number;
- }
- return sum;
- }
- public static double Mean(List<int> numbers)
- {
- return (double)Sum(numbers) / (double) numbers.Count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement