/// <summary> /// Takes a turn, placing an O in the best square /// </summary> /// <param name="board">the board</param> public void TakeTurn(Board board) { // place O in a random open square BoardSquare square = board.GetSquare(rand.Next(3), rand.Next(3)); while (!square.Empty) { square = board.GetSquare(rand.Next(3), rand.Next(3)); } square.Contents = SquareContents.O; }
/// <summary> /// Creates a new board centered at the given location /// </summary> /// <param name="contentManager">the content manager to use</param> /// <param name="x">x</param> /// <param name="y">y</param> public Board(ContentManager contentManager, int x, int y) { // dynamically get board square dimensions int sideLength = BoardSquare.GetSideLength(contentManager); // STUDENTS: CALCULATE THE X AND Y OF THE TOP LEFT CORNER OF THE BOARD // REPLACE THE 0s BELOW WITH THE APPROPRIATE EQUATIONS int leftX = 3 * sideLength; int topY = (3 * sideLength) - 100; // build board squares and add to array for (int row = 0; row < board.GetLength(0); row++) { for (int column = 0; column < board.GetLength(1); column++) { board[row, column] = new BoardSquare(contentManager, leftX + (column * sideLength) + sideLength / 2, topY + (row * sideLength) + sideLength / 2); } } }
/// <summary> /// Creates a new board centered at the given location /// </summary> /// <param name="contentManager">the content manager to use</param> /// <param name="x">x</param> /// <param name="y">y</param> public Board(ContentManager contentManager, int x, int y) { // dynamically get board square dimensions int sideLength = BoardSquare.GetSideLength(contentManager); // STUDENTS: CALCULATE THE X AND Y OF THE TOP LEFT CORNER OF THE BOARD // REPLACE THE 0s BELOW WITH THE APPROPRIATE EQUATIONS int leftX = x - sideLength; int topY = y - sideLength; // build board squares and add to array for (int row = 0; row < board.GetLength(0); row++) { for (int column = 0; column < board.GetLength(1); column++) { board[row, column] = new BoardSquare(contentManager, leftX + (column * sideLength) + sideLength / 2, topY + (row * sideLength) + sideLength / 2); } } }
/// <summary> /// Gets the side length for a board square /// </summary> /// <param name="contentManager">the content manager</param> /// <returns>the side length</returns> public static int GetSideLength(ContentManager contentManager) { BoardSquare tempSquare = new BoardSquare(contentManager, 0, 0); return(tempSquare.drawRectangle.Width); }
/// <summary> /// Gets the side length for a board square /// </summary> /// <param name="contentManager">the content manager</param> /// <returns>the side length</returns> public static int GetSideLength(ContentManager contentManager) { BoardSquare tempSquare = new BoardSquare(contentManager, 0, 0); return tempSquare.drawRectangle.Width; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //creates the board, its squares and the quitbutton board = new Board(Content, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); bSquare = new BoardSquare(Content, 0, 0); qButton = new QuitButton(Content, WINDOW_WIDTH / 2, WINDOW_HEIGHT - 50, GameState.Quit); }