private void placeMines()
    {
        if (hasPlacedMines == false)
        {
            Random random = new Random();
            int minesPlaced = 0;
            while (minesPlaced < mineCount) {
                // Get two random coordinates and set the square as a mine, unless it is a mine already.
                int randX = Integer.remainderUnsigned(random.nextInt(), gridSize), randY = Integer.remainderUnsigned(random.nextInt(), gridSize);
                Square square = getSquare(randX, randY);
                if (square.isMine() == false) {
                    square.setMine(true);
                    minesPlaced++;
                }
                // Else if the square is already a mine, continue looping without adding one to the count.
            }
            hasPlacedMines = true;
        }
    }