using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Input; using System; /* * A class for representing the game world. */ class GameWorld { /* * enum for different game states (playing or game over) */ enum GameState { Playing, GameOver } /* * screen width and height */ int screenWidth, screenHeight; /* * random number generator */ Random random; /* * main game font */ SpriteFont font; /* * sprite for representing a single tetris block element */ Texture2D block, gridBlock, background; /* * the current game state */ GameState gameState; Vector2 midScreen, backgroundOrigin; /* * the main playing grid */ TetrisGrid grid; public GameWorld(int width, int height, ContentManager Content) { screenWidth = width; screenHeight = height; midScreen = new Vector2(width / 2, height / 2); random = new Random(); gameState = GameState.Playing; gridBlock = Content.Load("gridBlock"); block = Content.Load("block"); font = Content.Load("SpelFont"); grid = new TetrisGrid(gridBlock); background = Content.Load("placeholder"); backgroundOrigin = new Vector2(background.Width / 2, background.Height / 2); } public void Reset() { } public void HandleInput(GameTime gameTime, InputHelper inputHelper) { } public void Update(GameTime gameTime) { } public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { spriteBatch.Begin(); spriteBatch.Draw(background,midScreen - backgroundOrigin,Color.White); grid.Draw(gameTime, spriteBatch, gridBlock); spriteBatch.End(); } /* * utility method for drawing text on the screen */ public void DrawText(string text, Vector2 positie, SpriteBatch spriteBatch) { spriteBatch.DrawString(font, text, positie, Color.Blue); } public Random Random { get { return random; } } class GameObject { protected GameObject parent = null; public virtual Vector2 GlobalPosition { get { if (parent != null) return parent.GlobalPosition + this.GlobalPosition; else return this.GlobalPosition; } } } }