// Programmierpraktikum WS99/00, LMU Informatik, LFE Theoretische Informatik
package catan;

import java.rmi.*;
import java.rmi.server.*; 

public class CatanView extends UnicastRemoteObject
                           implements RemoteCatanView {
    static final boolean DEBUG=false;
    int zustand;
    public CatanView() throws RemoteException {
	super();
    }
    public CatanView(RemoteCatan insel) throws RemoteException {
	super();
	insel.addView(this);
	if (DEBUG) System.err.println("CatanView-Objekt erfolgreich erzeugt.");
    }
    public void modiWert(int n) {
	zustand+=n;
	if (DEBUG) System.err.println("Wert um "+n+" geändert.");
    }
    public static void main(String[] args) {
	RemoteCatan insel=null;
	if (args.length==0) {
	    System.err.println("usage: java-1.2 CatanView host");
	    System.exit(-1);
	}
	String host=args[0];
	CatanView catanView=null;
	try {
	    insel=(RemoteCatan)Naming.lookup("rmi://"+host+"/Catan");
	} catch (Exception e){
	    System.err.println("CatanView exception: " + e.getMessage());
            e.printStackTrace();
        }
	try {
	    catanView=new CatanView(insel);
	} catch (Exception e){
	    System.err.println("CatanView exception: " + e.getMessage());
            e.printStackTrace();
        }
	try {
	    while (true){
		System.in.read();
		insel.update(catanView);
		if (DEBUG) {
		    System.err.println("Nun Wert "
				   +catanView.zustand+" angenommen.");
		} else {
		    System.out.println(catanView.zustand);
		}
	    }
	} catch (Exception e){
	    System.err.println("CatanView exception: " + e.getMessage());
            e.printStackTrace();
        }
    }
} 
