Post on 06-Feb-2015
TP Grupo 7: Presentación
Algoritmos y Programación III (75.07)
Cursos FontelaPrimer Cuatrimestre de 2009
Modelo
Vista
import ar.uba.fi.algo3.titiritero.Dibujable;import ar.uba.fi.algo3.titiritero.vista.SubVista;
public class JuegoSubVista extends SubVista {
private Juego juego;public JuegoSubVista(Juego juego) {
super(0, 0, 580, 800);setColor(Color.GREEN);this.juego = juego;
}protected void cargarDibujablesDeLaSubVista() {
Nivel nivel = juego.getNivel();ListIterator iterator = nivel.getCamino().iterator();while (iterator.hasNext()){
agregarDibujable(new VistaPeldañoDelCamino((Posicion) iterator.next()));
}for (Object atacanteObject : nivel.getAtacantes()){
agregarDibujable(new VistaElemento((ElementoUbicableEnTerreno) atacanteObject));
}for (Object enemigoObject : nivel.getEnemigos()){
agregarDibujable(new VistaElemento((ElementoUbicableEnTerreno) enemigoObject));
}}
}
Controlador
import componentes.Juego;import enemigo.EnemigoFactory;
import ar.uba.fi.algo3.titiritero.ObjetoVivo;
public class JuegoVivo implements ObjetoVivo {private Juego juego;private static final int CICLOS_HASTA_AGREGAR_ENEMIGO = 20;private int cantCiclosPasaron;
public JuegoVivo(Juego juego){this.juego = juego;cantCiclosPasaron = 10;
}
public void vivir() {if (cantCiclosPasaron == CICLOS_HASTA_AGREGAR_ENEMIGO){
juego.getNivel().agregarEnemigo(EnemigoFactory.generarEnemigo(juego));cantCiclosPasaron = 0;
}juego.continuar();cantCiclosPasaron++;
}}
Programa Principal(Pequeño ejemplo)
public static void main(String[] args) throws FileNotFoundException {
ControladorJuego controlador = new ControladorJuego();Juego juego = new Juego("Matata");
Ventana ventana = new VentanaPrincipal(controlador);controlador.setSuperficieDeDibujo(ventana);ventana.setVisible(true);
Nivel nivel = juego.getNivel();
Torre torreBlanca = new TorreBlanca(new Posicion(5,2));Obstaculo pegote = new Gelatina(new Posicion(5,4));
nivel.agregarAtacante(torreBlanca);nivel.agregarAtacante(pegote);nivel.agregarAtacante(torreBlanca2);
//juego.
//Agrego las vistas del juegoJugadorSubVista vistaJugador = new JugadorSubVista(juego.getJugador());
controlador.agregarDibujable(vistaJugador);controlador.agregarDibujable(new JuegoSubVista(juego));controlador.agregarDibujable(new MenuSubVista());
//Agrego al objeto vivocontrolador.agregarObjetoVivo(new JuegoVivo(juego));
controlador.agregarObjetoVivo(new JuegoVivo(juego));controlador.setIntervaloSimulacion(50);try {
controlador.comenzar();} catch (JugadorSeMurioException jsme){
controlador.detener();}
}
FIN
MUCHAS GRACIAS