public void toggleMuted() {
   if (!muted) {
     muted = true;
     stopBackgroundMusic();
   } else {
     muted = false;
     startBackgroundMusic();
   }
 }
  public void handleAction(int id) {
    if (id == TitleMenu.RETURN_TO_TITLESCREEN) {
      clearMenus();
      TitleMenu menu = new TitleMenu(GAME_WIDTH, GAME_HEIGHT);
      addMenu(menu);

    } else if (id == TitleMenu.START_GAME_ID) {
      clearMenus();
      isMultiplayer = false;
      chat.clear();

      localId = 0;
      localTeam = Team.Team1;
      synchronizer = new TurnSynchronizer(this, null, 0, 1);
      synchronizer.setStarted(true);

      createLevel(TitleMenu.level, TitleMenu.defaultGameMode);
      soundPlayer.stopBackgroundMusic();
    } else if (id == TitleMenu.SELECT_LEVEL_ID) {
      addMenu(new LevelSelect(false, localTeam));
    } else if (id == TitleMenu.SELECT_HOST_LEVEL_ID) {
      addMenu(new LevelSelect(true, localTeam));
    } else if (id == TitleMenu.UPDATE_LEVELS) {
      GuiMenu menu = menuStack.pop();
      if (menu instanceof LevelSelect) {
        addMenu(new LevelSelect(((LevelSelect) menu).bHosting, localTeam));
      } else {
        addMenu(new LevelSelect(false, localTeam));
      }
    } else if (id == TitleMenu.HOST_GAME_ID) {
      addMenu(new HostingWaitMenu());
      isMultiplayer = true;
      isServer = true;
      chat.clear();
      try {
        if (isServer) {
          localId = 0;
          localTeam = Team.Team1;
          serverSocket = new ServerSocket(3000);
          serverSocket.setSoTimeout(1000);

          hostThread =
              new Thread() {

                @Override
                public void run() {
                  boolean fail = true;
                  try {
                    while (!isInterrupted()) {
                      Socket socket = null;
                      try {
                        socket = serverSocket.accept();
                      } catch (SocketTimeoutException e) {

                      }
                      if (socket == null) {
                        System.out.println("Waiting for player to connect");
                        continue;
                      }
                      fail = false;

                      packetLink = new NetworkPacketLink(socket);

                      createServerState = 1;
                      break;
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  if (fail) {
                    try {
                      serverSocket.close();
                    } catch (IOException e) {
                    }
                  }
                };
              };
          hostThread.start();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (id == TitleMenu.JOIN_GAME_ID) {
      addMenu(new JoinGameMenu());
    } else if (id == TitleMenu.CANCEL_JOIN_ID) {
      popMenu();
      if (hostThread != null) {
        hostThread.interrupt();
        hostThread = null;
      }
    } else if (id == TitleMenu.PERFORM_JOIN_ID) {
      menuStack.clear();
      isMultiplayer = true;
      isServer = false;
      chat.clear();

      try {
        localId = 1;
        localTeam = Team.Team2;
        packetLink = new ClientSidePacketLink(TitleMenu.ip, 3000);
        synchronizer = new TurnSynchronizer(this, packetLink, localId, 2);
        packetLink.setPacketListener(this);
      } catch (Exception e) {
        e.printStackTrace();
        // System.exit(1);
        addMenu(new TitleMenu(GAME_WIDTH, GAME_HEIGHT));
      }
    } else if (id == TitleMenu.HOW_TO_PLAY) {
      addMenu(new HowToPlayMenu());
    } else if (id == TitleMenu.OPTIONS_ID) {
      addMenu(new OptionsMenu());
    } else if (id == TitleMenu.SELECT_DIFFICULTY_ID) {
      addMenu(new DifficultySelect(false));
    } else if (id == TitleMenu.SELECT_DIFFICULTY_HOSTING_ID) {
      addMenu(new DifficultySelect(true));
    } else if (id == TitleMenu.KEY_BINDINGS_ID) {
      addMenu(new KeyBindingsMenu(keys, inputHandler));
    } else if (id == TitleMenu.EXIT_GAME_ID) {
      System.exit(0);
    } else if (id == TitleMenu.RETURN_ID) {
      synchronizer.addCommand(new PauseCommand(false));
      keys.tick();
    } else if (id == TitleMenu.BACK_ID) {
      popMenu();
    }
  }