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.Collections.Generic;
- using System;
- namespace Labolatorium1
- {
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- int aimX;
- int aimY;
- Texture2D background;
- Texture2D icon;
- Texture2D numbers;
- Texture2D question;
- Rectangle dupa;
- Rectangle dupa2;
- bool test;
- bool test2;
- List<Texture2D> lista_icon = new List<Texture2D>();
- class Element
- {
- public Texture2D question1;
- public Rectangle obrazdoWyciecia;
- public Rectangle elementRec { get; set; }
- public Color kolor;
- public bool? najechany = false;
- public Element(Texture2D _question, Rectangle _elementRec,Rectangle _obrazdoWyciecia, Color _kolor)
- {
- elementRec = _elementRec;
- obrazdoWyciecia = _obrazdoWyciecia;
- kolor = _kolor;
- question1 = _question;
- }
- }
- List<Element> ListaElementow = new List<Element>();
- class Element_numbers
- {
- public Rectangle obrazdoWyciecia;
- public Rectangle elementRec;
- public Color kolor;
- public bool klikniety;
- public bool widoczny;
- public Element_numbers(Rectangle _elementRec, Rectangle _obrazdoWyciecia, Color _kolor)
- {
- klikniety = false;
- widoczny = false;
- elementRec = _elementRec;
- obrazdoWyciecia = _obrazdoWyciecia;
- kolor = _kolor;
- }
- }
- List<Element_numbers> ListaElementow_numbers = new List<Element_numbers>();
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
- Window.AllowUserResizing = true;
- }
- protected override void Initialize()
- {
- graphics.IsFullScreen = false;
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 650;
- graphics.ApplyChanges();
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- background = Content.Load<Texture2D>("background");
- icon = Content.Load<Texture2D>("question");
- question= Content.Load<Texture2D>("question");
- numbers = Content.Load<Texture2D>("numbers");
- Color[] tab = new Color[2] { Color.White, Color.Red };
- //Pole znakow zapytania
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- Rectangle field_rec = new Rectangle(200 + (50 * i), 5 + (50 * j), 50, 50);
- Element n = new Element(question,field_rec,new Rectangle(0,0,100,100), tab[0]);
- ListaElementow.Add(n);
- }
- }
- //Liczby
- for (int i = 0; i < 4; i++)
- {
- Element_numbers k = new Element_numbers(new Rectangle(5, 120 + (i * 65), 60, 60), new Rectangle(0 + (i * 100), 0, 100, 100), tab[0]);
- ListaElementow_numbers.Add(k);
- }
- for (int i = 0; i < 4; i++)
- {
- Element_numbers k = new Element_numbers(new Rectangle(5, 380 + (i * 65), 60, 60), new Rectangle(0 + (i * 100), 100, 100, 100), tab[0]);
- ListaElementow_numbers.Add(k);
- }
- }
- 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();
- if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true)
- this.Exit();
- MouseState state = Mouse.GetState();
- aimX = state.X;
- aimY = state.Y;
- foreach(Element_numbers e in ListaElementow_numbers)
- {
- if(e.elementRec.Contains(aimX,aimY))
- {
- e.kolor = Color.Red;
- }
- else
- {
- e.kolor = Color.White;
- }
- }
- foreach (Element_numbers e in ListaElementow_numbers)
- {
- if (e.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton==ButtonState.Pressed)
- {
- test = true;
- dupa = new Rectangle(e.obrazdoWyciecia.X,e.obrazdoWyciecia.Y,100,100);
- }
- }
- foreach (Element e in ListaElementow)
- {
- if (e.elementRec.Contains(aimX, aimY) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- if (test == true)
- {
- e.obrazdoWyciecia = dupa;
- e.question1 = numbers;
- test2 = true;
- }
- }
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- //BackGround
- spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
- if (test == true)
- //Ikona
- {
- spriteBatch.Draw(numbers, new Rectangle(5, 5, 100, 100), dupa, Color.White);
- }
- else
- {
- spriteBatch.Draw(icon, new Rectangle(5, 5, 100, 100), Color.White);
- }
- foreach(Element_numbers e in ListaElementow_numbers)
- {
- spriteBatch.Draw(numbers, e.elementRec, e.obrazdoWyciecia, e.kolor);
- }
- foreach (Element e in ListaElementow)
- {
- spriteBatch.Draw(e.question1, e.elementRec, e.obrazdoWyciecia, e.kolor, 0, new Vector2(0, 0), SpriteEffects.None, 0);
- }
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement