using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; /* * a class for representing the Tetris playing grid */ class TetrisGrid { static bool[,] occupied; /*Hmmm... de classe heet al TetrisGrid en heeft al een methode TetrisGrid, neem een andere naam * anders kan de compiler ze niet meer uit elkaar houen(en ik ook niet trouwens)*/ public static Vector2[,] gridPosition; //Snelle fix om er voor te zorgen dat we 'm ook kunnen gebruiken in de draw method public TetrisGrid(Texture2D gridBlock) //Twee constructor methods kan alleen bij verschillende hoeveelheden parameters, maar dat willen we niet, we willen beiden. { Vector2[,] gridPosition = new Vector2[Width, Height]; //13 x 24 array, elke cel bevat Vector2 voor positie in schermcoördinaten Vector2 screenLocation = new Vector2(0,0); //positie van grid in scherm, linkerbovenhoek als oorsprong for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { gridPosition[y, x] = new Vector2(x * gridBlock.Width, y * gridBlock.Height) + screenLocation; } } /* * 13 x 24 grid * 13 x 20 playing field * first three rows 'invisible' * bottom row 'invisible' and permanently occupied */ /*we zitten nog in TetrisGrid, dus die hoef je niet aan te roepen als je width en height wil * gebruiken, tevens moet je die int voor x en y er telkens bij gebruikt omdat je op 't niveau van de for zit*/ occupied = new bool[Width, Height]; for (int x = 0; x < Width; x++) { for (int y = 3; y < Height - 1; y++) { occupied[y, x] = false; } } for (int x = 0; x < Width; x++) { for (int y = Height - 1; y < Height; y++) { occupied[y, x] = true; } } } public static Vector2 screenPosition //position of the upper left corner of the grid on the screen { get { return screenPosition; } set { screenPosition = value; } } public static int Width // width in terms of grid elements { get { return 13; } } public static int Height //height in terms of grid elements { get { return 24; } } public void Draw(GameTime gametime, SpriteBatch s, Texture2D gridBlock) /* draws the grid on the screen*/ { for (int x = 0; x < Width; x++) { for (int y = 3; y < Height - 1; y++) { s.Draw(gridBlock, gridPosition[y, x], Color.White); } } } public static Vector2[,] GridPosition { get { return gridPosition; } } public static bool[,] Occupied { get { return occupied; } } }