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;
- namespace Coins
- {
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D background, coins, unknown, param;
- Texture2D[,] param2;
- Rectangle[] coinsRec;
- Rectangle[] coinsCut;
- Rectangle[,] board;
- Rectangle[,] boardcut;
- bool questionFlag;
- Rectangle question,rect;
- Color[] coinsColor;
- MouseState ms;
- KeyboardState ks;
- Point pms;
- int coinscount;
- int coinWidth = 50, coinHeight = 50, coinWidthCut = 100, coinHeightCut = 100;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 800;
- }
- protected override void Initialize()
- {
- coinsRec = new Rectangle[8];
- coinsCut = new Rectangle[8];
- coinsColor = new Color[8];
- board = new Rectangle[10,10];
- boardcut = new Rectangle[10,10];
- param2 = new Texture2D[10, 10];
- question = new Rectangle(25,25,100,100);
- rect = new Rectangle(0,0,100,100);
- coinscount = 0;
- questionFlag = false;
- for(int i = 0; i < 2; i++)
- {
- for(int j = 0; j < 4; j++)
- {
- coinsRec[coinscount] = new Rectangle(0+25, coinscount*55+150, coinWidth, coinHeight);
- coinsCut[coinscount] = new Rectangle(j*100, i*100, coinWidthCut, coinHeightCut);
- coinsColor[coinscount] = Color.White;
- coinscount += 1;
- }
- }
- for(int i = 0; i < 10; i++)
- {
- for(int j = 0; j < 10; j++)
- {
- board[i, j] = new Rectangle(150+(50*i),150+(50*j),50,50);
- boardcut[i, j] = new Rectangle(0,0,100,100);
- }
- }
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- background = Content.Load<Texture2D>("background");
- coins = Content.Load<Texture2D>("numbers");
- unknown = Content.Load<Texture2D>("question");
- param = unknown;
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- param2[i, j] = unknown;
- }
- }
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- ms = Mouse.GetState();
- pms = new Point(ms.X, ms.Y);
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- this.Exit();
- if (question.Contains(pms))
- {
- if(ms.LeftButton == ButtonState.Pressed)
- {
- questionFlag = true;
- param = unknown;
- rect = new Rectangle(0, 0, 100, 100);
- }
- }
- for (int i = 0; i < 8; i++)
- {
- if (coinsRec[i].Contains(pms))
- {
- coinsColor[i] = Color.Red;
- if(ms.LeftButton == ButtonState.Pressed)
- {
- questionFlag = false;
- param = coins;
- rect = coinsCut[i];
- }
- }
- else coinsColor[i] = Color.White;
- }
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- if (board[i, j].Contains(pms))
- {
- if(ms.LeftButton == ButtonState.Pressed)
- {
- if (questionFlag == true)
- {
- param2[i, j] = unknown;
- boardcut[i, j] = new Rectangle(0, 0, 100, 100);
- }
- else
- {
- param2[i, j] = coins;
- boardcut[i, j] = rect;
- }
- }
- }
- }
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
- spriteBatch.Draw(param, question, rect, Color.White);
- for(int i = 0; i < 8; i++)
- {
- spriteBatch.Draw(coins, coinsRec[i], coinsCut[i], coinsColor[i]);
- }
- for(int i = 0; i < 10; i++)
- {
- for(int j = 0; j < 10; j++)
- {
- spriteBatch.Draw(param2[i, j], board[i,j], boardcut[i,j], Color.White);
- }
- }
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement