Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System;
- using System.Collections.Generic;
- namespace Memory_Moje
- {
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D plansza;
- Texture2D przykrycie;
- bool? wcisniety = false;
- int liczba_odslonietych=0;
- Klocek e1, e2;
- int aimX, aimY;
- class Klocek
- {
- public Rectangle elementRec;
- public Rectangle obrazdoWyciecia;
- public Color kolor;
- public bool odsloniety;
- public Klocek(Rectangle _elementRec, Rectangle _obrazDoWyciecia, Color _kolor)
- {
- elementRec = _elementRec;
- obrazdoWyciecia = _obrazDoWyciecia;
- kolor = _kolor;
- odsloniety=false;
- }
- }
- List<Klocek> lista_klockow = new List<Klocek>();
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- graphics.PreferredBackBufferWidth = 1000;
- graphics.PreferredBackBufferHeight = 500;
- Content.RootDirectory = "Content";
- Window.AllowUserResizing = false;
- IsMouseVisible = true;
- }
- protected override void Initialize()
- {
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- plansza = Content.Load<Texture2D>("billy_talent");
- przykrycie = Content.Load<Texture2D>("b3");
- int zmianaKoloru=0;
- 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 };
- for (int i=0;i<10;i++)
- {
- for(int j=0;j<10;j++)
- {
- Klocek n = new Klocek(new Rectangle(i * 100 , (j * 50) , 100, 50), new Rectangle(i * 100, j * 100, 100, 100), tab[zmianaKoloru]);
- lista_klockow.Add(n);
- }
- zmianaKoloru++;
- }
- Pomieszaj();
- }
- private void Pomieszaj()
- {
- Random rand = new Random();
- for(int i=0;i<300; ++i)
- {
- int l1 = rand.Next(99);
- int l2 = rand.Next(99);
- Klocek temp = new Klocek(lista_klockow[l1].elementRec, lista_klockow[l1].obrazdoWyciecia, lista_klockow[l1].kolor);
- lista_klockow[l1].kolor = lista_klockow[l2].kolor;
- lista_klockow[l2].kolor = temp.kolor;
- }
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- MouseState state = Mouse.GetState();
- aimX = state.X;
- aimY = state.Y;
- foreach (Klocek k in lista_klockow)
- {
- if (k.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton==ButtonState.Pressed && !k.odsloniety)
- {
- k.odsloniety = true;
- liczba_odslonietych++;
- if(e1==null)
- {
- e1=k;
- }
- else if (e2 == null)
- {
- e2=k;
- }
- }
- }
- if (liczba_odslonietych == 3)
- {
- System.Threading.Thread.Sleep(500);
- if (!(e1.kolor == e2.kolor))
- {
- e1.odsloniety = false;
- e2.odsloniety = false;
- }
- liczba_odslonietych = 0;
- e1 = null;
- e2 = null;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- foreach(Klocek k in lista_klockow)
- {
- if (k.odsloniety == true)
- {
- spriteBatch.Draw(plansza, k.elementRec, k.obrazdoWyciecia, k.kolor);
- }
- else
- {
- spriteBatch.Draw(przykrycie, k.elementRec, Color.White);
- }
- }
- spriteBatch.End();
- if (liczba_odslonietych == 2) ++liczba_odslonietych;
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement