/** * *Clase Coordenadas *@author Diego del Valle *@author Diego Gonzalez */ import java.util.*; /** *Clase Coordenada que implementa por el lado del servidor la posicion en la que *se encuentra la figura que sera dibujada por los clientes */ public class Coordenadas { /**Constructor de clase coordenada que permite calcular tamano del mapa *@param width altura empleada para calcular el tamano del mapa *@param heigth anchura empleada para calcular el tamano del mapa *@param arquitectura Especifica arquitectura implementada por el servidor *@param circular especifica si la arquitectura es circular o no */ public Coordenadas(int width, int heigth, String arquitectura, boolean circular) { max_heigth = heigth; max_width = width; width_size = width; heigth_size = heigth; this.heigth = (new Random()).nextInt(max_heigth); this.width = (new Random()).nextInt(max_width); rate = 60; up = true; right = true; this.arquitectura = arquitectura; this.circular = circular; } /**Metodo que permite modificar tamano de ventana de mapa del servidor *@param clientCounter Numero maximo de clientes que se han conectado */ public void modify(int clientCounter) { if (arquitectura.equals("rectangular")) { if (clientCounter >= 2) max_heigth = heigth_size * 2; max_width = width_size * ((clientCounter - 1) / 2 +1); } else { max_width = width_size * clientCounter; } } /**Retorna posicion horizontal de la figura en el mapa *@return retorna posicion horizontal */ public int getWidth() { return width; } /**Retorna posicion vertical de la figura en el mapa *@return retorna posicion vertical */ public int getHeigth() { return heigth; } /**Retorna valor de parametro up *@return retorna valor de parametro up */ public boolean getUp() { return up; } /**Retorna valor de parametro right *@return retorna valor de parametro right */ public boolean getRight() { return right; } /** Cambian la direccion en que va la pelota, futuramente implementado cuando * existan "bordes" en cada panel */ public void setUp() { if ( up == true ) up = false; else up = true; } /** Cambian la direccion en que va la pelota, futuramente implementado cuando * * existan "bordes" en cada panel * */ public void setRight() { if ( right == true) right = false; else right = true; } /** Metodo que cambia todos los parametros de clase Coordenadas, con el * fin de adaptar dinamicamente la posicion de la figura en el mapa */ public void changeCoordinates() { if (heigth > (max_heigth - ANCHO*12)) up = true;//*18 if (heigth < 0 ) up = false; if (circular == false) { if (width > (max_width - ANCHO*12)) right = false; //*15 if (width < 0) right = true; } if (up == true ) heigth = heigth % max_heigth - 2; else heigth = heigth % max_heigth + 2; if (right == true ) width = width % max_width + 2; else width = width % max_width - 2; } //variables privadas private int max_heigth; private int max_width; private int heigth; private int width; private int width_size; private int heigth_size; private int rate; private boolean up; //up = true entonces sube, false, entonces baja private boolean right; private boolean circular; private String arquitectura; private static final int ANCHO = 5; }