/** * Menu Constructor * @param screenWidth Width of the screen * @param screenHeight Height of the screen * @param spriteBatch SpriteBatch * @param gameContent GameContent */ public Menu(int screenWidth, int screenHeight, SpriteBatch spriteBatch, GameContent gameContent) { this.screenWidth = screenWidth; this.screenHeight = screenHeight; this.spriteBatch = spriteBatch; this.gameContent = gameContent; easy = gameContent.menuText.MeasureString("Easy"); medium = gameContent.menuText.MeasureString("Medium"); hard = gameContent.menuText.MeasureString("Hard"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); gameContent = new GameContent(Content); NewGame(); menu = new Menu(screenWidth, screenHeight, spriteBatch, gameContent); loseSpace = gameContent.text.MeasureString("You Lose"); winSpace = gameContent.text.MeasureString("You Win"); // TODO: use this.Content to load your game content here }
/** * Tile Constructor * @param x X position * @param y Y position * @param spriteBatch SpriteBatch * @param gameContent GameContent */ public Tile(float x, float y, SpriteBatch spriteBatch, GameContent gameContent) { X = x; Y = y; SideLength = gameContent.imgBlankTile.Width * 3; hasMine = false; hasFlag = false; hasQuestionMark = false; Visible = false; firstMine = false; this.spriteBatch = spriteBatch; this.gameContent = gameContent; }
/** * Board Constructor * @param rows Number of rows * @param columns Number of columns * @param distanceFromTop Number of pixels from the top of the screen the board is being drawn * @param numMines Total number of mines on the board * @param spriteBatch SpriteBatch * @param gameContent GameContent */ public Board(int rows, int columns, int distanceFromTop, int numMines, SpriteBatch spriteBatch, GameContent gameContent) { Rows = rows; Columns = columns; DistanceFromTop = distanceFromTop; SideLength = gameContent.imgBlankTile.Width * 3; NumMines = numMines; Tiles = new Tile[Rows, Columns]; for (int i = 0; i < Rows; i++) { for (int j = 0; j < Columns; j++) { Tiles[i, j] = new Tile(i * SideLength, j * SideLength + DistanceFromTop, spriteBatch, gameContent); } } Random random = new Random(); int x; int y; while (numMines > 0) { x = random.Next(Rows); y = random.Next(Columns); if (!Tiles[x, y].hasMine) { Tiles[x, y].hasMine = true; numMines--; } } for (int i = 0; i < Rows; i++) { for (int j = 0; j < Columns; j++) { Tiles[i, j].numNeighbors = CheckNeighbors(i, j); } } }