All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.thehilikus.jrobocom.events.ResultEvent Maven / Gradle / Ivy

There is a newer version: 1.0.0-beta-02
Show newest version
package com.github.thehilikus.jrobocom.events;

import java.util.EventObject;

import com.github.thehilikus.jrobocom.Player;

/**
 * Event triggered at the end of a session
 * 
 * @author hilikus
 */
public class ResultEvent extends EventObject {

    private static final long serialVersionUID = -8358528969962936354L;
    private Result result;
    private Player player;

    /**
     * The result of a single session
     * 
     */
    public enum Result {
	/**
	 * A single winner
	 */
	WIN,
	/**
	 * No winner
	 */
	DRAW,
	/**
	 * End of a game without competition
	 */
	END
    }

    /**
     * Constructs an event for a draw
     * 
     * @param source event creator
     * @param draw true if the result was a draw. false if it was just the end of the game
     */
    public ResultEvent(Object source, boolean draw) {
	super(source);
	if (draw) {
	    result = Result.DRAW;
	} else {
	    result = Result.END;
	}
    }

    /**
     * Constructs an event for a win
     * 
     * @param source event creator
     * @param winner the winner of the game
     */
    public ResultEvent(Object source, Player winner) {
	super(source);
	result = Result.WIN;
	player = winner;
    }

    /**
     * @return the result
     */
    public Result getResult() {
	return result;
    }

    /**
     * @return the player that won. If the result was a draw, returns null
     */
    public Player getWinner() {
	return player;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy