Package Client

Source Code of Client.ClientGameState

package Client;

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import map.GameMap;
import spells.Spell;
import units.Unit;
import Global_Package.Enums;
import clientMessages.ClientEventIn;
import effectsAndParticles.Effect;


public class ClientGameState extends Thread{
  private GameMap Terrain;
  private Map <Integer,Unit> Units; //ID is key
  private Map <Integer,Spell> Spells;
  private List<String> ChatBuffer;
  public ClientNetwork Sockets;
  private Queue<ClientEventIn> EventQue;
  private List <Effect> EffectList;
 
  public Unit Player;
 
  private long initialTime;
 
  public ClientGameState(String ip, String name, String pass) throws IOException, InterruptedException{
   
    Units=new ConcurrentHashMap<Integer,Unit>();
    Spells=new ConcurrentHashMap<Integer,Spell> ();
    ChatBuffer=Collections.synchronizedList(new LinkedList<String>());
    EffectList= Collections.synchronizedList(new LinkedList<Effect>());
    EventQue=new ConcurrentLinkedQueue<ClientEventIn>();
    Sockets=new ClientNetwork(ip,EventQue,true,Enums.basicTestUnit);
    //Terrain=new GameMap(network getx, network get y);
  }
 
  public List<String> getChatBuff(){
    return ChatBuffer;
  }

  public Map<Integer,Unit> getUnits(){
    return Units; //alias
  }

  public Map<Integer,Spell> getSpells(){
    return Spells; //alias
  }
 
  public List<Effect> getEffects(){
    return EffectList;
  }
 
 
  public void run(){
    initialTime=System.currentTimeMillis();
      while(true){ //TODO change to something that can be switched on and off by client!
        for(int i=0;i<EventQue.size();i++){
          ClientEventIn r=EventQue.poll();
          if(r!=null){
            r.eventIn(this);
           
          }                                                                                         
       
        }
        //Sleep for a little, maybe a nap?
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
           
            e.printStackTrace();
          }
         
     
          //TODO Check if i did iterator right....
          int timePassed=(int)(initialTime-System.currentTimeMillis());
          while(EffectList.iterator().hasNext()){
            if( !EffectList.iterator().next().moreTime(timePassed) ){
              //no more time in this effect!!!!!
              EffectList.iterator().remove();
            }
          }
       
      }
   
  }
 
    private int EffectIDs=0;
    private int GetEffectID(){
      EffectIDs++;
      return EffectIDs--;
   
}
 
 
TOP

Related Classes of Client.ClientGameState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.