title: Repeating a sequence of lines in Java
body: <p>I can't think how to word what I want to do, but hopefully this will explain.</p>
  
  <p>My friend is making a text-based adventure game, and I was working on separating a part of the game out for ease of management.</p>
  
  <p>In the game, the stats of the player, the player inventory and many more get sent to another class. </p>
  
  <pre><code>    static Char player;
      static battle bat;
  
      public static void directchoice(Char p, battle b) {
      player = p;
      bat = b;
      String[] rightLeft = {"Left", "Right"};
      int direct = JOptionPane.showOptionDialog(null, "Left or Right?", "Option", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, rightLeft, rightLeft[0]);
      if(direct == 0){
          Maze.makeChoice(player, bat);
      }
      if(direct == 1){
          Maze.DoorChoice(player, bat);   
      }
  }
  </code></pre>
  
  <p>As can be seen here, at the beginning of the class, "player" and "bat" are a Character and a Battle. These are imported from the previous section of the game.</p>
  
  <p>The "Char p, battle b" seen in the subroutine brackets, along with the "player = p; bat = b;" inside the sub have to be repeated for every subroutine. </p>
  
  <p>So for example, here is another subroutine within that class: </p>
  
  <pre><code>    public static void DoorChoice(Char p, battle b) {   
      player = p;
      bat = b;
      String[] others = {"Go through door", "Don't go through"};
  int checkers = JOptionPane.showOptionDialog(null, "Go through door or not?", "Option", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, others, others[0]);
  </code></pre>
  
  <p>There are a bunch of others, such as player inventory, monster, and more that also need to be repeated. What I'm trying to do is create a way of repeating those lines of code automatically for each subroutine, as opposed to having to either type them all out or copy and paste. </p>
  
  <p>I tried what I could think of, but being still relatively noobish to java, I don't know what to do to repeat those lines.</p>
  
  <p>I hope this makes sense, and I'm sorry if it doesn't :(</p>