title: How to make an ongoing game?
body: <p>I'm working on a java Memory game using 2d arrays. There is a 4x4 grid of numbers. Each turn the player picks two numbers and those two array cells are turned over to reveal back. If the colors don't match the cards turn over and the player must go again. So far I've created mechanics of the game. The array is there, the player can turn over the cells, but the code stops after the first try. I need to change it so the program keeps running until the player has successfully matched all cards. Furthermore, if the player matches two cards, those cards must not turn back around. I have two classes: Card and MemoryGame. Here they are:</p>
  
  <pre><code>public class Card{
      boolean showing; // true or false, indicates that the card is flipped
      String back;     //hidden symbol on the back of the card
      int front;       //integer on the front of the card
  
      public Card(String theBack, int theFront)
      {
          showing = false; 
          back = theBack;
          front = theFront;
      }
  
      //
      public void showCard()
      {
          if(showing)
              System.out.print(String.format(back)); //if showing is true, it shows the hidden symbol
          else
              System.out.print(String.format("["+front+"]"));
      }
  
      public void setShowingStatus()
      {
          if(showing)
              showing = false;
          else
              showing = true;
      }
  }
  </code></pre>
  
  <p>And this is the memory game class. The playGame() method and choosePairofCards() methods are the one I need help completing.</p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  
  public class MemoryGame{
      //Declaration
      private Card[][] board;
      private String[] words = {"Blue", "Blue","Red","Red","Green","Green","Yellow","Yellow","Pink","Pink","Black","Black","Brown", "Brown","White","White"};
      private Random r; 
      private Scanner reader; 
  
      MemoryGame(){
          r = new Random();
          reader = new Scanner(System.in);
          board = new Card[4][4]; //Creates the 4x4 array that can hold Card objects
          shuffle();
          setCells();
          printCells();
          playGame();
      }
  
      public void shuffle(){
          // Has a loop that goes throught the array of words and chooses a random position and swaps the words
          // For loop position to random position
          // Words array is shuffled
          for(int a=0; a&lt;words.length; a++){
              int pos = r.nextInt(words.length);
              String temp = words[a];
              words[a] = words[pos];
              words[pos] = temp;
          }
      }
  
      public void setCells(){
          //Designates the words
          int a = 0; 
          for (int row = 0; row&lt;board.length; row++){
              for (int col = 0; col&lt;board[0].length; col++){
                  {
                      board[row][col] = new Card(words[a], a); //Creates new Card that pulls words from Shuffled array
                      a++;
                  }
              }
          }
      }
  
      public void printCells(){
          Card aCard; //Local variable = aCard, which is a type Card
          for (int row = 0; row&lt;board.length; row++){
              for(int col = 0; col&lt;board[0].length; col++){
                  aCard = board[row][col];
                  aCard.showCard();
              }
              System.out.println();
          }
      }
  
      public void playGame(){
          //INCOMPLETE
          choosePairOfCards();
      }
  
      public void choosePairOfCards(){
  
          int cardChoice, row1, col1, row2, col2;
          System.out.println();
          System.out.println("Enter the number on the card.");
          System.out.println("First Card Choice? &gt;");
          cardChoice = getInputAsInt();
          row1 = cardChoice / 4;
          col1 = cardChoice % 4;
          board[row1][col1].setShowingStatus();
  
          System.out.print("Second Card Choice? &gt;");
          cardChoice = getInputAsInt();
          row2 = cardChoice / 4;
          col2 = cardChoice % 4;
          board[row2][col2].setShowingStatus();
  
          System.out.print('\u000C'); //clears the screen
  
          printCells(); // INCOMPLETE
          // check to see if the "cards" match
          //if they don't then turn print game with cards turned around
      }
  
      public int getInputAsInt(){
          String temp = reader.nextLine();
          return Integer.parseInt(temp); //Returns a String containing integer, into an int value
      }
  }
  </code></pre>