Package models

Source Code of models.PlayerGen

package models;

import java.util.*;
import javax.swing.event.EventListenerList;
import controllers.PlayerChangeEventType;
import controllers.PlayerChangedEvent;
import controllers.PlayerListener;

public class PlayerGen implements PlayerListener {

  private ArrayList<Integer> history;
  private int victories;
  private int currentScore;
  private Game currentGame;
 
  /**
     * Contains the Listener list of the Model
     */
    private EventListenerList listeners;
 
  public PlayerGen(){
    this.history=new ArrayList<Integer>();
    this.victories=0;
    this.currentScore=0;
    this.currentGame=new Game();
    listeners = new EventListenerList();
  }
 
  public void clearCurrentGame(){
    this.currentGame=new Game();
  }
 
  public void addToCurrentGame(Card newCard){
    this.currentGame.addCard(newCard);
    fireChanged(PlayerChangeEventType.DRAW_CARD);
  }
 
  public void stay(){
    fireChanged(PlayerChangeEventType.STAY);
  }
 
  public void setCurrentScore(int valueAdd){
    this.currentScore=this.currentScore+valueAdd;
  }

  public void setListeners(EventListenerList listeners) {
    this.listeners = listeners;
  }

  public EventListenerList getListeners() {
    return listeners;
  }

  /**
     * Adds a new Player listening object
     * @param listener Component registered to the <tt>PlayerListener</tt>
     */
    public void addPlayerListener(PlayerListener listener) {
        listeners.add(PlayerListener.class, listener);
    }

    /**
     * Removes a Player listening object
     * @param listener Component unregistered from the <tt>PlayerListener</tt>
     */
    public void removePlayerListener(PlayerListener listener) {
        listeners.remove(PlayerListener.class, listener);
    }
 
    /**
     * Creates events for listeners, called when writing in the Player
     * @param type Type of the event
     */
    public void fireChanged(PlayerChangeEventType type) {
        PlayerListener[] listenerList = (PlayerListener[]) listeners.getListeners(PlayerListener.class);
        switch (type) {
            case DRAW_CARD:
                for (PlayerListener listener : listenerList) {
                    listener.cardDrawn(new PlayerChangedEvent(this, type));

                }
                break;
            case STAY:
                for (PlayerListener listener : listenerList) {
                    listener.playerStays(new PlayerChangedEvent(this, type));

                }
                break;
            case BET:
                for (PlayerListener listener : listenerList) {
                    listener.betMade(new PlayerChangedEvent(this, type));

                }
                break;
            case WIN:
                for (PlayerListener listener : listenerList) {
                    listener.playerWins(new PlayerChangedEvent(this, type));

                }
                break;
            case LOSE:
                for (PlayerListener listener : listenerList) {
                    listener.playerLoses(new PlayerChangedEvent(this, type));

                }
                break;
        }
    }

  @Override
  public void betMade(PlayerChangedEvent event) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void cardDrawn(PlayerChangedEvent event) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void playerLoses(PlayerChangedEvent event) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void playerStays(PlayerChangedEvent event) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void playerWins(PlayerChangedEvent event) {
    // TODO Auto-generated method stub
   
  }

  public ArrayList<Integer> getHistory() {
    return history;
  }

  public void setHistory(ArrayList<Integer> history) {
    this.history = history;
  }

  public int getVictories() {
    return victories;
  }

  public void setVictories(int victories) {
    this.victories = victories;
  }

  public Game getCurrentGame() {
    return currentGame;
  }
 
  public ArrayList<String> showCurrentGame(){
    ArrayList<String> sList = new ArrayList<String>();
    Card interCard=null;
    String interS;
    ArrayList<Card> cardList = currentGame.getPersonalCardList();
    for (int i=0;i<cardList.size();i++){
      interCard = cardList.get(i);
      interS = (interCard.getCardColor()+"\\"+interCard.getCardName());
      sList.add(interS);
    }
    return sList;
  }

  public void setCurrentGame(Game currentGame) {
    this.currentGame = currentGame;
  }

  public int getCurrentScore() {
    return currentScore;
  }
 
}
TOP

Related Classes of models.PlayerGen

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.