title: How can I implement a range of player turns? I.E 3-10 players in Java
body: <p>I am creating a tic tac toe game but in this case, it is more than two players. I am completely unsure how to go about this and had many iterations. It is done via JButtons gridlayout. For normal tictactoe, it works just fine:</p>
  <pre><code>buttons[i].addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      for(int i=0;i&lt;9;i++) {
                          if(e.getSource()==buttons[i]) {
                              if(pTurn) {
                                  if(buttons[i].getText()==&quot;&quot;) {
                                      buttons[i].setForeground(new Color(255,0,0));
                                      buttons[i].setText(&quot;X&quot;);
                                      pTurn=false;
                                      txt.setText(&quot;O turn&quot;);
                                      checkCondition();
                                  }
                              }
                              else {
                                  if(buttons[i].getText()==&quot;&quot;) {
                                      buttons[i].setForeground(new Color(0,0,255));
                                      buttons[i].setText(&quot;O&quot;);
                                      pTurn=true;
                                      txt.setText(&quot;X turn&quot;);
                                      checkCondition();
                                  }
                              }
                          }           
                      }
                  }
              });
  </code></pre>
  <p>However, my implementation of 3+ players is not working. My logic is skewed but I am unsure where.</p>
  <pre><code>           buttons[i].addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      for(int i=0;i&lt;size;i++) {
                          if(e.getSource()==buttons[i]) {
                              for (int k = 0; k &lt; col_row; k++ ) {
                                  for (int j = k+1; j &lt; col_row; j++) {
                                      if (players[k]) {
                                          if(buttons[i].getText()==&quot;&quot;) {
                                              buttons[i].setForeground(new Color(0,0,255));
                                              buttons[i].setText(pIcon[k]);
                                              players[k]=false;
                                              txt.setText(pIcon[j] + &quot; turn&quot;);
                                              checkCondition();
                                          }
                                      }
                                      else {
                                          if(buttons[i].getText()==&quot;&quot;) {
                                              buttons[i].setForeground(new Color(0,0,255));
                                              buttons[i].setText(pIcon[j]);
                                              players[k]=true;
                                              txt.setText(pIcon[j+1] + &quot; turn&quot;);
                                              checkCondition();
                                          }
                                      }
                                  }
                                      
  
  
                              }
  
                          }           
                      }
                  }
              });
  </code></pre>
  <p>In this case, col_row is just the number of players. Players[] is an array of boolean players. My logic is that its checked to see if they have went but it doesn't work really.
  pIcon[] is an array of player characters (X,O,A,B,C...). I am not really sure how to fix this.</p>
  <p><a href="https://i.stack.imgur.com/SINYS.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SINYS.gif" alt="enter image description here" /></a></p>