package com.games.swarm;

import com.client.*;
import com.common.*;

import java.nio.*;
import java.nio.channels.*;
import java.util.*;
import java.net.*;
import java.io.*;

public class  SWARMTestClient
{
  static SWARMClient gc;
  private EntityState es;
  private float bearing  = 92;
  private float speed    = 532;
  private float rate     = 2224;
  private int boatType   = 3;

  public static void main(String args[])
  {
    if (args.length < 2) 
    {
      System.out.println("usage: java com.games.swarm.SWARMClient <host> <player_name>\n");
      System.exit(0);
    }
    
    // fire up the client
    SWARMTestClient stc = new SWARMTestClient();
    gc = new SWARMClient(stc);
    gc.init(args);
    gc.start();
    stc.SendMessageToServer();
    stc.SendBearing();
    stc.SendSpeed();
    stc.SendTurningRate();
    stc.SendConnect();
    stc.SendDisconnect();
   

  }
  private void SendMessageToServer()
  {

    int [] tData;
    int count = 4;
    tData = new int[count];
    for (int x = 0; x< count; x++)
        tData[x] = x;
    GameEventDefault e = new GameEventDefault(GameEventDefault.C_TEST, count, tData);
    gc.sendMessage(e);

  }

  public void SendBearing()
  {
    boolean retval = gc.sendBearingUpdate(bearing);
  }
  public void SendSpeed()
  {
    boolean retval = gc.sendSpeedUpdate(speed);
  }
  public void SendTurningRate()
  {
    boolean retval = gc.sendTurningRateUpdate(rate);
  }
  public void SendConnect()
  {
    String connectionHandle = gc.connect(boatType);
  }
  public void SendDisconnect()
  {
    boolean retval = gc.disconnect("MYCONNECTIONHANDLE");
  }


  void handleUpdate (int count, EntityState[] update)
  {
    System.out.print("Client Received update for " + count + " Entities\n");
    for (int x =0; x<count; x++)
    {
       System.out.print("**Entity "+x+" **\n");
       System.out.print(
          "Bearing: "+
          update[x].getBearing()+
          " \nId: "+
          update[x].getId()+
          " \nSpeed: "+
          update[x].getSpeed()+
          " \nX: "+
          update[x].getXcoord()+
          " \nY: "+
          update[x].getYcoord()+
          " \nIsAlive: "+
          update[x].getIsAlive()+
          "\n\n");

    }

  }


  public void ReceiveSomething()
  {
    System.out.print("Client received something\n");

  }
}
