Package de.nameless.gameEngine.system

Source Code of de.nameless.gameEngine.system.NEgameServer

package de.nameless.gameEngine.system;

import de.nameless.gameEngine.gameObjects.NEDebugLandUnit;
import de.nameless.gameEngine.gameObjects.NEField;
import de.nameless.gameEngine.gameObjects.NEGameObject;
import de.nameless.gameEngine.gameObjects.NEMap;
import de.nameless.gameEngine.gameObjects.NEUnit;
import de.nameless.gameEngine.system.lan.messages.NEWorldMessage;
import de.nameless.graphicEngine.NEGraphicServer;
import static de.nameless.gameEngine.util.Logger.debug;


public class NEgameServer {
 
  private NEGameObjectManager GaOJ;
 
  private NEGraphicServer GFXServer;
 
  private NEMap Map;
 
  /**
   * Findet eine Unit mit entsprechneder ID oder gibt null aus.
   * @param id
   * @return
   */
  public NEUnit getUnitByID(long id){   
    for(NEGameObject  o :GaOJ.getAll()){
      if (o instanceof NEUnit) {
        NEUnit u = (NEUnit) o;
        if(u.getUnitId()==id)return u;
      }
    }   
    return null;   
  }

  public NEgameServer() {
    GaOJ = new NEGameObjectManager();
  }
 
  public void flushAllGFX(){
    if(GFXServer!=null){
     
      for(NEGameObject o: GaOJ.getAll()){
        GFXServer.addGraphicObjectAll(o.getGfx());
      }
    } else {
      debug("flushAllGFX called but no GfxServer set!", false);
    }   
  }

  public void setGFXServer(NEGraphicServer server) {
    GFXServer = server;
    this.flushAllGFX();
  }

  public NEGraphicServer getGFXServer() {
    return GFXServer;
  }

  public void unplugGFXServer(){
    GFXServer = null;
  }

  public void addGameObject(NEGameObject e) {
    GaOJ.add(e);
    if (GFXServer != null){
      GFXServer.addGraphicObjectAll(e.getGfx());
    }
  }

  public boolean remove(NEGameObject a) {
    if(GFXServer != null){
      GFXServer.removeAllGraphicObjects(a.getGfx());
    }
    return GaOJ.remove(a);
  }
 
  /**
   * Der gameserver l�dt die standert karte.
   */
  public void loadMap(){
    int [][] F = {{0,0,0,0,0,0,0,0},
              {0,0,0,0,0,2,2,2},
              {0,0,0,1,0,2,0,0},
              {2,2,0,1,0,2,2,2},
              {0,2,0,1,1,2,0,0},
              {0,2,2,2,2,2,0,0},
              {0,0,0,0,0,0,0,0}   
            }
 
    /*
    int [][] F ={{0,0,0},
               {0,1,0},
               {0,0,0} 
           }; 
    */
   
    Map = new NEMap(F)
    this.addGameObject(Map);
   
    NEDebugLandUnit U = new NEDebugLandUnit(NEplayer.BLUE);   
    addUnit(U, 1, 2);
   
    U = new NEDebugLandUnit(NEplayer.BLUE);     
    addUnit(U, 3, 3);
   
    U = new NEDebugLandUnit(NEplayer.RED);     
    addUnit(U, 3, 6);
   
  }
 
  public void addUnit(NEUnit u, int x, int y){
    u.placeUnitOnSquare(Map.get(x,y));
   
    this.addGameObject(u);   
  }
 
  public NEWorldMessage toMassage(){
    return new NEWorldMessage(GaOJ);
  }
 
  public void fromMassage(NEWorldMessage m){
    this.GaOJ = m.getWorld();
  }

  public NEMap getMap() {
    if (Map == null){
      for(NEGameObject  o :GaOJ.getAll()){
        if (o instanceof NEMap) {
          Map = (NEMap) o;         
        }
      } 
    }
    return Map;
  }
 
  public NEField getFieldByGLXY(float x, float y){   
    return getMap().get((int)((x-getMap().x+1)/2f) , (int)((y-getMap().y+1)/2f));
  }
 
  public NEField getFieldByXY(int x, int y){
    return getMap().get(x, y);
  }
 
  public void removeTurnLabels(){
    for(NEGameObject  o :GaOJ.getAll()){
      if (o instanceof NEUnit) {
        NEUnit u = (NEUnit) o;
        u.releaseMovedLable();
      }
    } 
  }
 
  public void removeMoveLabels(){
    for(NEGameObject  o : Map.children){
      if (o instanceof NEField) {
        ((NEField)o).reachable.release();       
      }
    }
  }
 
 
}
TOP

Related Classes of de.nameless.gameEngine.system.NEgameServer

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.