   import java.util.Scanner;
/** 
 *   This class is designed to play a game of PseudoWar
 *
 *
 *   @author:Elizabeth Adams
 *   @version 1 
 */

    public class PseudoWar_V1
   {
      private int score1, score2;
      private String player1, player2;
      private int  numberRounds;
      private int roundNumber;
   
   /** This is the constructor for pseudoWar
    *  It sets the class attributes
    * 
    *   @param name1  user's choice of name for first player
    *   @param name2  user's choice of name for second player
    *   @param numRounds  number of rounds user want the game to contain
    */
       public PseudoWar_V1 (String name1, String name2, int numRounds)
      {
       		 // sets the name of the first player
         this.player1 = name1;
      	 
      		 // sets the name of the second player
         this.player2 = name2;  
      
      	    // initialize players' scores to 0
         this.score1 = 0;
         this.score2 = 0;
      
            // sets the number of rounds
         this.numberRounds = numRounds;
      	 
      	  // initialize round number 
         this.roundNumber = 0;
      	 
      // debug     System.out.println (" attributes initialized ");	 
      }	// end constructor 
   	
   	   	
   /**
    *   This method returns the heading for the output
    *   
    *     
   */
       public void  startGame ()
      {
         System.out.println ("\t\t " + player1 + "\t\t " + player2 + "\t\t  Winner ");
         System.out.println ("-----------------------------------------------------");
       
      // debug    System.out.println (" about to call playGame ");
         playGame();
      } // end startGame
   
   /**
    *    This method runs the round and prints the
    *    output of each round and the echo of users
    *    input
    *
    *
    */
       public void playGame ()
      {
      /* debug      Scanner mykey;
      	     mykey = new Scanner (System.in);
      	     String temp;
      */      	
         String roundData;
      	
         for (int i = 1; i <= this.numberRounds; i++)
         {
         /* debug     System.out.println (" in playGame about to call runRound " + 
              " for the " + i + " th time \n i is " + i + " and this.numberRounds is " +
         	  this.numberRounds );
         	  System.out.println (" enter " + i + " and hit return ");
         	  temp = mykey.nextLine();  
         */
			   roundData = runRound ();
            System.out.println (roundData);
         }
      } // end playGame
    
    
    /** 
     *
     *   This method generates a random number in the
     *   range 1 to 52 and returns it.
     *
     *   @return random number in range 1 to 52
     *
     */
       public int generateNumber ()
      {
         double temp;
         int value;
      	 
      // debug   System.out.println (" in generateNumber ");
         temp = Math.random();
         //System.out.println (temp);
         temp = temp * 52 + 1;
         //System.out.println (temp);
         value = (int) temp;
      // debug    System.out.println (value);
         return value;
      }  // end generateNumber
    
    
     /** 
      *  This method receives two random numbers, the
   	*  first belonging to player 1, the second to player 2
   	*  compares the numbers 
   	*  
   	*  @param num1  first player's number
   	*  @param num2  second player's number
   	*
   	*  @return  1  if player1's number is higher
   	*  		   2 if player2's number is higher
   	*           0 if the numbers of the two players are the same
   	*/
       public int determineWinner ( int num1, int num2)
      {
         int returnValue;
      	
      //debug   System.out.println (" in determineWinner ");
         
         if (num1 > num2)
            returnValue = 1;
         else if (num2 > num1)
            returnValue = 2;
         else
            returnValue = 0;
         return returnValue;
      
      } // end determine winner	 
     
     /**  
      *   This method calls generateNumber and determineWinner
   	*   an updates the player's scores and returns a String
   	*   with the appropriate round String
   	*
   	*   @return result of the round to be put in output table
   	*/
       public  String runRound ()
      {
      // debug   Scanner myrun;
         int num1, num2, winner;
         String resultString, winnerName;
      // debig   String temp; 
      
      //  debug   myrun = new Scanner (System.in);
      
         winnerName = "\t\t\t\t\t\t\t ";
      //  debug   System.out.println (" in runRound ");
      	 
      	 // call generate number for player1
         num1 = generateNumber();
      	 // call generate number for player2
         num2 = generateNumber();
          // call determineWinner  
         this.roundNumber = this.roundNumber + 1;
      //  debug 	System.out.println (this.roundNumber);
      //  debug   temp = myrun.nextLine(); 
         resultString = this.roundNumber + "\t\t " + num1 + "\t\t " + num2;			 			 
      
         winner = determineWinner (num1, num2);
         if (winner == 1)
         {
            winnerName = this.player1;
            this.score1 = this.score1 + 1;
         }	
         else if (winner == 2)
         {
            winnerName = this.player2;
            this.score2 = this.score2 + 1;
         }	 
      /* debug         else
            System.out.println (" result was a tie ");
      */     		 
         resultString = resultString + "\t\t " + winnerName;  
      	   
         return resultString;
      
      } // end runRound
   	
   	/**
   	 *
   	 *  this method returns a string with the final output
   	 *  including the final game results
   	 *
   	 *  @return final results 
   	 */
       public  String  getFinalResult ()
      {
         String finalResult;
      	
         finalResult = this.player1 + " won " + this.score1 + " rounds\n" +
                       this.player2 + " won " + this.score2 + " rounds\n" +
            			  "The game has ended ";
      		 
         return finalResult;
       
      } //end getFinalResult
       
   } // end PseudoWar