Advertisement
adolciaaa

Nieoceniane1

Oct 16th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5. using System;
  6.  
  7. namespace Labolatorium1
  8. {
  9.  
  10. public class Game1 : Game
  11. {
  12. GraphicsDeviceManager graphics;
  13. SpriteBatch spriteBatch;
  14.  
  15. int aimX;
  16. int aimY;
  17.  
  18. Texture2D background;
  19. Texture2D icon;
  20. Texture2D numbers;
  21. Texture2D question;
  22.  
  23. Rectangle dupa;
  24. Rectangle dupa2;
  25.  
  26. bool test;
  27. bool test2;
  28. List<Texture2D> lista_icon = new List<Texture2D>();
  29. class Element
  30. {
  31. public Texture2D question1;
  32. public Rectangle obrazdoWyciecia;
  33. public Rectangle elementRec { get; set; }
  34. public Color kolor;
  35. public bool? najechany = false;
  36.  
  37. public Element(Texture2D _question, Rectangle _elementRec,Rectangle _obrazdoWyciecia, Color _kolor)
  38. {
  39. elementRec = _elementRec;
  40. obrazdoWyciecia = _obrazdoWyciecia;
  41. kolor = _kolor;
  42. question1 = _question;
  43. }
  44.  
  45. }
  46. List<Element> ListaElementow = new List<Element>();
  47.  
  48. class Element_numbers
  49. {
  50.  
  51. public Rectangle obrazdoWyciecia;
  52. public Rectangle elementRec;
  53. public Color kolor;
  54. public bool klikniety;
  55. public bool widoczny;
  56. public Element_numbers(Rectangle _elementRec, Rectangle _obrazdoWyciecia, Color _kolor)
  57. {
  58. klikniety = false;
  59. widoczny = false;
  60. elementRec = _elementRec;
  61. obrazdoWyciecia = _obrazdoWyciecia;
  62. kolor = _kolor;
  63. }
  64.  
  65.  
  66. }
  67. List<Element_numbers> ListaElementow_numbers = new List<Element_numbers>();
  68.  
  69. public Game1()
  70. {
  71. graphics = new GraphicsDeviceManager(this);
  72. Content.RootDirectory = "Content";
  73. this.IsMouseVisible = true;
  74. Window.AllowUserResizing = true;
  75. }
  76.  
  77.  
  78. protected override void Initialize()
  79. {
  80. graphics.IsFullScreen = false;
  81. graphics.PreferredBackBufferWidth = 800;
  82. graphics.PreferredBackBufferHeight = 650;
  83. graphics.ApplyChanges();
  84. base.Initialize();
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
  91. protected override void LoadContent()
  92. {
  93.  
  94. spriteBatch = new SpriteBatch(GraphicsDevice);
  95.  
  96. background = Content.Load<Texture2D>("background");
  97.  
  98. icon = Content.Load<Texture2D>("question");
  99.  
  100. question= Content.Load<Texture2D>("question");
  101.  
  102. numbers = Content.Load<Texture2D>("numbers");
  103.  
  104. Color[] tab = new Color[2] { Color.White, Color.Red };
  105.  
  106. //Pole znakow zapytania
  107. for (int i = 0; i < 10; i++)
  108. {
  109. for (int j = 0; j < 10; j++)
  110. {
  111. Rectangle field_rec = new Rectangle(200 + (50 * i), 5 + (50 * j), 50, 50);
  112.  
  113. Element n = new Element(question,field_rec,new Rectangle(0,0,100,100), tab[0]);
  114. ListaElementow.Add(n);
  115. }
  116. }
  117.  
  118. //Liczby
  119. for (int i = 0; i < 4; i++)
  120. {
  121. Element_numbers k = new Element_numbers(new Rectangle(5, 120 + (i * 65), 60, 60), new Rectangle(0 + (i * 100), 0, 100, 100), tab[0]);
  122. ListaElementow_numbers.Add(k);
  123. }
  124. for (int i = 0; i < 4; i++)
  125. {
  126. Element_numbers k = new Element_numbers(new Rectangle(5, 380 + (i * 65), 60, 60), new Rectangle(0 + (i * 100), 100, 100, 100), tab[0]);
  127. ListaElementow_numbers.Add(k);
  128. }
  129.  
  130.  
  131. }
  132.  
  133.  
  134. protected override void UnloadContent()
  135. {
  136.  
  137. }
  138.  
  139.  
  140. protected override void Update(GameTime gameTime)
  141. {
  142.  
  143. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  144. Exit();
  145.  
  146. if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true)
  147. this.Exit();
  148.  
  149. MouseState state = Mouse.GetState();
  150. aimX = state.X;
  151. aimY = state.Y;
  152.  
  153. foreach(Element_numbers e in ListaElementow_numbers)
  154. {
  155. if(e.elementRec.Contains(aimX,aimY))
  156. {
  157. e.kolor = Color.Red;
  158. }
  159. else
  160. {
  161. e.kolor = Color.White;
  162. }
  163. }
  164.  
  165. foreach (Element_numbers e in ListaElementow_numbers)
  166. {
  167. if (e.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton==ButtonState.Pressed)
  168. {
  169.  
  170. test = true;
  171. dupa = new Rectangle(e.obrazdoWyciecia.X,e.obrazdoWyciecia.Y,100,100);
  172.  
  173. }
  174.  
  175.  
  176. }
  177.  
  178. foreach (Element e in ListaElementow)
  179. {
  180.  
  181. if (e.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton == ButtonState.Pressed)
  182. {
  183. if (test == true)
  184. {
  185. e.obrazdoWyciecia = dupa;
  186. e.question1 = numbers;
  187. test2 = true;
  188. }
  189. }
  190.  
  191.  
  192. }
  193.  
  194. base.Update(gameTime);
  195. }
  196.  
  197.  
  198. protected override void Draw(GameTime gameTime)
  199. {
  200. GraphicsDevice.Clear(Color.CornflowerBlue);
  201. spriteBatch.Begin();
  202.  
  203. //BackGround
  204. spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
  205.  
  206. if (test == true)
  207. //Ikona
  208. {
  209. spriteBatch.Draw(numbers, new Rectangle(5, 5, 100, 100), dupa, Color.White);
  210. }
  211. else
  212. {
  213. spriteBatch.Draw(icon, new Rectangle(5, 5, 100, 100), Color.White);
  214. }
  215. foreach(Element_numbers e in ListaElementow_numbers)
  216. {
  217. spriteBatch.Draw(numbers, e.elementRec, e.obrazdoWyciecia, e.kolor);
  218. }
  219.  
  220.  
  221. foreach (Element e in ListaElementow)
  222. {
  223.  
  224. spriteBatch.Draw(e.question1, e.elementRec, e.obrazdoWyciecia, e.kolor, 0, new Vector2(0, 0), SpriteEffects.None, 0);
  225.  
  226. }
  227.  
  228.  
  229. spriteBatch.End();
  230.  
  231.  
  232. base.Draw(gameTime);
  233. }
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement