Hyluss

cards

Oct 16th, 2018
439
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Content;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using Microsoft.Xna.Framework.Input;
  5.  
  6. namespace Game2
  7. {
  8.     public class Card
  9.     {
  10.         Texture2D currentTexture;
  11.         Texture2D reversTexture;
  12.         Texture2D mainTexture;
  13.         Rectangle rect;
  14.         Rectangle chunk;
  15.         Rectangle? currentChunk=null;
  16.  
  17.  
  18.         int width = 100;
  19.         int height = 100;
  20.  
  21.         public int Type;
  22.  
  23.         bool clicked = false;
  24.         bool unlocked = false;
  25.  
  26.         public Rectangle Rect { get => rect; set => rect = value; }
  27.  
  28.         public Card(ContentManager content, int x, int y, int offsetX, int offsetY, int type)
  29.         {
  30.             Type = type;
  31.             reversTexture = content.Load<Texture2D>("question");
  32.             mainTexture = content.Load<Texture2D>("numbers");
  33.  
  34.             chunk = new Rectangle(y * width, x * height, width, height); //reverse x and y
  35.  
  36.  
  37.             rect = new Rectangle(offsetX, offsetY, width, height);
  38.  
  39.            
  40.  
  41.             currentTexture = reversTexture;
  42.         }
  43.  
  44.         public void Draw(SpriteBatch spriteBatch, int x, int y)
  45.         {
  46.             //spriteBatch.Draw(currentTexture, rect, Color.White);
  47.             spriteBatch.Draw(currentTexture, rect , currentChunk, Color.White);
  48.         }
  49.  
  50.         public void Update(Rectangle cursor)
  51.         {
  52.             if (rect.Intersects(cursor)) //mouse collision
  53.             {
  54.                 if (Mouse.GetState().LeftButton == ButtonState.Pressed && clicked==false && unlocked==false)
  55.                 {
  56.                     clicked = true;
  57.                     ++Game1.ClickedCounter;
  58.                     ++Game1.ShowedCards;                    
  59.  
  60.                     if (Game1.CurrentType == Type)
  61.                     {
  62.                         Unlock();
  63.                         Game1.pairs++;
  64.                     }
  65.                     else
  66.                     {
  67.                         if (Game1.ShowedCards == 2)
  68.                         {
  69.                             --Game1.ClickedCounter;
  70.                             Hide();
  71.                             Game1.SelectedCard.Hide();
  72.                         }
  73.                         else
  74.                         {
  75.                             Show();
  76.                         }
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.  
  82.         public void Hide()
  83.         {
  84.             Game1.ShowedCards = 0;
  85.             Game1.CurrentType = -1;            
  86.             currentChunk = null;
  87.             currentTexture = reversTexture;
  88.             clicked = false;
  89.         }
  90.  
  91.         public void Show()
  92.         {
  93.             Game1.SelectedCard = this;
  94.             Game1.CurrentType = Type;
  95.             currentChunk = chunk;
  96.             currentTexture = mainTexture;
  97.         }
  98.  
  99.         public void Unlock()
  100.         {
  101.             unlocked = true;
  102.             currentChunk = chunk;
  103.             currentTexture = mainTexture;
  104.             Game1.CurrentType = -1;
  105.             Game1.SelectedCard = null;
  106.             Game1.ShowedCards = 0;            
  107.  
  108.         }
  109.     }
  110. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment