/**
 * A text implementation of the JoggleFE interface.
 *
 * @version $Id: JoggleFEText.java,v 1.3 1996/11/22 01:51:31 gadde Exp $
 * @author Syam Gadde (gadde@cs.duke.edu)
 * @see joggle.client.JoggleFE
 * 
 * $Log: JoggleFEText.java,v $
 * Revision 1.3  1996/11/22 01:51:31  gadde
 * Changed package name
 *
 * Revision 1.2  1996/11/20 15:45:16  gadde
 * removed all references to joggle.JoggleAccessLayer
 *
 * Revision 1.1  1996/11/20 00:14:30  gadde
 * Initial revision
 *
 */

package jogglesyam;

import joggle.client.*;
import java.lang.*;
import java.util.*;
import java.io.*;

public class JoggleFEText extends Thread implements JoggleFE
{
  private boolean myDone = false;
  private Vector mySolutions;
  private int myClock;

  public void setup(String [] players) {
    System.out.println("The players are:");
    int i;
    for (i=0; i<players.length; i++) {
      System.out.println(players[i]);
    }
  }

  public void startGame(char [] [] board) {
    int i;
    int j;
    for (i=0; i<board.length; i++) {
      for (j=0; j<board[i].length; j++) {
	System.out.print(board[i][j]);
	System.out.print(' ');
      }
      System.out.println();
    }

    myClock = 180; // seconds

    mySolutions = new Vector();
    while (! myDone) {
      try {
	if (System.in.available() > 0) {
	  mySolutions.addElement((new DataInputStream(System.in)).readLine());
	}
	yield();
      }
      catch (Exception e) {

      }
    }
    System.out.println("Game over, waiting for results...");
  }

  public String [] stopGame() {
    String [] returnarray = new String [mySolutions.size()];
    mySolutions.copyInto(returnarray);
    myDone = true;
    return returnarray;
  }

  public void showResults(String winner,
			  String [] common,
			  String [] [] playersWords,
			  String [] missed) {
    System.out.println("The winner is " + winner);
    System.out.println("Here are the words more than one player got:");
    for (int i=0; i<common.length; i++) {
      System.out.println(" " + common[i]);
    }
    for (int j=0; j<playersWords.length; j++) {
      System.out.println("Here are player #" + j + "'s words:");
      for (int i=0; i<playersWords[j].length; i++) {
	System.out.println(" " + playersWords[j][i]);
      }
    }
    System.out.println("Here are words that no one got:");
    for (int i=0; i<missed.length; i++) {
      System.out.println(" " + missed[i]);
    }
  }

  public void showMessage(String msg) {
    System.out.println(msg);
  }

  public void tick() {
    myClock--;
    if (myClock % 10 == 0) {
      System.out.println(myClock + " seconds left.");
    }
  }
}

