@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main_game);

    allDoneLevels = new ArrayList<>();
    AssetManager am = getResources().getAssets();

    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);
    final HowdyShadeView howdyShadeView = (HowdyShadeView) this.findViewById(R.id.howdyShadeView);
    final GlowingBoard glowingBoard = (GlowingBoard) this.findViewById(R.id.glowingBoard);
    final HowdyView howdyView = (HowdyView) this.findViewById(R.id.howdyView);
    this.game = new Game();

    boardView.setHowdyShadeView(howdyShadeView);
    boardView.setGlowingBoard(glowingBoard);
    boardView.setHowdyView(howdyView);
    boardView.setOnTouchListener(new BoardGameTouchListener(this));
  }
  public void loseGame() {
    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);

    game.reInitGame();

    boardView.setGame(game);
    boardView.invalidate();
  }
  /** Implement the run() method for the thread */
  public void run() {
    try {
      // Create data input and output streams
      DataInputStream fromPlayer1 = new DataInputStream(player1.getInputStream());
      DataOutputStream toPlayer1 = new DataOutputStream(player1.getOutputStream());
      DataInputStream fromPlayer2 = new DataInputStream(player2.getInputStream());
      DataOutputStream toPlayer2 = new DataOutputStream(player2.getOutputStream());

      // Write anything to notify player 1 to start
      // This is just to let player 1 know to start
      toPlayer1.writeInt(1);

      // Continuously serve the players and determine and report
      // the game status to the players
      while (true) {
        // Receive a move from player 1
        int row = fromPlayer1.readInt();
        int column = fromPlayer1.readInt();
        int yCoordinate = game.insert("[X]", column);

        // Check if Player 1 wins
        if (game.isWinner(column, yCoordinate, "[X]")) { // if a  winner is found
          toPlayer1.writeInt(PLAYER1_WON);
          toPlayer2.writeInt(PLAYER1_WON);
          sendMove(toPlayer2, row, column);
          break; // Break the loop
        } else {
          toPlayer2.writeInt(CONTINUE);
          sendMove(toPlayer2, row, column);
        }
        // Receive a move from Player 2
        row = fromPlayer2.readInt();
        column = fromPlayer2.readInt();
        yCoordinate = game.insert("[O]", column);
        // Check if Player 2 wins
        if (game.isWinner(column, yCoordinate, "[O]")) { // if a  winner is found
          toPlayer1.writeInt(PLAYER2_WON);
          toPlayer2.writeInt(PLAYER2_WON);
          sendMove(toPlayer1, row, column);
          break; // Break the loop
        } else if (game.boardIsFull()) { // Check if all cells are filled
          toPlayer1.writeInt(DRAW);
          toPlayer2.writeInt(DRAW);
          sendMove(toPlayer1, row, column);
          break;
        } else {
          // Notify player 2 to take the turn
          toPlayer1.writeInt(CONTINUE);
          // Send player 1's selected row and column to player 2
          sendMove(toPlayer1, row, column);
        }
      }
    } catch (IOException ex) {
      System.err.println(ex);
    }
  }
  public void nextLevel() {
    boolean loaded = false;
    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);
    this.level++;

    AssetManager am = getResources().getAssets();

    try {
      List<String> allTutoLevels =
          new LinkedList<String>(Arrays.asList(am.list("levels/tutorial")));

      // if(addMsg){
      //    allTutoLevels.addAll(Arrays.asList(am.list("msg")));
      // }

      Log.d(TAG, allTutoLevels.toString());

      for (String name : allTutoLevels) {
        if (name.startsWith(this.level + ".")) {
          BufferedReader br =
              new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name)));
          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
          loaded = true;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (!loaded) {
      Random r = new Random();

      List<String> allLevels = new ArrayList<>();

      try {
        allLevels = Arrays.asList(am.list("levels"));
      } catch (IOException e) {
      }

      if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) {
        try {
          int nLevel;
          do {
            nLevel = r.nextInt(allLevels.size());
          } while (allDoneLevels.contains(allLevels.get(nLevel)));

          String name = allLevels.get(nLevel);
          BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name)));

          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          allDoneLevels.add(name);

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        } catch (IOException e) {
          this.game.initGame(
              level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        }
      } else {
        this.game.initGame(
            level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
      }
    }

    // am.close();

    boardView.setGame(this.game);
    boardView.invalidate();
    boardView.getHowdyShadeView().invalidate();

    Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show();

    Log.i(
        TAG,
        "Max tiles : "
            + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60));
  }