Advertisement
Guest User

cycev2.0 CHwaster

a guest
Oct 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.62 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4.  
  5. namespace Coins
  6. {
  7.     public class Game1 : Game
  8.     {
  9.         GraphicsDeviceManager graphics;
  10.         SpriteBatch spriteBatch;
  11.         Texture2D background, coins, unknown, param;
  12.         Texture2D[,] param2;
  13.         Rectangle[] coinsRec;
  14.         Rectangle[] coinsCut;
  15.         Rectangle[,] board;
  16.         Rectangle[,] boardcut;
  17.         bool questionFlag;
  18.         Rectangle question,rect;
  19.         Color[] coinsColor;
  20.         MouseState ms;
  21.         KeyboardState ks;
  22.         Point pms;
  23.         int coinscount;
  24.         int coinWidth = 50, coinHeight = 50, coinWidthCut = 100, coinHeightCut = 100;
  25.  
  26.         public Game1()
  27.         {
  28.  
  29.             graphics = new GraphicsDeviceManager(this);
  30.             Content.RootDirectory = "Content";
  31.             this.IsMouseVisible = true;
  32.             graphics.PreferredBackBufferWidth = 800;
  33.             graphics.PreferredBackBufferHeight = 800;
  34.  
  35.         }
  36.  
  37.         protected override void Initialize()
  38.         {
  39.  
  40.             coinsRec = new Rectangle[8];
  41.             coinsCut = new Rectangle[8];
  42.             coinsColor = new Color[8];
  43.             board = new Rectangle[10,10];
  44.             boardcut = new Rectangle[10,10];
  45.             param2 = new Texture2D[10, 10];
  46.             question = new Rectangle(25,25,100,100);
  47.             rect = new Rectangle(0,0,100,100);
  48.             coinscount = 0;
  49.             questionFlag = false;
  50.  
  51.             for(int i = 0; i < 2; i++)
  52.             {
  53.                 for(int j = 0; j < 4; j++)
  54.                 {
  55.                     coinsRec[coinscount] = new Rectangle(0+25, coinscount*55+150, coinWidth, coinHeight);
  56.                     coinsCut[coinscount] = new Rectangle(j*100, i*100, coinWidthCut, coinHeightCut);
  57.                     coinsColor[coinscount] = Color.White;
  58.                     coinscount += 1;
  59.                 }
  60.             }
  61.  
  62.             for(int i = 0; i < 10; i++)
  63.             {
  64.                 for(int j = 0; j < 10; j++)
  65.                 {
  66.                     board[i, j] = new Rectangle(150+(50*i),150+(50*j),50,50);
  67.                     boardcut[i, j] = new Rectangle(0,0,100,100);
  68.                 }
  69.             }
  70.  
  71.             base.Initialize();
  72.         }
  73.  
  74.         protected override void LoadContent()
  75.         {
  76.             spriteBatch = new SpriteBatch(GraphicsDevice);
  77.             background = Content.Load<Texture2D>("background");
  78.             coins = Content.Load<Texture2D>("numbers");
  79.             unknown = Content.Load<Texture2D>("question");
  80.             param = unknown;
  81.  
  82.             for (int i = 0; i < 10; i++)
  83.             {
  84.                 for (int j = 0; j < 10; j++)
  85.                 {
  86.                     param2[i, j] = unknown;
  87.                 }
  88.             }
  89.         }
  90.  
  91.         protected override void UnloadContent()
  92.         {
  93.  
  94.         }
  95.  
  96.         protected override void Update(GameTime gameTime)
  97.         {
  98.             ms = Mouse.GetState();
  99.             pms = new Point(ms.X, ms.Y);
  100.            
  101.             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  102.                 this.Exit();
  103.  
  104.             if (question.Contains(pms))
  105.             {
  106.                 if(ms.LeftButton == ButtonState.Pressed)
  107.                 {
  108.                     questionFlag = true;
  109.                     param = unknown;
  110.                     rect = new Rectangle(0, 0, 100, 100);
  111.                 }
  112.             }
  113.  
  114.             for (int i = 0; i < 8; i++)
  115.             {
  116.                 if (coinsRec[i].Contains(pms))
  117.                 {
  118.                     coinsColor[i] = Color.Red;
  119.  
  120.                     if(ms.LeftButton == ButtonState.Pressed)
  121.                     {
  122.                         questionFlag = false;
  123.                         param = coins;
  124.                         rect = coinsCut[i];
  125.                     }
  126.                 }
  127.                 else coinsColor[i] = Color.White;
  128.             }
  129.  
  130.             for (int i = 0; i < 10; i++)
  131.             {
  132.                 for (int j = 0; j < 10; j++)
  133.                 {
  134.                     if (board[i, j].Contains(pms))
  135.                     {
  136.                         if(ms.LeftButton == ButtonState.Pressed)
  137.                         {
  138.                             if (questionFlag == true)
  139.                             {
  140.                                 param2[i, j] = unknown;
  141.                                 boardcut[i, j] = new Rectangle(0, 0, 100, 100);
  142.                             }
  143.                             else
  144.                             {
  145.                                 param2[i, j] = coins;
  146.                                 boardcut[i, j] = rect;
  147.                             }
  148.  
  149.                         }
  150.                     }
  151.                 }
  152.             }
  153.  
  154.             base.Update(gameTime);
  155.         }
  156.  
  157.         protected override void Draw(GameTime gameTime)
  158.         {
  159.             GraphicsDevice.Clear(Color.CornflowerBlue);
  160.             spriteBatch.Begin();
  161.             spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
  162.             spriteBatch.Draw(param, question, rect, Color.White);
  163.  
  164.             for(int i = 0; i < 8; i++)
  165.             {
  166.                 spriteBatch.Draw(coins, coinsRec[i], coinsCut[i], coinsColor[i]);
  167.             }
  168.  
  169.             for(int i = 0; i < 10; i++)
  170.             {
  171.                 for(int j = 0; j < 10; j++)
  172.                 {
  173.                     spriteBatch.Draw(param2[i, j], board[i,j], boardcut[i,j], Color.White);
  174.                 }
  175.             }
  176.  
  177.             spriteBatch.End();
  178.             base.Draw(gameTime);
  179.         }
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement