Package game.model

Source Code of game.model.TitleModel

package game.model;

import beans.core.GeneralConstant;
import game.animation.Animation;
import game.animation.TitleAnimation;
import game.animation.TitleBackAnimation;
import game.core.Collector;
import game.core.Counter;
import game.core.event.Event;
import game.core.event.TitleEvent;
import game.audioPlayer.AudioPlayer;
import game.view.TitleScreen;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Random;

/**
* Classe gerant les données de l'ecran titre
* @author mastersnes
*/
public class TitleModel extends Observable implements Observer {

    private TitleAnimation animation;
    private Animation backAnim;
    private final AudioPlayer audioPlayer;
    private GUIModel guiModel;
    private List<Animation> animations = new ArrayList<Animation>();
    final Counter counter;

    /**
     * Initialise l'animation et le counter
     * @param guiModel
     */
    public TitleModel(final GUIModel guiModel) {
        Event.setTitleEvent(new TitleEvent(this));
        counter = new Counter();
        audioPlayer = new AudioPlayer(GeneralConstant.MUSIQUE_PATH + "title.mp3");
        audioPlayer.start();
        Collector.signaler(audioPlayer);
        animation = new TitleAnimation();
        Collector.signaler(animation);
        animation.addObserver(this);
        counter.addAnimation(animation);
        animations.add(animation);

        backAnim = new TitleBackAnimation();
        Collector.signaler(backAnim);
        backAnim.addObserver(this);
        counter.addAnimation(backAnim);
        animations.add(backAnim);

        this.guiModel = guiModel;
        final TitleScreen titleScreen = new TitleScreen(this);
        guiModel.setScreen(titleScreen);
        this.addObserver(titleScreen);
    }

    /**
     * Envoie l'animation a TitleScreen
     * @see TitleScreen
     * @return
     */
    public List<Animation> getAnimation() {
        counter.tick();
        return animations;
    }

    @Override
    public void update(final Observable o, final Object arg) {
        setChanged();
        notifyObservers();
    }

    /**
     * Reponse de l'evenement TitleEvent
     * @see TitleEvent
     */
    public void EnterRequest() {
        String choix = animation.getChoice();
        if (choix.equals("jouer")) {
            Collector.stopAll();
            counter.kill();
            final GameModel gameModel = new GameModel(guiModel, "debut");
        } else if (choix.equals("quitter")) {
            guiModel.dispose();
        }
    }
}
TOP

Related Classes of game.model.TitleModel

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.