Hyluss icon

board

Hyluss | PRO | 10/16/18 11:34:51 PM UTC | 0 ⭐ | 380 👁️ | Never ⏰ | []
C# |

2.66 KB

|

None

|

0 👍

/

0 👎

using Microsoft.Xna.Framework.Content;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using System.Linq;
using Microsoft.Xna.Framework;
 
namespace Game2
{
    public class Board
    {
         readonly int rows = 4;
         readonly int columns = 6;
 
        int _offsetX = 30;
        int _offsetY = 30;
 
 
        int width = 100;
        int height = 100;
 
        //   Card[,] Cards;
        List<Card> Deck;
 
        static readonly int spriteRows = 3;
        static readonly int spriteColumns = 4;
        static readonly int blankSpace = 10;
 
        public List<Card> Deck1 { get => Deck; set => Deck = value; }
 
        public Board(ContentManager content)
        {
            Deck = new List<Card>();
            //   Cards = new Card[rows, columns];            
 
            int type = 0;
 
            for (int x = 0; x < spriteRows; x++)
            {
                for (int y = 0; y < spriteColumns; y++)
                {
                    var offsetX = _offsetX + blankSpace * x + x * width;
                    var offsetY = _offsetY + blankSpace * y + y * height;
 
                    Deck.Add(new Card(content, x, y,offsetX,offsetY, type));
 
                    Deck.Add(new Card(content, x, y, offsetX + width*spriteColumns - _offsetX - _offsetX, offsetY, type)); // xd
                    type++;
                }
            }
 
            Shuffle();
        }
 
        void Shuffle()
        {
            var tmpList = new List<Card>(Deck);
            Random random = new Random();
 
            int i = 0;
            while(Deck.Count != 0)
            { 
                int randomNext = random.Next(0, Deck.Count);
                int randomNext2 = random.Next(0, Deck.Count);
                var rect = Deck[randomNext].Rect;
               // var rect = new Rectangle(Deck[randomNext].Rect.X, Deck[randomNext].Rect.Y, width, height);
                tmpList[randomNext2].Rect = rect;
                Deck.RemoveAt(randomNext);
              //  ++i;
            }
            Deck = new List<Card>(tmpList);
 
 
        }
 
 
        internal void Draw(SpriteBatch spriteBatch)
        {
            int index = 0;
        
            for (int x = 0; x < rows; x++)
            {
                for (int y = 0; y < columns; y++)
                {
                    Deck[index].Draw(spriteBatch, x, y);
                    ++index;
                }
            }
        }
 
 
        public void Update(Rectangle cursor)
        {
            foreach (var item in Deck)
            {
                item.Update(cursor);
            }
        }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎