Ensayo De Vida
Enviado por raygeraldo • 7 de Julio de 2013 • 18.377 Palabras (74 Páginas) • 309 Visitas
ROMPER LADRILLOS
Para este juego se necesita 10 clases:
Clase Main: Esta clase es la principal que hace uso de las otras nueve clases.
package brickbreaker;
//Importar clases
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
// La clase Main esta heredando de la clase Aplication que es una clase de la cual las aplicaciones JavaFX herendan
public class Main extends Application {
private static MainFrame mainFrame;
public static MainFrame getMainFrame() {
return mainFrame;
}
//sobreescribir el método "start()" que inicia la configuración del juego
@Override
public void start(Stage stage) {
//llamar al método "initialize()" de la clase Config
Config.initialize();
//Preparar el escenario (ventana) que contendrá el juego
//Título, redimensionar, tamaño
Group root = new Group();
mainFrame = new MainFrame(root);
stage.setTitle("Brick Breaker");
stage.setResizable(false);
stage.setWidth(Config.SCREEN_WIDTH + 2 * Config.WINDOW_BORDER);
stage.setHeight(Config.SCREEN_HEIGHT + 2 * Config.WINDOW_BORDER + Config.TITLE_BAR_HEIGHT);
Scene scene = new Scene(root);
scene.setFill(Color.BLACK);
stage.setScene(scene);
mainFrame.changeState(MainFrame.SPLASH);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
public class MainFrame {
// Instancia root
private Group root;
// Instancia de Splash (Si existe)
private Splash splash;
// Instancia de nivel (Si existe)
private Level level;
// Instancia de contador de vidas
private int lifeCount;
// Instancia de puntaje
private int score;
//costructor
private MainFrame(Group root) {
this.root = root;
}
public int getState() {
return state;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getLifeCount() {
return lifeCount;
}
//método para incrementar el contador de vidas
public void increaseLives() {
lifeCount = Math.min(lifeCount + 1, Config.MAX_LIVES);
}
//método para disminuir el contador de vidas
public void decreaseLives() {
lifeCount--;
}
// Inicializar el juego (vidas, puntajes, etc)
public void startGame() {
lifeCount = 3;
score = 0;
changeState(1);
}
// Stado actual del juego.
public static final int SPLASH = 0;
// 1..Level.LEVEL_COUNT - Level
private int state = SPLASH;
public void changeState(int newState) {
this.state = newState;
if (splash != null) {
splash.stop();
}
if (level != null) {
level.stop();
}
if (state < 1 || state > LevelData.getLevelsCount()) {
root.getChildren().remove(level);
level = null;
...