Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.53 KB | None | 0 0
  1. public class Settings : BaseWindow
  2.     {
  3.         private readonly RectangleShape backButton;
  4.         private readonly Text backText;
  5.         private readonly Text settingsText;
  6.  
  7.         private readonly RectangleShape easyButton;
  8.         private readonly RectangleShape mediumButton;
  9.         private readonly RectangleShape hardButton;
  10.         private readonly Text easyButtonText;
  11.         private readonly Text mediumButtonText;
  12.         private readonly Text hardButtonText;
  13.  
  14.  
  15.         public Settings()
  16.         {
  17.             backButton = new RectangleShape(new Vector2f(700, 100))
  18.             {
  19.                 FillColor = new Color(150, 200, 150),
  20.                 Position = new Vector2f(50, 475)
  21.             };
  22.  
  23.             backText = new Text("BACK TO MENU", Font)
  24.             {
  25.                 CharacterSize = 60,
  26.                 Style = Text.Styles.Regular,
  27.                 Position = new Vector2f(190, 485),
  28.                 Color = Color.Blue
  29.             };
  30.  
  31.             string topTextString = "Difficulty level:";
  32.            
  33.  
  34.             settingsText = new Text(topTextString, Font)
  35.             {
  36.                 CharacterSize = 20,
  37.                 Style = Text.Styles.Regular,
  38.                 Position = new Vector2f(50, 50),
  39.                 Color = Color.Blue
  40.             };
  41.  
  42.             easyButton = new RectangleShape(new Vector2f(350, 50))
  43.             {
  44.                 FillColor = new Color(150, 200, 150),
  45.                 Position = new Vector2f(30, 85)
  46.             };
  47.  
  48.             easyButtonText = new Text("EASY", Font)
  49.             {
  50.                 CharacterSize = 30,
  51.                 Style = Text.Styles.Regular,
  52.                 Position = new Vector2f(170, 90),
  53.                 Color = Color.Blue
  54.             };
  55.  
  56.             mediumButton = new RectangleShape(new Vector2f(350, 50))
  57.             {
  58.                 FillColor = new Color(150, 200, 150),
  59.                 Position = new Vector2f(30, 175)
  60.             };
  61.  
  62.             mediumButtonText = new Text("MEDIUM", Font)
  63.             {
  64.                 CharacterSize = 30,
  65.                 Style = Text.Styles.Regular,
  66.                 Position = new Vector2f(150, 180),
  67.                 Color = Color.Blue
  68.             };
  69.  
  70.             hardButton = new RectangleShape(new Vector2f(350, 50))
  71.             {
  72.                 FillColor = new Color(150, 200, 150),
  73.                 Position = new Vector2f(30, 265)
  74.             };
  75.  
  76.             hardButtonText = new Text("HARD", Font)
  77.             {
  78.                 CharacterSize = 30,
  79.                 Style = Text.Styles.Regular,
  80.                 Position = new Vector2f(170, 270),
  81.                 Color = Color.Blue
  82.             };
  83.  
  84.  
  85.  
  86.             bindEvents();
  87.             start();
  88.         }
  89.  
  90.         private void start()
  91.         {
  92.             while (Window.IsOpen)
  93.             {
  94.                 Window.DispatchEvents(); //init event
  95.                 Window.Clear(new Color(0, 192, 255)); //clear window
  96.  
  97.                 Window.Draw(backButton);
  98.                 Window.Draw(backText);
  99.  
  100.                 Window.Draw(settingsText);
  101.  
  102.                 Window.Draw(easyButton);
  103.                 Window.Draw(easyButtonText);
  104.  
  105.                 Window.Draw(mediumButton);
  106.                 Window.Draw(mediumButtonText);
  107.  
  108.                 Window.Draw(hardButton);
  109.                 Window.Draw(hardButtonText);
  110.  
  111.                 Window.Display(); //display render up view
  112.             }
  113.         }
  114.  
  115.         private void bindEvents()
  116.         {
  117.             Window.MouseMoved += (sender, e) =>
  118.             {
  119.                 backButton.FillColor = backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)
  120.                     ? new Color(100, 100, 100)
  121.                     : new Color(150, 200, 150);
  122.  
  123.                 easyButton.FillColor = easyButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)
  124.                     ? new Color(100, 100, 100)
  125.     :               new Color(150, 200, 150);
  126.                 mediumButton.FillColor = mediumButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)
  127.                     ? new Color(100, 100, 100)
  128.                     : new Color(150, 200, 150);
  129.                 hardButton.FillColor = hardButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)
  130.                     ? new Color(100, 100, 100)
  131.                     : new Color(150, 200, 150);
  132.             };
  133.  
  134.             Window.MouseButtonReleased += (sender, args) =>
  135.             {
  136.                 if (backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  137.                 {
  138.                     WindowsStack.CloseLastWindow();
  139.                 }
  140.                 else if (easyButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  141.                 {
  142.                     GameLogic.difficulty = 2;
  143.                     WindowsStack.CloseLastWindow();
  144.                 }
  145.                 else if (mediumButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  146.                 {
  147.                     GameLogic.difficulty = 4;
  148.                     WindowsStack.CloseLastWindow();
  149.                 }
  150.                 else if (hardButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  151.                 {
  152.                     GameLogic.difficulty = 5;
  153.                     WindowsStack.CloseLastWindow();
  154.                 }
  155.             };
  156.         }
  157.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement