Advertisement
adolciaaa

Memory

Oct 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System;
  5. using System.Collections.Generic;
  6.  
  7. namespace Memory_Moje
  8. {
  9.  
  10. public class Game1 : Game
  11. {
  12. GraphicsDeviceManager graphics;
  13. SpriteBatch spriteBatch;
  14.  
  15. Texture2D plansza;
  16. Texture2D przykrycie;
  17.  
  18. bool? wcisniety = false;
  19.  
  20. int liczba_odslonietych=0;
  21. Klocek e1, e2;
  22.  
  23. int aimX, aimY;
  24.  
  25. class Klocek
  26. {
  27. public Rectangle elementRec;
  28. public Rectangle obrazdoWyciecia;
  29. public Color kolor;
  30. public bool odsloniety;
  31.  
  32. public Klocek(Rectangle _elementRec, Rectangle _obrazDoWyciecia, Color _kolor)
  33. {
  34. elementRec = _elementRec;
  35. obrazdoWyciecia = _obrazDoWyciecia;
  36. kolor = _kolor;
  37.  
  38. odsloniety=false;
  39. }
  40. }
  41. List<Klocek> lista_klockow = new List<Klocek>();
  42.  
  43.  
  44.  
  45.  
  46. public Game1()
  47. {
  48. graphics = new GraphicsDeviceManager(this);
  49. graphics.PreferredBackBufferWidth = 1000;
  50. graphics.PreferredBackBufferHeight = 500;
  51. Content.RootDirectory = "Content";
  52. Window.AllowUserResizing = false;
  53. IsMouseVisible = true;
  54. }
  55.  
  56.  
  57. protected override void Initialize()
  58. {
  59.  
  60.  
  61. base.Initialize();
  62. }
  63.  
  64.  
  65. protected override void LoadContent()
  66. {
  67.  
  68. spriteBatch = new SpriteBatch(GraphicsDevice);
  69. plansza = Content.Load<Texture2D>("billy_talent");
  70. przykrycie = Content.Load<Texture2D>("b3");
  71.  
  72. int zmianaKoloru=0;
  73. Color[] tab = new Color[10] { Color.Yellow, Color.Green, Color.Blue, Color.Gray, Color.Red, Color.Pink, Color.White, Color.Violet, Color.Orange, Color.Brown };
  74.  
  75. for (int i=0;i<10;i++)
  76. {
  77. for(int j=0;j<10;j++)
  78. {
  79. Klocek n = new Klocek(new Rectangle(i * 100 , (j * 50) , 100, 50), new Rectangle(i * 100, j * 100, 100, 100), tab[zmianaKoloru]);
  80. lista_klockow.Add(n);
  81.  
  82. }
  83. zmianaKoloru++;
  84. }
  85. Pomieszaj();
  86. }
  87.  
  88. private void Pomieszaj()
  89. {
  90. Random rand = new Random();
  91. for(int i=0;i<300; ++i)
  92. {
  93. int l1 = rand.Next(99);
  94. int l2 = rand.Next(99);
  95. Klocek temp = new Klocek(lista_klockow[l1].elementRec, lista_klockow[l1].obrazdoWyciecia, lista_klockow[l1].kolor);
  96. lista_klockow[l1].kolor = lista_klockow[l2].kolor;
  97. lista_klockow[l2].kolor = temp.kolor;
  98. }
  99.  
  100. }
  101.  
  102. protected override void UnloadContent()
  103. {
  104.  
  105. }
  106.  
  107.  
  108. protected override void Update(GameTime gameTime)
  109. {
  110. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  111. Exit();
  112.  
  113.  
  114.  
  115. MouseState state = Mouse.GetState();
  116. aimX = state.X;
  117. aimY = state.Y;
  118.  
  119.  
  120. foreach (Klocek k in lista_klockow)
  121. {
  122. if (k.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton==ButtonState.Pressed && !k.odsloniety)
  123. {
  124.  
  125. k.odsloniety = true;
  126. liczba_odslonietych++;
  127.  
  128. if(e1==null)
  129. {
  130. e1=k;
  131. }
  132. else if (e2 == null)
  133. {
  134. e2=k;
  135. }
  136. }
  137.  
  138. }
  139.  
  140. if (liczba_odslonietych == 3)
  141. {
  142. System.Threading.Thread.Sleep(500);
  143. if (!(e1.kolor == e2.kolor))
  144. {
  145. e1.odsloniety = false;
  146. e2.odsloniety = false;
  147. }
  148. liczba_odslonietych = 0;
  149. e1 = null;
  150. e2 = null;
  151. }
  152. base.Update(gameTime);
  153. }
  154.  
  155.  
  156. protected override void Draw(GameTime gameTime)
  157. {
  158. GraphicsDevice.Clear(Color.CornflowerBlue);
  159.  
  160. spriteBatch.Begin();
  161.  
  162. foreach(Klocek k in lista_klockow)
  163. {
  164. if (k.odsloniety == true)
  165. {
  166. spriteBatch.Draw(plansza, k.elementRec, k.obrazdoWyciecia, k.kolor);
  167.  
  168. }
  169. else
  170. {
  171. spriteBatch.Draw(przykrycie, k.elementRec, Color.White);
  172. }
  173. }
  174.  
  175. spriteBatch.End();
  176.  
  177. if (liczba_odslonietych == 2) ++liczba_odslonietych;
  178. base.Draw(gameTime);
  179. }
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement